fix(core): preserve page data lifecycle during HMR - #3590
Conversation
Rsdoctor Bundle Diff AnalysisFound 5 projects in monorepo, 0 projects with changes. 📊 Quick Summary
Generated by Rsdoctor GitHub Action |
Deploying rspress-v2 with
|
| Latest commit: |
f273891
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://0c10740a.rspress-v2.pages.dev |
| Branch Preview URL: | https://fix-page-data-hmr-lifecycle.rspress-v2.pages.dev |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f273891148
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| setPageDataAlias( | ||
| alias, | ||
| environment.name === 'web' ? 'web' : 'fallback', | ||
| ); |
There was a problem hiding this comment.
Recreate the MD resolver after switching to web aliases
When the virtual module is rendered by a non-web environment before the web chain is configured, this stores the fallback aliases and initializes flattenMdxContent's module-level resolver with them. Although the subsequent web callback regenerates page data with the authoritative aliases, packages/core/src/node/utils/flattenMdxContent.ts never recreates its resolver once startFlatten is set, so Markdown imports that depend on a web-specific alias can remain unresolved or resolve to the fallback target, producing incorrect search content and omitting the dependency from HMR tracking. Reset or key that resolver when the alias source changes.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Pull request overview
Fixes @rspress/core page-data generation so dev HMR invalidation reliably regenerates the virtual page-data module (and associated local search indexes), while production builds reuse a single authoritative generation result across compiler targets. It also tracks imported Markdown/MDX dependencies so changes in included content trigger updates.
Changes:
- Add
_depstoPageIndexInfoand plumbflattenMdxContent()dependency tracking into extracted page index info. - Include
_depsin the page-data generation dependency set so virtual modules watch imported Markdown/MDX files too. - Refactor the rsbuild page-data plugin to manage generation state/revisions for dev refresh vs production caching, with new unit tests validating the lifecycle.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/shared/src/types/index.ts | Adds optional _deps field to page index info to carry imported MD/MDX dependency paths. |
| packages/core/src/node/runtimeModule/pageData/rsbuildPlugin.ts | Reworks page-data/search-index generation lifecycle for dev HMR refresh and production reuse via a shared generation state. |
| packages/core/src/node/runtimeModule/pageData/rsbuildPlugin.test.ts | Adds unit tests covering alias selection, production caching, dev regeneration, and failure retry behavior. |
| packages/core/src/node/runtimeModule/pageData/createPageData.ts | Collects dependencies from _deps into the watched file path set (deduped). |
| packages/core/src/node/route/extractPageData.ts | Captures deps from flattenMdxContent() and stores them as _deps on page index info. |
| packages/core/src/node/route/extractPageData.test.ts | Updates snapshot to include _deps for recursive import fixtures. |
| .changeset/fresh-pages-refresh.md | Documents the patch behavior change for dev refresh on imported Markdown dependency updates. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Fix page data generation so development virtual modules refresh after invalidation while production builds reuse the authoritative result. Track imported Markdown dependencies so page data and local search indexes update when included content changes.
Context
Extracted from #3520 as an independently reviewable Core prerequisite. The other prerequisites split from that PR are #3591 and #3592.
Related Issue
N/A
Checklist