Repository navigation
Fix middleware hmr behaviour - #17605
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: 07a05a6 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 |
ashleigh-yeoman
force-pushed
the
fix-17590
branch
from
August 6, 2026 08:15
fb6fa32 to
2470533
Compare
ashleigh-yeoman
force-pushed
the
fix-17590
branch
from
August 6, 2026 11:13
2470533 to
07a05a6
Compare
ematipico
approved these changes
Aug 6, 2026
Merged
Contributor
Author
|
@ematipico sorry there's a test case I'd forgotten that I've just realised. I've created a patch file containing it. The test case passes, thankfully. |
Member
|
You can send another PR if you want |
Merged
ashleigh-yeoman
added a commit
to ashleigh-yeoman/astro
that referenced
this pull request
Aug 7, 2026
Merged PR that was missing this case: withastro#17605
ematipico
pushed a commit
that referenced
this pull request
Aug 7, 2026
Merged PR that was missing this case: #17605
thelazylamaGit
pushed a commit
to thelazylamaGit/astro
that referenced
this pull request
Aug 7, 2026
Merged PR that was missing this case: withastro#17605
dadezzz
pushed a commit
to dadezzz/university_notes
that referenced
this pull request
Aug 16, 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)) | [`7.2.0` → `7.2.1`](https://renovatebot.com/diffs/npm/astro/7.2.0/7.2.1) |  |  | --- ### Release Notes <details> <summary>withastro/astro (astro)</summary> ### [`v7.2.1`](https://github.com/withastro/astro/blob/HEAD/packages/astro/CHANGELOG.md#721) [Compare Source](https://github.com/withastro/astro/compare/[email protected]@7.2.1) ##### Patch Changes - [#​17612](withastro/astro#17612) [`7133730`](withastro/astro@7133730) Thanks [@​thelazylamaGit](https://github.com/thelazylamaGit)! - Fixes CSS hot module replacement after navigating between pages with `ClientRouter` - [#​17628](withastro/astro#17628) [`4ada248`](withastro/astro@4ada248) Thanks [@​astrobot-houston](https://github.com/astrobot-houston)! - Fixes a CSP violation when using both `security.csp` and `experimental.clientPrerender` with `data-astro-prefetch` links. The dynamically injected `<script type="speculationrules">` now uses a static `"source": "document"` approach with a CSS selector, producing a deterministic payload that is hashed and included in the CSP `script-src` directive at build time. - [#​17605](withastro/astro#17605) [`89e4647`](withastro/astro@89e4647) Thanks [@​ashleigh-yeoman](https://github.com/ashleigh-yeoman)! - Fixes middleware HMR not responding to changes in imported modules. Previously, only direct edits to the middleware file would trigger a reload. - [#​17582](withastro/astro#17582) [`bd2c1a5`](withastro/astro@bd2c1a5) Thanks [@​astrobot-houston](https://github.com/astrobot-houston)! - Fixes a regression where content collection `reference()` fields silently accepted entry IDs that don't exist, such as an ID that doesn't match a loader's slugified version of it. Astro now logs an error for references that point to a missing entry after all loaders finish syncing. - [#​17661](withastro/astro#17661) [`97b0cc7`](withastro/astro@97b0cc7) Thanks [@​ArmandPhilippot](https://github.com/ArmandPhilippot)! - Improves Markdown options documentation with links to the Markdown guide and official processors. - [#​17349](withastro/astro#17349) [`4328c73`](withastro/astro@4328c73) Thanks [@​astrobot-houston](https://github.com/astrobot-houston)! - Fixes an issue where requests handled by the dev prerender environment (e.g. `/_image` with `@astrojs/cloudflare`'s `prerenderEnvironment: 'node'`) returned a 500 when a prerendered catch-all route existed, because non-prerendered route modules were imported in an environment where their runtime-specific APIs are unavailable - [#​17603](withastro/astro#17603) [`722eed6`](withastro/astro@722eed6) Thanks [@​astrobot-houston](https://github.com/astrobot-houston)! - Fixes `<video>` and `<audio>` elements being non-functional after navigating via view transitions (`<ClientRouter />`) - [#​17616](withastro/astro#17616) [`3a890d2`](withastro/astro@3a890d2) Thanks [@​lazerg](https://github.com/lazerg)! - Fixes `experimental.incrementalBuild` re-rendering unchanged routes that import more than one asset. The route's dependency hash depended on the order the assets finished building, so two builds of identical sources could produce different hashes. The hash is now based on the file name each asset resolves to. - [#​17547](withastro/astro#17547) [`fba468c`](withastro/astro@fba468c) Thanks [@​dmgawel](https://github.com/dmgawel)! - Improves `getCollection()` and `getEntry()` performance for entries without local image references - [#​17602](withastro/astro#17602) [`16e0d9d`](withastro/astro@16e0d9d) Thanks [@​astrobot-houston](https://github.com/astrobot-houston)! - Fixes a build error caused by hash collisions in generated content collection image import identifiers </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 CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xNy4xIiwidXBkYXRlZEluVmVyIjoiNDQuMTcuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->
mhsnook
pushed a commit
to mhsnook/bug-repro-astro
that referenced
this pull request
Sep 7, 2026
Both from a maintainer's review, both checked against shipped code here before being written down. The Astro end is a regression, not the plugin's design. 7.2.0 watched changes itself and returned early twice — once if the path was not under srcDir, again if it was not the middleware file — so a .wrangler write cost nothing. 7.2.1 replaced that with a hotUpdate handler taking no arguments and no guards. Counting isMiddlewarePath( in the shipped file gives two occurrences in 7.2.0 and one, the definition, in 7.2.1 and 7.3.1: the function is still there, still exported, with no callers. withastro/astro#17605, merged 2026-08-06, closed #17590 by making transitive imports trigger HMR; widening the match is the point of it, losing the path check reads as incidental. This matters for what gets filed. "Astro invalidates unconditionally" invites an argument about design. "Astro used to check and stopped in 7.2.1, and left the checking function exported with no callers" is a regression report with a commit attached. The proposed patch was also wrong. **/.wrangler/** only covers the default: getPersistenceRoot resolves persistState.path against the Vite root, so a configured path goes anywhere and the glob misses it. resourcePersistencePath is already computed from it a few lines down, so the plugin should ignore that and follow its own configuration. The user-side workaround stays a glob, because a user cannot name the resolved path, and now says so. One further correction from the same review does not apply here: the three [router] warnings are one app instance reporting three features from #warnMissingFeatures, not three HMR passes. Nothing in this repository used them as corroboration; the 3-hooks figure is counted from the plugin hook itself. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HirQxF9ePMJEn59VitiJHG
mhsnook
pushed a commit
to mhsnook/astro
that referenced
this pull request
Sep 8, 2026
The middleware plugin invalidates its virtual module on every hotUpdate, whatever changed. Any process writing a file under the Vite root during development causes an invalidation per write. A change Vite matched no modules for cannot be the middleware and cannot be anything the middleware imports, so returning early on an empty ctx.modules costs nothing and stops the unrelated invalidations. This deliberately does not restore the isMiddlewarePath check that 7.2.0 used. That check would undo withastro#17605: transitive imports of the middleware are modules in the graph but are not middleware paths, and they need to keep triggering HMR. Testing ctx.modules keeps that behaviour and only excludes changes that are not modules at all. Measured on a minimal reproduction, astro 7.3.1 with @astrojs/cloudflare, median of five requests after warm-up. That adapter rewrites its trace store under .wrangler/state while serving, inside the Vite root, so each request is a file change and no editing is needed to trigger this: with src/middleware.ts, as shipped 0.50s with src/middleware.ts, with this 0.09s no middleware at all 0.14s With the fix a pass-through middleware is no longer measurable against having none. On a larger application the same change takes page loads from about 7s to about 0.13s, since the cost scales with the SSR module graph. It also fixes withastro#17922, where prerendered routes fail nondeterministically on workerd in dev. On that issue's own reproduction, at its pinned versions, five cold runs each failed at least one route (14 of 35); with this change, fifteen consecutive cold runs passed every route. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HirQxF9ePMJEn59VitiJHG
1 task done
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
Fixes the previous attempt to get HMR working for middleware. Now any imports (and transitive imports) in
middleware.tscan trigger HMR formiddleware.ts, instead of just itself.This is meant to be a cleaner and better-tested version of #17597
Closes #17590
Testing
3 tests added to
packages/astro/test/middleware.test.ts, covering the 3 main HMR casesmiddleware.tsis modifiedmiddleware.tsis modifiedmiddleware.ts) is modifiedDocs
No docs update needed. This PR fixes a bug in HMR behavior, with no API changes.