lighthouse: tree-shake bundled libs and ship only used Radix color scales#6563
lighthouse: tree-shake bundled libs and ship only used Radix color scales#6563FarhanAliRaza wants to merge 2 commits into
Conversation
Replace the blanket `import * as` of every bundled library with per-library named imports collected from the app's actual static usage (plus tags captured during dynamic-component serialization), so Rolldown can drop unused exports. Keep star imports for internal `$/utils/*` modules, `react`/`@emotion/react`, and any tag set that isn't a valid JS identifier. Plumb `theme_roots` through the Radix Themes plugin and the Tailwind v3/v4 root style so only the Radix CSS token files for accent/gray colors referenced by `Theme` components are emitted, with the monolithic stylesheet retained as a fallback for state-driven or unrecognized colors.
Greptile SummaryThis PR optimizes the frontend bundle by (1) replacing blanket
Confidence Score: 4/5Safe to merge with minor follow-up; the two findings are edge cases that don't affect the typical Radix/React component usage covered by the new tests. The color-detection and named-import logic is well-tested and handles all the important fallback cases. Two edge cases are not covered: accent_color=gray produces a duplicate gray.css entry (self-referential pairing in _RADIX_ACCENT_TO_AUTO_GRAY), and any bundled external library whose components exclusively use default imports will be absent from window.__reflex because only named tags are collected. Neither affects the common Radix component usage path, but both would produce unexpected output in the specific scenarios described. packages/reflex-components-radix/src/reflex_components_radix/plugin.py (duplicate color entry) and reflex/compiler/compiler.py (default-import-only library exclusion) Important Files Changed
|
When accent_color and its paired gray resolve to the same scale (e.g. accent_color="gray"), the tokens CSS file was imported twice. Subtract accents from grays before extending the sheet list so each color file is emitted only once.
|
Add more tests for dynamic components. |
Replace the blanket
import * asof every bundled library with per-library named imports collected from the app's actual static usage (plus tags captured during dynamic-component serialization), so Rolldown can drop unused exports. Keep star imports for internal$/utils/*modules,react/@emotion/react, and any tag set that isn't a valid JS identifier.Plumb
theme_rootsthrough the Radix Themes plugin and the Tailwind v3/v4 root style so only the Radix CSS token files for accent/gray colors referenced byThemecomponents are emitted, with the monolithic stylesheet retained as a fallback for state-driven or unrecognized colors.All Submissions:
Type of change
Please delete options that are not relevant.
New Feature Submission:
Changes To Core Features:
fixes ENG-9323
