Repository navigation
fix: load only the optional libraries each dynamic component uses - #7276
FarhanAliRaza merged 16 commits into
Conversation
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryDynamic components now request only the optional libraries they use.
Reviews (12) · Last reviewed commit: "Merge upstream main into PR #7276" · Reviewed by Greptile |
Merging this PR will degrade performance by 4.06%2 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing |
|
the finding in the issue is that with the setting on, it actually ships larger initial JS payload than with it turned off... is that incorrect? the proposed change seems to paper over the reported issue |
|
Implemented the runtime fix for the reported regression in 6f44747. The lazy path no longer preloads every registered optional library on the first dynamic-component evaluation; generated dynamic modules request only their own bundled module paths, and the loader caches each requested module independently. Added regression coverage plus root/reflex-base performance fragments. Local validation: 322 compiler/dynamic tests passed (1 skipped), targeted tests passed, Ruff, Pyright, and pre-commit passed. |
There was a problem hiding this comment.
All reported issues were addressed across 6 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 3 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
FarhanAliRaza
left a comment
There was a problem hiding this comment.
I exercised lazy dynamic components in a real app and ran a production export. I reran the optional-registry test and compared identical-source failure and retry behavior with the baseline evaluator using a controlled async loader.
See the inline comments.
|
Addressed the review findings:
The docs retry test passes, and all CI workflows are green on |
Parse the //__reflex_evaluate library list with startsWith on the first line instead of a multiline regex over the whole component source. Drop the unconditional "fewer initial library requests" claim from the changelog and README: with the flag on, a page that renders dynamic components can make more requests, not fewer. Describe the per-component loading in the docs README.
List only optional libraries in the //__reflex_evaluate line: the default libraries are always in window.__reflex. Always write the list, so the marker has one form and make_component loses the extra branch. Use Object.hasOwn in the app-root loader instead of a local helper. Replace string assertions on loader source with behavior checks: - the codegen test asserts the exact library list, including an empty one - the docs node test evaluates a module generated by make_component, so a marker format change on either side fails it, and it loads a library named constructor - test_dynamic_components runs with the flag off and on; with it on, the banana icon must stay out of window.__reflex until its component renders
Resolve conflicts with reflex-dev#7604 and reflex-dev#7441: - test_dynamic_components keeps reflex-dev#7604's deep Lucide checks; the banana icon is expected at first render only when libraries load eagerly - the docs node test passes reflex-dev#7441's context-registry library to setup
Fixes #7262.
With
frontend_lazy_bundled_libraries=True, the first dynamic-component evaluation loaded every registered optional library. A page that rendered only a dynamicrx.iconalso downloaded Radix Themes. So the flag added JavaScript instead of removing it.Changes
make_componentwrites the optional libraries of each dynamic component on the first line of the generated module://__reflex_evaluate:["lib", ...]. Default libraries (React,@emotion/react,$/utils/state,$/utils/context) are always loaded, so they are not listed.evalReactComponentreads that line and callswindow.__reflex_load(libraries)beforeimport(). A failed load rejects before the module is cached, so the next evaluation of the same source tries the load again.window.__reflex_loadloads each library separately, shares requests in progress, and clears a failed entry so it can retry. Without arguments, it still loads all optional libraries.test_dynamic_componentsruns with the flag off and on. With the flag on, it checks that an optional library loads only when a component that uses it renders.Measurements
Production build, decoded JS loaded until the dynamic components render:
rx.iconWhen a page needs Radix, the lazy chunks stay about 75 KB larger than the static import. This PR does not change that chunking.