Repository navigation
Conversation
starter-extra calls `rsc()` without options, so replacing `rsc({` was a no-op and the test still ran with automatic CSS injection.
Only the first `import.meta.viteRsc.loadCss(id)` in a module got its `__vite_rsc_importer_resources_<hash>` import in build, since one flag tracked whether any import had been added. A second call with a different id then referenced an undeclared identifier and failed at render with a ReferenceError. Track the added imports per hash instead.
This branch has not been deployed
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.
Description
In a build, only the first
import.meta.viteRsc.loadCss(id)in a module gets its__vite_rsc_importer_resources_<hash>import. A second call with a different id references an identifier that was never declared, and the render fails with aReferenceError:#742 added a guard so that two calls with the same id in one module do not import the same binding twice. The guard is a single
importAddedflag for the whole module, so after the first import it also skips the imports for every other id. This PR tracks the added imports per hash instead.vite devis not affected, because it imports each call's resources dynamically.We ran into this in a framework that generates a route table and renders
loadCss(<route file>)for each lazily loaded route, so that a page links only the CSS of its own route chunk.The new
manual-css-multiple-idse2e test renders two components whose CSS is loaded only through twoloadCss(id)calls in one module, withrscCssTransform: false. Without the fix, its build case fails because the page does not render. With the fix, it passes in dev and build.A separate commit fixes the existing
manual-csstest.examples/starter-extracallsrsc()without options, sos.replace('rsc({', ...)changed nothing, and the test ran with automatic CSS injection. Withrsc()replaced,rscCssTransform: falsetakes effect, and the test still passes in dev and build.pnpm -C packages/plugin-rsc test --run(525 tests) andpnpm -C packages/plugin-rsc tscpass.e2e/manual-css.test.tspasses in Chromium. Four tests ine2e/starter.test.tsfail on my machine (macOS), and they fail the same way onmainwithout this change.