WIP fix(ssr): invalidate nested ESM chunks in dev mode#8467
Open
GiveMe-A-Name wants to merge 6 commits intomainfrom
Open
WIP fix(ssr): invalidate nested ESM chunks in dev mode#8467GiveMe-A-Name wants to merge 6 commits intomainfrom
GiveMe-A-Name wants to merge 6 commits intomainfrom
Conversation
- Add requireFromString function to bypass ESM cache in dev mode - Use mtime-based caching to avoid frequent recompilation - Add fallback mechanism when requireFromString fails Note: This fix addresses the main bundle loading, but there is a remaining issue with rspack's internal chunk loading (__webpack_require__.e) that requires rspack to fix internally. Related: web-infra-dev/rspack#13304
🦋 Changeset detectedLatest commit: f9c1720 The changes in this PR will be included in the next version bump. This PR includes changesets to release 113 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for modernjs-byted ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
Rsdoctor Bundle Diff Analysis📊 Quick Summary
Generated by Rsdoctor GitHub Action |
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.

Summary
Problem
In dev SSR mode for ESM projects, top-level bundle invalidation was not enough. After editing a page or component, the SSR entry bundle could be refreshed, but nested rspack chunk imports still came from the ESM cache, which caused stale SSR output and hydration mismatch on refresh.
Solution
compatibleRequirenow detects the rspack dynamic chunk import pattern in development ESM mode, rewrites those chunk imports to append a timestamp query, writes a temporary patched bundle file, imports it, and then removes the temp file.This keeps the existing production path unchanged while ensuring nested SSR chunk imports are invalidated in development.
Tests
pnpm test:ut -- packages/toolkit/utils/tests/compatRequire.test.tspnpm test:framework -- integration/ssr/tests/esm-cache-invalidation.test.tspnpm lint packages/toolkit/utils/src/cli/require.ts packages/toolkit/utils/tests/compatRequire.test.ts#8373