Skip to content

fix(core): preserve page data lifecycle during HMR - #3590

Open
SoonIter wants to merge 1 commit into
mainfrom
fix/page-data-hmr-lifecycle
Open

fix(core): preserve page data lifecycle during HMR#3590
SoonIter wants to merge 1 commit into
mainfrom
fix/page-data-hmr-lifecycle

Conversation

@SoonIter

@SoonIter SoonIter commented Aug 7, 2026

Copy link
Copy Markdown
Member

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

  • Tests updated.
  • Documentation updated (not required).

Copilot AI lite review requested due to automatic review settings August 7, 2026 07:47
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 0 projects with changes.

📊 Quick Summary
Project Total Size Gzip Size Change Gzip Change
website_html 14.2 MB 2.0 MB 0 0
website_md 1.8 MB 262.4 KB 0 0
website_js 16.7 MB 2.9 MB 0 0
auto_nav_sidebar_html 447.5 KB 93.4 KB 0 0
auto_nav_sidebar_js 544.1 KB 171.5 KB 0 0

Generated by Rsdoctor GitHub Action

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying rspress-v2 with  Cloudflare Pages  Cloudflare Pages

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

View logs

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +90 to +93
setPageDataAlias(
alias,
environment.name === 'web' ? 'web' : 'fallback',
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 _deps to PageIndexInfo and plumb flattenMdxContent() dependency tracking into extracted page index info.
  • Include _deps in 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants