Repository navigation
Conversation
… take
On the web target a value only known at runtime reached its CSS variable
as written, so <Box p={m} /> with m = 2 set padding: 2, which is no CSS
length, while p={2} compiles to 8px. Each such value is now passed
through a small helper the file declares once, which converts a number,
or a string holding only one, as the build converts a literal of that
property: spacing and sizes x4 in px, durations in ms, and unitless
properties, colors and custom properties unchanged. Other strings and
null, undefined or false pass through, so the latter still drop the
declaration. Responsive arrays, selectors, conditionals and Devup UI's
own styled() callbacks and templates follow the same rule; Emotion,
styled-components and vanilla-extract files keep their px numbers.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dependent build Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…scale Files no longer declare their own __devupScale (web) or __u (React Native) function. The conversions live in a dependency-free, side-effect-free `scale` subpath of @devup-ui/react (ESM + CJS, no component code), and a file that needs one imports it once, from `<package>/scale` so a custom package option keeps working, under a collision-safe local name. CommonJS output requires it instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
On the web target, a value only known at runtime reached its CSS variable as written.
<Box p={m} />withm = 2setpadding: 2, which is invalid CSS, whilep={2}compiles to8px. Each such value now goes through a conversion that turns a number into exactly what the static path makes of a literal of that property. The conversion lives in a new tiny subpath,@devup-ui/react/scale, and a file that needs it imports it once. Values the build can prove still fold at build time.Rules (derived from
ExtractStaticStyle::normalize_static_value, mirroring the RNruntime_scalein #1039)2,'2')'2rem','auto')null/undefined/falsep,w,fontSize,bg...)px(8px)TIME_PROPERTIES(transitionDuration,animationDelay...)ms(2ms)MAINTAIN_VALUE_PROPERTIES(opacity,zIndex,lineHeight,flex,order...)*color), custom properties (--*)Rule coverage:
_hover), conditionals, and Devup UI's ownstyled()callbacks and templates.css()stays build-time only, since a runtime value there is already a build error.css-prop files keep their own px conversion and get no import.`${m}px`) is left as written.Shared util:
@devup-ui/react/scalepackages/react/src/scale.tsis exported as./scale(ESM + CJS + types). It is dependency-free, the package is alreadysideEffects: false, and the module imports no component code.__devupScale(v, s = 4, u = 'px')for the web.__devupNativeScale(v, s)for React Native: a number result, ×scale with nopx,pxas 1,rem/emas 16. Native (feat: compile Devup UI elements to React Native styles (core, static subset) #1039) now imports this one instead of declaring__uin every file.<package>/scale, so a custompackageoption resolves to its own re-export. It is added once per file, only when a call remains, after the leading imports, and under a collision-safe local name (__devupScale as __devupScale_when the name is taken). A CommonJS file getsconst __devupScale = require("<package>/scale").__devupScale;.@devup-ui/react, so vite, webpack, rsbuild, Next (webpack and Turbopack) and bun resolve the subpath like any other package import.Before / after
Bundle impact
dist/scale.js451 B /scale.cjs432 B, once per bundle, both conversions__ubodyFiles with only static values, or only unitless or color values, are byte-identical and import nothing.
Intentional behavior change:
styled()callbacks (owner-approved)Inside Devup UI's own
styled()callbacks and templates, a runtime number on a CSS name used to be read as px (3→3px) or passed through bare. Written statically, the same3gives12px. Both now give12px, matching the static path; the owner accepted this. Emotion and styled-components keep px.The change is isolated in one branch in
extractor/styled_scalar.rs. The tests pinning it arebound_callback_numeric_tests, theretained_render_assertionsopaque case,known_mixin_regressionsandtests/imported_styled_retained_edges. The changeset notes it.Review notes
mainonce the@devup-ui/react/scaleimport line is removed and__devupScale(...)is unwrapped, so no static output changed.__ubody forimport { __devupNativeScale as __u } from "@devup-ui/react/scale".packages/react/src/__tests__/scale.test.ts, with 100% coverage.scale.tssource and bind each imported local name to it.package, CommonJSrequire, no import when nothing is converted, and idempotent recompilation.p={m}withm = 2computespadding: 8px,'2'gives 8px,'1rem'gives 16px, opacity stays raw and duration is in ms.bgwith a color variable (nowcolor).Test plan
cargo test(workspace),cargo clippy --all-targets -- -D warnings,cargo fmt --checkbun test packages/react/src/__tests__/scale.test.ts(100% coverage)bunx playwright test e2e/css-composition.spec.ts(27 passed)요약
웹 타깃에서 런타임에만 알 수 있는 값이 CSS 변수에 그대로 들어갔습니다.
<Box p={m} />에m = 2를 주면padding: 2가 되는데, 이는 잘못된 CSS입니다. 반면p={2}는8px로 컴파일됩니다. 이제 이런 값은 변환 함수를 거칩니다. 이 함수는 정적 경로가 해당 속성의 리터럴을 변환하는 방식 그대로 숫자를 변환합니다. 함수는 새로 추가한 작은 서브패스@devup-ui/react/scale에 있고, 필요한 파일이 한 번만 import합니다. 빌드 타임에 증명 가능한 값은 계속 빌드 타임에 접힙니다.규칙 (
ExtractStaticStyle::normalize_static_value에서 도출, #1039의 RNruntime_scale과 동일)2,'2')'2rem','auto')null/undefined/falsep,w,fontSize,bg...)px(8px)TIME_PROPERTIES(transitionDuration,animationDelay...)ms(2ms)MAINTAIN_VALUE_PROPERTIES(opacity,zIndex,lineHeight,flex,order...)*color), 커스텀 속성 (--*)규칙 적용 범위:
_hover), 조건식, Devup UI 자체styled()콜백과 템플릿.css()는 여전히 빌드 타임 전용입니다. 런타임 값은 이미 빌드 에러입니다.cssprop 파일은 기존 px 변환을 유지하며 import도 추가되지 않습니다.`${m}px`)은 그대로 둡니다.공유 유틸:
@devup-ui/react/scalepackages/react/src/scale.ts를./scale로 export합니다(ESM + CJS + 타입). 의존성이 없고, 패키지는 이미sideEffects: false이며, 컴포넌트 코드를 전혀 import하지 않습니다.__devupScale(v, s = 4, u = 'px').__devupNativeScale(v, s): 숫자 결과,px없이 ×scale,px는 1,rem/em은 16. 네이티브(feat: compile Devup UI elements to React Native styles (core, static subset) #1039)는 이제 파일마다__u를 선언하지 않고 이 함수를 import합니다.<package>/scale에서 import하므로package옵션을 바꾸면 그 패키지의 re-export로 해석됩니다. 호출이 남아 있는 파일에만, 파일당 한 번, 맨 앞 import들 뒤에 추가됩니다. 이름이 겹치면__devupScale as __devupScale_처럼 충돌 없는 로컬 이름을 씁니다. CommonJS 파일에는const __devupScale = require("<package>/scale").__devupScale;가 들어갑니다.@devup-ui/react를 alias하거나 external로 빼지 않으므로 vite, webpack, rsbuild, Next(webpack·Turbopack), bun 모두 일반 패키지 import처럼 서브패스를 해석합니다.전 / 후
영어 섹션의 diff를 참고하세요.
번들 영향
dist/scale.js451 B /scale.cjs432 B, 번들당 한 번, 두 변환 포함__u본문 226 B정적 값만 있거나 무단위·색상 값만 있는 파일은 바이트 단위로 동일하며 아무것도 import하지 않습니다.
의도된 동작 변경:
styled()콜백 (오너 승인)Devup UI 자체
styled()콜백과 템플릿에서 CSS 이름에 붙은 런타임 숫자는 px로 읽히거나(3→3px) 단위 없이 그대로 전달됐습니다. 같은3을 정적으로 쓰면12px입니다. 이제 둘 다 정적 경로와 같은12px이며, 오너가 이 변경을 승인했습니다. Emotion과 styled-components는 px를 유지합니다.이 변경은
extractor/styled_scalar.rs의 분기 하나에 격리되어 있습니다. 이를 고정하는 테스트는bound_callback_numeric_tests,retained_render_assertions의 opaque 케이스,known_mixin_regressions,tests/imported_styled_retained_edges입니다. changeset에도 적었습니다.리뷰 참고
@devup-ui/react/scaleimport 줄을 지우고__devupScale(...)를 벗기면main과 바이트 단위로 같다는 것을 확인했습니다. 정적 출력은 바뀌지 않았습니다.__u본문이import { __devupNativeScale as __u } from "@devup-ui/react/scale"로 바뀐 것뿐입니다.packages/react/src/__tests__/scale.test.ts의 단위 테스트 30개로 커버리지 100%입니다.scale.ts소스를 실행하고, import된 각 로컬 이름을 거기에 연결합니다.package, CommonJSrequire, 변환할 값이 없을 때 import 없음, 재컴파일 시 동일함을 다룹니다.p={m}에m = 2이면padding: 8px,'2'는 8px,'1rem'은 16px, opacity는 그대로, duration은 ms입니다.bg에 색상 변수를 쓰던 README 예제를color로 고쳤습니다.🤖 Generated with Claude Code