fix(build): [POC] server dynamic-import-vars for RSC env (#1533)#1842
Draft
james-elicx wants to merge 1 commit into
Draft
fix(build): [POC] server dynamic-import-vars for RSC env (#1533)#1842james-elicx wants to merge 1 commit into
james-elicx wants to merge 1 commit into
Conversation
commit: |
| if (seen.has(key)) continue; | ||
| seen.add(key); | ||
| entries.push( | ||
| ` ${JSON.stringify(key)}: () => import(${JSON.stringify(spec)}),`, |
Contributor
|
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.
Draft / POC — not ready for merge. Addresses #1533 (a
next/dynamic/ variable dynamic importimport(\./${slug}`)renders the fallback instead of real content because variable dynamic imports aren't expanded in the RSC/server Vite environment the way Vite's clientdynamic-import-vars` plugin handles them).This branch adds a 254-line
server-dynamic-import-vars.tsplugin that builds a static candidate map for the simple case. It makes the issue's exact case pass, but a self-review surfaced material gaps that must be resolved before this is safe to merge:import(\./icon-${name}`)` would statically pull in every sibling (incl. unrelated server-only modules), risking a server/client directive-boundary build break.import(\./${x}/index`),./${x}.client`) miss the map → runtime throw (the very failure mode being fixed).button.tsxvsbutton.css) bind nondeterministically.Recommendation: either (a) scope the plugin strictly to the bare single-variable direct-sibling case and fall through (no transform) for prefix/suffix/nested patterns to avoid regressions, or (b) invest in a robust port of Vite's dynamic-import-vars for the server environment. Given this is a single e2e test, deprioritized as not-a-small-patch. Closes #1533 only once hardened.