feat(compiler): mirror memo output paths to Python source modules#6457
feat(compiler): mirror memo output paths to Python source modules#6457FarhanAliRaza wants to merge 5 commits intoreflex-dev:mainfrom
Conversation
Memos now compile into a single JSX file per user module at a path that mirrors the module's dotted name, instead of one file per memo under . The page-side import surface matches the source layout, which makes debugging easier and lets Vite group co-defined memos in the same chunk. Memos without a captured source module keep the legacy per-name files and index. A manifest in records emitted paths so stale files from previous compiles get pruned.
Merging this PR will not alter performance
Comparing Footnotes
|
Greptile SummaryThis PR changes how memo-defined JSX files are written to
Confidence Score: 3/5Safe to merge for production builds, but hot-reload development workflows can silently produce wrong JSX paths when a module's package/regular-module status changes between saves. The core compilation path is well-structured and the legacy fallback is preserved, but
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[memo decorator / custom_component] --> B{capture_source_module}
B -->|user module| C[source_module set]
B -->|None / framework| D[source_module = None]
C --> E[module_to_mirrored_segments]
E -->|package __init__.py| F["segments + 'index'"]
E -->|regular module| G[segments as-is]
F & G --> H[library_specifier_for\n'$/a/b/c']
D --> I[legacy per-name path\n'$/utils/components/Name']
H --> J[_compile_memo_components\ngroups by segments]
I --> K[legacy_files + index]
J --> L[single merged JSX\nper source module]
K --> M[utils/components/Name.jsx\n+ index re-export]
L & M --> N[prune_stale_memo_files\nreads .memo-manifest.json]
N --> O[deletes stale JSX files\n& empty directories]
N --> P[writes new manifest]
Reviews (1): Last reviewed commit: "feat(compiler): mirror memo output paths..." | Re-trigger Greptile |
Identical memoizable subtrees on pages from different user modules produce the same wrapper tag. The auto-memo registry was keyed by tag alone, so the second registration overwrote the first — only one of the source modules got a mirrored memo file emitted, and the other page imported the tag from a JSX file that never declared it. Vite failed the prod build with MISSING_EXPORT. Key the registry by (tag, source_module) so each module's mirrored file gets its own definition, and add an integration test that builds two pages from distinct user modules sharing a memoizable subtree.
was d, so once a module had been resolved its mirrored path was frozen for the process. A user toggling a module between a regular and a package () during dev reload kept the original origin and emitted memo files to the stale path. Drop the cache and read from first, falling back to only when the module isn't loaded — is rebound on reload, while a cached spec wouldn't be. Also tighten to close the mkstemp fd up front so it can't leak if reopening raises, and re-export from for parity with the rest of the surface.
Memos now compile into a single JSX file per user module at a path that mirrors the module's dotted name, instead of one file per memo under . The page-side import surface matches the source
layout, which makes debugging easier and lets Vite group co-defined memos in the same chunk.
Memos without a captured source module keep the legacy per-name files and index. A manifest in records emitted
paths so stale files from previous compiles get pruned.
All Submissions:
Type of change
Please delete options that are not relevant.
New Feature Submission:
Changes To Core Features:
closes #6218