Invalidate route cache when module identity changes after HMR#16776
Merged
Conversation
🦋 Changeset detectedLatest commit: e29a210 The changes in this PR will be included in the next version bump. This PR includes changesets to release 417 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 |
The route cache stores getStaticPaths() return values keyed by route path, but never checked whether the module that produced those values had been re-evaluated. After HMR, components passed as props via getStaticPaths() remained stale even on manual refresh. Store the module reference in the cache entry and compare identity on lookup. A new module object (from a fresh import after HMR) causes the cache to miss, re-calling getStaticPaths() with updated references. Fixes #16522
5568beb to
e29a210
Compare
Merged
ematipico
pushed a commit
that referenced
this pull request
May 20, 2026
The route cache stores getStaticPaths() return values keyed by route path, but never checked whether the module that produced those values had been re-evaluated. After HMR, components passed as props via getStaticPaths() remained stale even on manual refresh. Store the module reference in the cache entry and compare identity on lookup. A new module object (from a fresh import after HMR) causes the cache to miss, re-calling getStaticPaths() with updated references. Fixes #16522
dadezzz
pushed a commit
to dadezzz/university_notes
that referenced
this pull request
May 24, 2026
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [astro](https://astro.build) ([source](https://github.com/withastro/astro/tree/HEAD/packages/astro)) | [`6.3.5` → `6.3.6`](https://renovatebot.com/diffs/npm/astro/6.3.5/6.3.6) |  |  | --- ### Release Notes <details> <summary>withastro/astro (astro)</summary> ### [`v6.3.6`](https://github.com/withastro/astro/blob/HEAD/packages/astro/CHANGELOG.md#636) [Compare Source](https://github.com/withastro/astro/compare/astro@6.3.5...astro@6.3.6) ##### Patch Changes - [#​16774](withastro/astro#16774) [`8f77583`](withastro/astro@8f77583) Thanks [@​astrobot-houston](https://github.com/astrobot-houston)! - Fixes markdown images with empty alt text (``) in content collections dropping the `alt` attribute entirely. The `alt=""` attribute is now correctly preserved in the rendered HTML output, which is important for accessibility (indicating decorative images). - [#​16776](withastro/astro#16776) [`3d10b5e`](withastro/astro@3d10b5e) Thanks [@​matthewp](https://github.com/matthewp)! - Fixes HMR serving stale content when components are passed as props via `getStaticPaths()` - [#​16784](withastro/astro#16784) [`7453860`](withastro/astro@7453860) Thanks [@​ematipico](https://github.com/ematipico)! - Improved the printing of the build time if it goes over the 60 seconds. - [#​16665](withastro/astro#16665) [`3dbbcee`](withastro/astro@3dbbcee) Thanks [@​Princesseuh](https://github.com/Princesseuh)! - Fixes remote SVG sources erroring with `dangerouslyProcessSVG` after the v6.3 SVG-processing gate. The default Sharp service now resolves the output format from the source up-front when it can (URL extension, `data:` MIME, ESM metadata), and from the actual buffer at request time when it can't, so SVG sources pass through untouched without needing to set `image.dangerouslyProcessSVG: true` or an explicit `format="svg"`. The error message has also been updated to point at `format="svg"` as the simpler workaround when an SVG source is encountered without `dangerouslyProcessSVG` enabled. - [#​16777](withastro/astro#16777) [`1754b91`](withastro/astro@1754b91) Thanks [@​matthewp](https://github.com/matthewp)! - Fixes HMR serving stale content for dynamically imported components through barrel files - [#​16730](withastro/astro#16730) [`068d924`](withastro/astro@068d924) Thanks [@​harshagarwalnyu](https://github.com/harshagarwalnyu)! - Fixes an issue where the `file()` content loader did not generate a valid JSON Schema for collections whose JSON or YAML data is a top-level array instead of an object. </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xODIuMSIsInVwZGF0ZWRJblZlciI6IjQzLjE4Mi4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
1 task
matthewp
added a commit
that referenced
this pull request
May 26, 2026
…sitive warning (#16864) * fix(core): include `mod` in SSR route-cache entry to silence false-positive warning The fast-path check added in #16776 (`cached.mod === mod`) was never satisfied for SSR dynamic routes because the SSR branch in `callGetStaticPaths` stored its empty entry without `mod`. Every request after the first re-entered the SSR branch, called `routeCache.set()` again, and triggered `Internal Warning: route cache overwritten` in production. Store `mod` alongside the SSR entry so the fast-path hits cleanly. Closes #16863 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * test: drop `default: () => null` mock that broke astro-check typecheck `AstroComponentFactory` requires a non-null return value. The SSR non-prerender path never touches `mod.default`, so an empty mock object is sufficient. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Address review feedback on PR #16864 Related: 93ea130, 3d10b5e ## Goal Address ematipico's review comments on the SSR route-cache fix PR. ## Decisions - Made RouteCacheEntry.mod required instead of optional: both set() call sites already provide mod (the function throws early if mod is undefined), so the optional marker was lying about the actual invariant. - Converted the entire test describe block to use SpyLogger: the reviewer asked why the new test was different from the others, and the cleanest answer was to unify them all on SpyLogger rather than keeping a mix of hand-rolled AstroLogger+destination and SpyLogger. - Shortened changeset to a single user-facing sentence per the Astro changeset guide (patch changes need one line, not implementation details). ## Changes - .changeset/ssr-route-cache-mod.md: Replaced 3-paragraph explanation with single-line patch description. - route-cache.ts: Changed RouteCacheEntry.mod from optional to required. - getstaticpaths-cache.test.ts: Replaced manual AstroLoggerDestination with SpyLogger throughout. Removed before() hook, moved logger creation into beforeEach(). New SSR test uses spyLogger.logs for assertions. --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: Matthew Phillips <matthew@matthewphillips.info>
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.
Changes
callGetStaticPaths) now stores the module reference alongside cached static paths and compares identity on lookup. After HMR,modis a new object from a freshimport(), so the cache treats the old entry as stale and re-callsgetStaticPaths()with updated component references. This fixes the case where components passed as props viagetStaticPaths()served stale content in dev — even on manual refresh.Fixes #16522
Testing
getstaticpaths-cache.test.ts: "re-calls getStaticPaths when module identity changes (HMR)" — callscallGetStaticPathswith one module, confirms cache hit on same module, then passes a different module object and asserts the cache is bypassed and fresh props are returned.Docs