fix(core): include mod in SSR route-cache entry to silence false-positive warning#16864
Merged
Merged
Conversation
…sitive warning The fast-path check added in withastro#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 withastro#16863 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 444b357 The changes in this PR will be included in the next version bump. This PR includes changesets to release 405 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 |
`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>
ematipico
requested changes
May 26, 2026
Comment on lines
+199
to
+205
| const capturingDestination: AstroLoggerDestination<AstroLoggerMessage> = { | ||
| write: (msg) => { | ||
| messages.push(msg.message); | ||
| return true; | ||
| }, | ||
| }; | ||
| const warnLogger = new AstroLogger({ destination: capturingDestination, level: 'warn' }); |
Member
There was a problem hiding this comment.
Use the SpyLogger for these cases
| // subsequent requests; otherwise `cached.mod === mod` is always false | ||
| // in SSR and we re-enter this branch, triggering the "route cache | ||
| // overwritten" warning on every request after the first. | ||
| routeCache.set(route, { ...cached, mod, staticPaths: entry }); |
Member
There was a problem hiding this comment.
At this point it's best to update RouteCacheEntry and make sure we provide mod every time
Comment on lines
+5
to
+9
| Fixes a regression introduced in 6.3.6 (#16776) where dynamic SSR routes logged `Internal Warning: route cache overwritten.` on every request after the first, per worker isolate. | ||
|
|
||
| The SSR branch in `callGetStaticPaths` stored its empty static-paths entry without `mod`, so the new `cached.mod === mod` fast-path check always failed, control fell back into the SSR branch and `routeCache.set()` ran again. In production this triggered the warning at the top of `RouteCache.set()`. | ||
|
|
||
| The SSR-branch entry now includes `mod`, so the fast-path hits cleanly on subsequent requests and no spurious warning is logged. |
Member
There was a problem hiding this comment.
This changeset is too long for this file. Here's a guide https://contribute.docs.astro.build/docs-for-code-changes/changesets/#tips-and-examples
| assert.equal(result3.keyed.get('/one')?.props?.title, 'new'); | ||
| }); | ||
|
|
||
| it('does not log "route cache overwritten" on repeated SSR requests for the same module', async () => { |
Member
There was a problem hiding this comment.
Why this test is different from the previous?
Contributor
|
Thanks for submitting this. |
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.
ematipico
approved these changes
May 26, 2026
Merged
dadezzz
pushed a commit
to dadezzz/university_notes
that referenced
this pull request
May 30, 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.7` → `6.3.8`](https://renovatebot.com/diffs/npm/astro/6.3.7/6.3.8) |  |  | --- ### Release Notes <details> <summary>withastro/astro (astro)</summary> ### [`v6.3.8`](https://github.com/withastro/astro/blob/HEAD/packages/astro/CHANGELOG.md#638) [Compare Source](https://github.com/withastro/astro/compare/astro@6.3.7...astro@6.3.8) ##### Patch Changes - [#​16830](withastro/astro#16830) [`f2bf3cb`](withastro/astro@f2bf3cb) Thanks [@​matthewp](https://github.com/matthewp)! - Fixes 404s for dynamically imported JS chunks when using an adapter with `assetQueryParams` (e.g. Vercel skew protection) - [#​16831](withastro/astro#16831) [`ace96ba`](withastro/astro@ace96ba) Thanks [@​astrobot-houston](https://github.com/astrobot-houston)! - Fixes a misleading `GetStaticPathsRequired` error when a redirect is configured from a dynamic route to a static (or less-dynamic) destination. For example, `'/project/[slug]': '/'` previously produced a confusing error pointing at `index.astro`. Astro now detects the parameter mismatch at config validation time and throws a clear `InvalidRedirectDestination` error naming the missing parameters. - [#​16702](withastro/astro#16702) [`b7d1758`](withastro/astro@b7d1758) Thanks [@​matthewp](https://github.com/matthewp)! - Fixes scoped styles from `.astro` components being dropped when rendered inside MDX content (`<Content />` from `render(entry)`) passed through a named slot using `<Fragment slot="X">`. The Fragment component now eagerly evaluates its slot contents to ensure propagating components register their styles before head content is flushed. - [#​16823](withastro/astro#16823) [`3df6a45`](withastro/astro@3df6a45) Thanks [@​astrobot-houston](https://github.com/astrobot-houston)! - Fixes missing CSS for conditionally rendered Svelte components in production builds - [#​16836](withastro/astro#16836) [`3d7adfa`](withastro/astro@3d7adfa) Thanks [@​LongYC](https://github.com/LongYC)! - Document compressHTML: "jsx" config is only available since Astro v6.2.0 - [#​16864](withastro/astro#16864) [`334ce13`](withastro/astro@334ce13) Thanks [@​cheets](https://github.com/cheets)! - Fixes a false-positive `Internal Warning: route cache overwritten` logged on every SSR request for dynamic routes </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:eyJjcmVhdGVkSW5WZXIiOiI0My4xOTUuNiIsInVwZGF0ZWRJblZlciI6IjQzLjE5NS42IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
1 task
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
modin the SSR-branch cache entry incallGetStaticPathsso the newcached.mod === modfast-path actually hits on subsequent SSR requests for the same component.Before this patch, the SSR branch wrote
{ ...cached, staticPaths: entry }withoutmod. The fast-path added in #16776 (cached?.staticPaths && cached.mod === mod) therefore always failed on the second request, control fell back into the SSR branch,routeCache.set()ran again, andRouteCache.set()emittedInternal Warning: route cache overwrittenat the top of the function — once per dynamic-route component per worker isolate, on every request after the first, in production.The static branch already stores
modso it was unaffected.Closes #16863.
Testing
Added a unit test in
packages/astro/test/units/routing/getstaticpaths-cache.test.ts:It constructs a
RouteCachein production mode with a capturing logger destination, callscallGetStaticPathsthree times withssr: true,prerender: false, the samemod, and asserts noroute cache overwrittenmessage was logged. The existing HMR and prerendered-route tests continue to pass.Docs
No docs changes — fixes an internal warning, no public API change.