You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Plugin hook transformPageData result is cached per page, making it impossible to inject shared data that changes independently of page content #5193
Is your feature request related to a problem? Please describe.
Yes. When a VitePress plugin uses transformPageData to inject shared/global data (such as a site-wide page hierarchy) into every page, the result is cached per page file by VitePress's internal markdown LRU cache. When any source file changes, VitePress only re-runs transformPageData for that specific file — all other pages continue serving stale cached data until the dev server is restarted. There is no public API to invalidate this cache from a plugin.
Describe the solution you'd like
A way to opt out of the markdown cache for a specific transformPageData hook, or a lifecycle hook that runs before the cache is consulted on every page request. Alternatively, exposing a public clearCache() function that plugins can call to invalidate the markdown LRU cache when their shared data changes.
Describe alternatives you've considered
Calling VitePress's internal clearCache function located by scanning the dist/node/chunk-*.js files at runtime — this works but relies on an undocumented internal that can break on any VitePress update. Also considered serving shared data via a custom dev middleware endpoint and fetching it client-side, but this requires different code paths for dev and build, significantly complicating plugin architecture.
Additional context
This affects any plugin that injects global or hierarchical data into pages — not just navigation trees. The pattern of computing shared data once and embedding it into every page's __pageData is a natural fit for transformPageData, but the per-file caching makes it unreliable in dev whenever the shared data can change independently of the page being viewed. A real-world example is a site hierarchy built from all pages' frontmatter: changing a label on one page should be reflected in the navigation of every other page, but currently requires a dev server restart.
Worth mentioning: the issue results from several iterations of Vibe-coding with Anthropic Claude to implement a generic theme for VitePress I'd like to use with more regular websites driven by markdown files. Everything provided here except for this paragraph has been provided by the AI coding agent trying to fix the issue for about an hour investigating back and forth the setup. The particular scenario is a breacrumb menu on a page properly updating its view when adjusting the frontmatter of another page listed in the breadcrumb, too. Eventually I'd like to have a clean future-proof solution instead of having to search the chunks of a VitePress release for an internal function.
Thanks for picking this up! Functionally this matches what I've been doing as a workaround in my plugin (clear the md cache, invalidate the graph, full reload), and the test reproduces my scenario well.
Some remarks:
The PR includes unrelated files (Dockerfile, Makefile, .nvmrc, README section) — probably better split out.
This fix turns every markdown edit into a full reload for any site that uses transformPageData, even when it only derives data from the page itself. An opt-in (e.g. a public clearCache() or a config flag) would keep HMR for those sites.
Since we are on 1.x the fix won't reach our current state of implementation unless there is either a backport or a final 2.x release.
@soletan Thanks for the detailed feedback! I'll clean up the unrelated files and look into an opt-in approach that preserves HMR for sites that don't need cross-page invalidation. I'll also check the intended release target with the maintainers before making further changes.
@soletan Thanks for the feedback! I've updated [PR #5546](#5546) to address the suggested changes:
Removed the unrelated development-environment changes.
Made cross-page cache invalidation opt-in through the experimental transformPageDataHmr option, defaulting to false, so existing HMR behavior is preserved by default.
Thanks, this looks good to me now — the opt-in is exactly what I had in mind, and the tests cover my scenario (shared data derived from other pages' frontmatter) including repeated edits.
Regarding 1.x: a backport would let me drop my workaround earlier, but I can keep it until I move to 2.x. I'd leave that decision to the maintainers rather than holding up this PR.
Thanks, @soletan , for the thoughtful feedback and for confirming that the updated approach addresses your use case!
The suggested changes are now in place, and the PR has been updated accordingly.
Could a maintainer please review [PR #5546](#5546) when convenient? If everything looks good, I'd appreciate your consideration for merging it. Thanks!
Activity
parnilV06 commentedon Oct 16, 2026
I would like to work on this issue
parnilV06 commentedon Oct 19, 2026
Hi! I've opened [PR #5546](#5546) to address this issue. I'd appreciate it if you could review it and suggest any changes needed. Thank you!
soletan commentedon Oct 20, 2026
Thanks for picking this up! Functionally this matches what I've been doing as a workaround in my plugin (clear the md cache, invalidate the graph, full reload), and the test reproduces my scenario well.
Some remarks:
parnilV06 commentedon Oct 21, 2026
@soletan Thanks for the detailed feedback! I'll clean up the unrelated files and look into an opt-in approach that preserves HMR for sites that don't need cross-page invalidation. I'll also check the intended release target with the maintainers before making further changes.
parnilV06 commentedon Oct 21, 2026
@soletan Thanks for the feedback! I've updated [PR #5546](#5546) to address the suggested changes:
transformPageDataHmroption, defaulting tofalse, so existing HMR behavior is preserved by default.transformPageData.I've also updated the PR description with the revised implementation and validation results.
The PR still targets
main. Could you clarify whether a separate VitePress 1.x backport would be useful?soletan commentedon Oct 21, 2026
Thanks, this looks good to me now — the opt-in is exactly what I had in mind, and the tests cover my scenario (shared data derived from other pages' frontmatter) including repeated edits.
Regarding 1.x: a backport would let me drop my workaround earlier, but I can keep it until I move to 2.x. I'd leave that decision to the maintainers rather than holding up this PR.
parnilV06 commentedon Oct 22, 2026
Thanks, @soletan , for the thoughtful feedback and for confirming that the updated approach addresses your use case!
The suggested changes are now in place, and the PR has been updated accordingly.
Could a maintainer please review [PR #5546](#5546) when convenient? If everything looks good, I'd appreciate your consideration for merging it. Thanks!