Repository navigation
Conversation
Resolve `$` tokens and typography of devup.json at build time for React Native. With one theme every value is a literal and no runtime is imported; with more, each theme's styles are precomputed and picked by the index `useThemeIndex()` of the new `@devup-ui/react/native` runtime gives, which follows the OS appearance and `setTheme`. `_theme*` and the theme API compile, and `runtime: false` keeps them build errors. The Metro plugin registers devup.json's theme, and the Expo example gains a theme toggle and a bundle check that static files do not use the runtime. Part of #411. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
verify-dist loads every declared entry, and `@devup-ui/react/native` imports react-native, which is Flow source Bun cannot parse. A virtual module stands in for it so the entry still loads and exports. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cover a typography whose token one theme does not define, a static style merged into a themed one, and a later style checked against a choice that applies in one theme. A merge that leaves every theme declaring the same styles now collapses to one static style instead of picking between equal objects. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #411, depends on #1041 (base:
feat/react-native-metro). PR 3 of the React Native plan: theme tokens, multiple themes and a minimal runtime.What it does
Tokens at build time.
$color,lengthandshadowtokens andtypographyresolve to the values React Native takes. The theme is parsed bylibs/sheetas on the web (registerTheme), andbinding-coreconverts it into a plain per-theme table for the native extractor, so thecodeExtractNativeABI is unchanged. A relative typographylineHeight(unitless,%,em) oremletterSpacingbecomes pixels of the typography'sfontSize.One theme: fully static, no runtime import.
Several themes (R2): one precomputed object per theme, picked by index; theme-independent parts stay shared.
default>light> first), as the web orders them. A token a theme lacks falls back to the default variant, like the web's:rootcascade.use*,memo/forwardRef, orexport default. An element outside one (module scope, class components, lowercase helpers) renders through the runtime'sThemedwrapper instead, so the rules of hooks hold._themeDark,_themeSepia, … apply their styles only in that theme, including nested and conditional blocks. An unknown theme name is a build error.useTheme,getThemeandsetThemeimported from@devup-ui/reactare rewritten to the runtime (they were build errors in feat: compile Devup UI elements to React Native styles (core, static subset) #1039).Runtime:
@devup-ui/react/native(RN-only subpath; web entries never import it). 628 B minified, 398 B min+gz.useSyncExternalStore. No CSS parsing, no token resolution, no style computation.Appearance. The dark theme isdarkwhen devup.json renders it dark, else the first themecolorSchememakes dark.setTheme(name)overrides the OS choice and supports any number of themes. An unknown name renders the default theme's styles, as on the web.react-nativeis an optional peer; there are no other dependencies.defineThemes.runtime: falsestays strict. Anything that needs the runtime is a build error: a value that differs by theme,_theme*with more than one theme, anduseTheme/getTheme/setTheme. Single-theme tokens still compile.Still build errors: responsive tokens or typography (a value at each breakpoint; PR 4), unknown
$tokens or typographies, tokens that reference each other in a loop, a relative typography without a pixelfontSize, and a typography chosen by a runtime value.Metro plugin registers devup.json's theme (with
extends) once per worker.Expo example has light/dark themes, tokens, a typography and a
setThemetoggle. The CI bundle check now:@devup-ui/react/dist/nativefrom@devup-ui/react;src/App.tsxto use the runtime;src/Badge.tsxnot to. The check maps eachdefineThemes/useThemeIndexoccurrence back through the bundle's source map. It was verified locally to fail whenBadge.tsxuses a token.CI: adds
feat/react-native-metroto thepull_requestbranches (it is removed when this is retargeted tomain), andpackages/react/src/native/to the Expo job's path filter.Tests
runtime: false; theme errors; the theme conversion inbinding-core.-D warningsis clean.mock.module('react-native')):setThemeoverriding the OS;Themedwrapper.#411의 일부이며 #1041에 의존합니다(base:
feat/react-native-metro). React Native 계획의 PR 3으로, 테마 토큰, 다중 테마와 최소 런타임을 다룹니다.변경 사항
빌드 타임 토큰.
$색상·length·shadow토큰과typography를 React Native 값으로 바꿉니다. 테마는 웹과 같이libs/sheet가 파싱하고(registerTheme),binding-core가 네이티브 추출기용 테마별 표로 변환하므로codeExtractNativeABI는 그대로입니다. 상대 단위lineHeight(단위 없음,%,em)와emletterSpacing은 typography의fontSize기준 픽셀이 됩니다.테마 1개: 모두 정적이며 런타임 import가 없습니다(위 예시).
테마 여러 개(R2): 테마마다 미리 계산한 객체를 인덱스로 고릅니다. 테마와 무관한 부분은 공유합니다(위 예시).
default>light> 첫 번째). 테마에 없는 토큰은 웹의:root처럼 기본 variant 값을 씁니다.Themed래퍼로 렌더링하므로 hooks 규칙을 지킵니다._themeDark같은_theme*는 해당 테마에서만 적용됩니다. 알 수 없는 테마 이름은 빌드 에러입니다.useTheme/getTheme/setThemeimport는 런타임으로 다시 씁니다(#1039에서는 빌드 에러였습니다).런타임
@devup-ui/react/native(RN 전용 서브패스이며 웹 엔트리는 import하지 않습니다). min 628B, min+gz 398B.useSyncExternalStore로 읽는 작은 스토어이며, CSS 파싱·토큰 해석·스타일 계산이 없습니다.Appearance로 OS를 따릅니다.setTheme(name)은 OS 선택을 덮어쓰고 테마 개수에 제한이 없습니다. 알 수 없는 이름은 웹과 같이 기본 테마 스타일로 렌더링합니다.react-native는 optional peer이며, 다른 의존성은 없습니다.**
runtime: false**는 엄격 모드를 유지합니다. 런타임이 필요한 것은 모두 빌드 에러이고, 단일 테마 토큰은 그대로 컴파일됩니다.여전히 빌드 에러: 반응형 토큰과 typography(PR 4), 정의되지 않은 토큰이나 typography, 순환 토큰, 픽셀
fontSize가 없는 상대 typography, 런타임 값으로 고르는 typography.Metro 플러그인은 devup.json 테마(
extends포함)를 워커마다 한 번 등록합니다.Expo 예제에는 light/dark 테마, 토큰, typography와
setTheme토글을 추가했습니다. CI 번들 검사는 다음을 확인합니다:@devup-ui/react중에서는dist/native만 허용합니다;App.tsx가 런타임을 사용해야 합니다;Badge.tsx는 런타임을 사용하면 안 됩니다. 이 검사는 source map으로 확인하며, 로컬에서 실패하는 경우도 검증했습니다.CI:
pull_request브랜치에feat/react-native-metro를 추가했습니다(main으로 retarget할 때 제거합니다). Expo 잡의 경로 필터에는packages/react/src/native/를 추가했습니다.테스트
runtime: false, 에러, 변환. 웹 스냅샷 변경은 없고 clippy도 깨끗합니다.setTheme우선, 알 수 없는 이름,Themed. 커버리지는 100%입니다.🤖 Generated with Claude Code