Repository navigation
Fix astro sync replacing a running dev server's optimized dependencies - #18451
Conversation
`astro sync`, which `astro check` and `astro build` also run, starts a
temporary Vite server with `optimizeDeps: { noDiscovery: true }`. Astro
and integrations still add `optimizeDeps.include` entries, so Vite keeps
the dependency optimizer running there, and it wrote to the default
Vite cache. That replaced the optimized dependencies of a dev server
running in the same project, so framework islands in that dev server
broke (for example React's production `jsx-dev-runtime`, where `jsxDEV`
is undefined) until it was restarted with `--force`.
The temporary server now writes to `<cacheDir>/vite-sync/`. It optimizes
the same dependencies as before; only the output location changes.
Fixes withastro#18449
Tested: `astro-sync.test.ts` passes 10/10; the new test fails without
the change in `sync/index.ts`.
🦋 Changeset detectedLatest commit: e873dff The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Merging this PR will not alter performance
|
There was a problem hiding this comment.
Verdict: approved. No blocking findings remain.
Findings
No findings.
Merge Requirement Assessment
Status: satisfied
- The temporary Vite server used by
astro sync,astro checkandastro buildmust not write optimized dependencies into the cache a runningastro devreads (#18449).createTempViteServernow passescacheDir: fileURLToPath(new URL('./vite-sync/', settings.config.cacheDir))in the command config (packages/astro/src/core/sync/index.ts:260).createVitemerges this config last (create-vite.ts:370), so it overrides two other values: Astro's defaultnode_modules/.vite/and any user-setvite.cacheDir. The relative schema always resolvesconfig.cacheDirto a directory URL ending in/, so thenew URLcall reliably resolves to a subdirectory. All three commands reach this server throughsyncInternalwhenever content sync is not skipped. - Plugins should see the same config and optimize the same dependencies; only the output location changes.
optimizeDeps,ssrand the plugin pipeline are unchanged, and the diff only addscacheDir. - Regression coverage. The new test in
test/astro-sync.test.tswrites a placeholdernode_modules/.vite/deps/_metadata.json, runs sync and asserts the file is unchanged. Without the change, sync's optimizer output would overwrite the placeholder and the assertion would fail. The test cleans up infinally. Its fixture has its owncacheDirandoutDir, and other tests don't start a dev server on it.
Review Status
Verdict: ready to merge based on static review
Context: PR #18451, plus the linked issue #18449 as described in the PR body
Scope: PR base c55134c1 to head e873dff3 (3 files: sync/index.ts, astro-sync.test.ts, and the changeset).
Changeset: present and covers astro (patch).
Limitations: The linked issue was not fetched separately; requirements came from the PR description.
Validation: Static review only; no project code, tests, builds, or checks were run.
GitHub context: collected
Git scope: PR base/head verified
This review was made by an LLM. The analysis may be wrong, and reports might be incorrect.
matthewp
left a comment
There was a problem hiding this comment.
I'm a little unsure about this but think we can merge this version and see what happens. The downside to using a different cache directory for sync is that you lose cache-warming when sync runs first, but I don't think that's the common case anyways.
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [@astrojs/check](https://github.com/withastro/astro/tree/main/packages/language-tools/astro-check) ([source](https://github.com/withastro/astro/tree/HEAD/packages/language-tools/astro-check)) | [`0.9.11` → `0.9.12`](https://renovatebot.com/diffs/npm/@astrojs%2fcheck/0.9.11/0.9.12) |  |  | | [@astrojs/markdown-remark](https://astro.build) ([source](https://github.com/withastro/astro/tree/HEAD/packages/markdown/remark)) | [`7.3.3` → `7.3.4`](https://renovatebot.com/diffs/npm/@astrojs%2fmarkdown-remark/7.3.3/7.3.4) |  |  | | [astro](https://astro.build) ([source](https://github.com/withastro/astro/tree/HEAD/packages/astro)) | [`7.4.1` → `7.4.2`](https://renovatebot.com/diffs/npm/astro/7.4.1/7.4.2) |  |  | --- ### Release Notes <details> <summary>withastro/astro (@​astrojs/check)</summary> ### [`v0.9.12`](https://github.com/withastro/astro/blob/HEAD/packages/language-tools/astro-check/CHANGELOG.md#0912) [Compare Source](https://github.com/withastro/astro/compare/@astrojs/check@0.9.11...@astrojs/check@0.9.12) ##### Patch Changes - [#​18455](withastro/astro#18455) [`7af66fc`](withastro/astro@7af66fc) Thanks [@​astro-factory](https://github.com/apps/astro-factory)! - Fixes the `astro-check` binary ignoring its first two command-line arguments, so flags such as `--help`, `--root`, `--watch`, and `--tsconfig` are respected again. If your scripts padded the arguments to work around this (for example, `astro-check -- -- --tsconfig ./tsconfig.app.json`), remove the padding. - Updated dependencies \[[`044148d`](withastro/astro@044148d)]: - [@​astrojs/language-server](https://github.com/astrojs/language-server)@2.17.3 </details> <details> <summary>withastro/astro (@​astrojs/markdown-remark)</summary> ### [`v7.3.4`](https://github.com/withastro/astro/blob/HEAD/packages/markdown/remark/CHANGELOG.md#734) [Compare Source](https://github.com/withastro/astro/compare/@astrojs/markdown-remark@7.3.3...@astrojs/markdown-remark@7.3.4) ##### Patch Changes - Updated dependencies \[[`cf27e70`](withastro/astro@cf27e70)]: - [@​astrojs/prism](https://github.com/astrojs/prism)@4.1.1 </details> <details> <summary>withastro/astro (astro)</summary> ### [`v7.4.2`](https://github.com/withastro/astro/blob/HEAD/packages/astro/CHANGELOG.md#742) [Compare Source](https://github.com/withastro/astro/compare/astro@7.4.1...astro@7.4.2) ##### Patch Changes - [#​18430](withastro/astro#18430) [`dda9ec3`](withastro/astro@dda9ec3) Thanks [@​Abhirup-99](https://github.com/Abhirup-99)! - Speeds up content sync with `experimental.collectionStorage: "chunked"` by computing each character's UTF-8 width from its code point instead of encoding every character through `TextEncoder`. On a store of \~44k entries this cuts the chunking step from about 60 seconds to well under a second, with byte-identical output. - [#​18438](withastro/astro#18438) [`5e0eaa4`](withastro/astro@5e0eaa4) Thanks [@​astro-factory](https://github.com/apps/astro-factory)! - Fixes `astro dev` with `@astrojs/cloudflare` failing with ``Calling `require` for "node-fetch"`` when a server dependency such as `cross-fetch` requires `node-fetch` - [#​18376](withastro/astro#18376) [`a4e201d`](withastro/astro@a4e201d) Thanks [@​okxint](https://github.com/okxint)! - Fixes `astro dev` treating a stale lock file containing a Linux thread ID as a running Astro server. A successful process lookup with no matching PID now marks the lock as stale, preventing `astro dev stop` and `astro dev --force` from killing the unrelated process that owns the thread. - [#​18467](withastro/astro#18467) [`d1fb7d3`](withastro/astro@d1fb7d3) Thanks [@​astro-factory](https://github.com/apps/astro-factory)! - Fixes the `defineConfig()` types for `i18n.defaultLocale`, `i18n.fallback`, and `i18n.domains` so they accept a custom locale's `path` instead of its `codes`, matching how Astro validates and uses these values - [#​18475](withastro/astro#18475) [`cf27e70`](withastro/astro@cf27e70) Thanks [@​ematipico](https://github.com/ematipico)! - Bumps the minimum supported Node.js version to 22.23.4, which includes the fixes from the [October 2026 Node.js security releases](https://nodejs.org/en/blog/vulnerability/october-2026-security-releases) This is a patch release because the [Node.js support and upgrade policy](https://docs.astro.build/en/upgrade-astro/#nodejs-support-and-upgrade-policies) allows the Core team to raise the minimum Maintenance LTS version in a patch release when a disclosed and fixed Node.js security flaw affects Astro. - [#​18451](withastro/astro#18451) [`7a0ba6f`](withastro/astro@7a0ba6f) Thanks [@​DenisCDev](https://github.com/DenisCDev)! - Fixes `astro sync`, `astro check` and `astro build` replacing the optimized dependencies of a dev server running in the same project, which broke framework islands in that dev server until it was restarted with `--force` - [#​18336](withastro/astro#18336) [`e943003`](withastro/astro@e943003) Thanks [@​astro-factory](https://github.com/apps/astro-factory)! - Fixes inline styles in dev so that framework-transformed CSS is used, such as scoped styles and `v-bind()` in Vue single-file components - [#​18399](withastro/astro#18399) [`829fc00`](withastro/astro@829fc00) Thanks [@​astro-factory](https://github.com/apps/astro-factory)! - Fixes a dev server error (`Could not find server component name`) for a `server:defer` island that imports `astro:actions` or `astro:config/server`, when its page was not the first island page loaded after starting the server - [#​18330](withastro/astro#18330) [`4db9e0d`](withastro/astro@4db9e0d) Thanks [@​Samuteg](https://github.com/Samuteg)! - Fixes the `astro:env/server` virtual module being generated with invalid JS in dev when any environment variable contains `$` replacement patterns (`` $` ``, `$&`, `$'`, `$1`, …). The inlined env JSON was passed as a string to `String.replace`, so e.g. the `KITTY_PUBLIC_KEY` value set by default in Kitty terminals corrupted the module and broke dev with `Failed to parse source for import analysis` - Updated dependencies \[[`cf27e70`](withastro/astro@cf27e70)]: - [@​astrojs/telemetry](https://github.com/astrojs/telemetry)@3.4.1 - [@​astrojs/markdown-satteri](https://github.com/astrojs/markdown-satteri)@0.4.5 </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. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://github.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- 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:eyJjcmVhdGVkSW5WZXIiOiI0NC4xODEuMSIsInVwZGF0ZWRJblZlciI6IjQ0LjE4MS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
* Fix corrupted `astro:env/server` module when env vars contain `$` replacement patterns (#18330) * [ci] format * Fix inlined Vue styles in dev serving untransformed (unscoped, raw v-bind) CSS (#18336) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * fix(deps): update vitest monorepo to v5 (#18403) Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev> * Update Partytown to 1.0.1 (#18439) * fix(cloudflare): return 4xx instead of 500 from `/_image` when the source isn't an image (#18422) Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> * Skip server island manifest in CSS ensureModulesLoaded to fix late-discovery 500 in dev (#18399) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * Fix astro-check binary silently dropping the first two CLI arguments (#18455) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * Preserve sharpImageService() options when imageService: 'compile' is used in the Cloudflare adapter (#18461) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * fix(check): skip Volar's cancellation polling sleep in `astro check` (#18460) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * fix(content): compute UTF-8 width arithmetically in getChunkEnd (#18430) * fix(content): compute UTF-8 width arithmetically in getChunkEnd * test(content): cover UTF-8 width boundaries and lone surrogates in chunkString * chore: changeset * fix(cloudflare): don't prebundle Astro in the Node prerender environment so a custom src/fetch.ts renders through the dev environment (#18465) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * Respect exact version argument in @astrojs/upgrade (#18466) * fix(upgrade): respect exact version argument in @astrojs/upgrade * fix(upgrade): only pin exact version for the astro package Integrations are versioned independently, so a published version string matching the requested Astro version must not be used for them; they keep the dist-tag/latest fallback instead of being downgraded. --------- Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * fix(i18n): use locale path instead of codes in defineConfig i18n types (#18467) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * fix(cloudflare): skip Prism optimizeDeps include during type generation so sync/check/build don't overwrite a running dev server's deps_ssr (#18468) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * Use a separate Vite cache for the temporary sync server (#18451) `astro sync`, which `astro check` and `astro build` also run, starts a temporary Vite server with `optimizeDeps: { noDiscovery: true }`. Astro and integrations still add `optimizeDeps.include` entries, so Vite keeps the dependency optimizer running there, and it wrote to the default Vite cache. That replaced the optimized dependencies of a dev server running in the same project, so framework islands in that dev server broke (for example React's production `jsx-dev-runtime`, where `jsxDEV` is undefined) until it was restarted with `--force`. The temporary server now writes to `<cacheDir>/vite-sync/`. It optimizes the same dependencies as before; only the output location changes. Fixes #18449 Tested: `astro-sync.test.ts` passes 10/10; the new test fails without the change in `sync/index.ts`. * fix(dev): treat missing ps row as stale in lockfile process check (#18376) Co-authored-by: Princesseuh <3019731+Princesseuh@users.noreply.github.com> * fix(astro): stop excluding node-fetch from server dep optimization in workerd dev (#18438) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * Update dependency @playwright/test to v1.64.1 (#18441) * Update @astrojs/node (#18440) * Close duplicate pull requests when an issue is fixed (#18472) * fix: minimal support node version (#18475) * [ci] release (#18459) * Fix release workflow package list after the Changesets v3 upgrade (#18104) Co-authored-by: Chris Swithinbank <swithinbank@gmail.com> Co-authored-by: Armand Philippot <git@armand.philippot.eu> * Fix DataCloneError when importing SVGs with parallelPrerender enabled (#18476) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> Co-authored-by: Princesseuh <3019731+Princesseuh@users.noreply.github.com> * fix(telemetry): look up the project ID without blocking (#18481) * Skip CSP hashes for external stylesheets and scripts. (#18488) * [ci] format * fix(astro): allow Node.js >=22.22.0 on StackBlitz WebContainers (#18494) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * fix(assets): dedupe equivalent densities in image srcset (#18500) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * docs: update legacy flags JSDocs to generate their reference in docs (#18378) Co-authored-by: ematipico <602478+ematipico@users.noreply.github.com> * Restore scroll position instantly on back/forward navigation when smooth scrolling is enabled (#18506) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * fix(transitions): silence ready rejection before skipTransition in ClientRouter (#18517) * Merge commit from fork * ci: pass issue author login to needs-repro step via env (#18518) * Restore CSS tree-shaking for unused barrel-imported Astro components (#18493) * Mark $$createComponent pure so unused barrel-exported components drop their scoped CSS * Bump Vite to 8.3.5 (Rolldown 1.2.15) and exercise the image service at runtime in the Sharp test Rolldown 1.2.13 could fold its runtime helpers into a dynamically imported page chunk, making the SSR entry statically import (and eagerly evaluate) that page. Rolldown 1.2.14+ keeps the runtime out of entry chunks. With unused components tree-shaken, the Cloudflare worker only bundles the Sharp chain when an on-demand route uses the image service, so the Sharp test now makes api.ts call getImage(). --------- Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> Co-authored-by: Matthew Phillips <matthew@matthewphillips.info> * Update @astrojs/markdoc (#18513) * fix(@astrojs/vercel): make redirects match when trailingSlash is always/never (#18085) * fix(@astrojs/vercel): make redirects match when trailingSlash is always/never * refactor(@astrojs/vercel): use path slash utilities in adjustSourceForTrailingSlash * fix(@astrojs/vercel): make spread redirects match under trailingSlash always * fix(@astrojs/vercel): match Vercel's dot rule for trailing-slash redirects Vercel's normalizer only appends a slash when the last segment has no dot, so a dotted source must stay unslashed and a dynamic or spread last segment has to match both forms. Verified against @vercel/routing-utils output. * fix(@astrojs/vercel): avoid super-linear backtracking in dot check eslint's regexp/no-super-linear-backtracking rejects the two overlapping [^/]* quantifiers; anchoring on the last dot is equivalent and linear. * fix(csp): include hashes inserted by body components in the CSP meta tag for non-streaming renders (#18512) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * fix(server-islands): keep fallback instead of throwing when the island fetch fails (#18497) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * fix(assets): avoid duplicate 1x candidate in Picture source srcset when densities includes 1 (#18504) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * [ci] format * fix(cloudflare): scope process.env define to server environments so client bundles get Vite's default replacement (#18526) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * Fix type errors in shipped components under the `strictest` TypeScript preset (#18524) * Fix strictest tsc errors in shipped Image, Picture, Code, Debug and ClientRouter components * test(astro): type-check shipped components under strictest tsconfig Add an astro check fixture whose tsconfig extends astro/tsconfigs/strictest and includes node_modules/astro/components/*.astro, so the strictest errors from #18471 cannot come back without CI failing. --------- Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * fix(cli): drop shell: true from astro info package manager calls to avoid DEP0190 warning (#18525) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * Pass the React id prefix to `renderToString` when streaming is disabled (#18482) * fix(react): pass identifierPrefix to renderToString when streaming is disabled * test(react): give the disable-streaming fixture its own outDir * Merge commit from fork * Merge commit from fork * Fix transition:name styles silently dropped in dev when component is nested under a non-propagating component (#18511) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * Prevent memory cache from storing empty 404/500 responses that would be rerouted to error pages (#18522) Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> * [ci] release (#18478) * astro add: configure tagged official adapters (#18344) Recognize resolved official package names when tagged specifiers are used so installation and Astro config updates stay aligned. Co-authored-by: Matthew Phillips <matthewphillips@cloudflare.com> --------- Co-authored-by: Samuteg <151961384+Samuteg@users.noreply.github.com> Co-authored-by: Samuteg <Princesseuh@users.noreply.github.com> Co-authored-by: astro-factory[bot] <316791938+astro-factory[bot]@users.noreply.github.com> Co-authored-by: factory[bot] <factory[bot]@users.noreply.github.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev> Co-authored-by: Jack Hanford <jackhanford@gmail.com> Co-authored-by: Tim L. White <tim@cyface.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com> Co-authored-by: Abhirup Pal <abhiruppalmethodist@gmail.com> Co-authored-by: Denis Scarabelli <87149177+DenisCDev@users.noreply.github.com> Co-authored-by: okxint <130782884+okxint@users.noreply.github.com> Co-authored-by: Emanuele Stoppa <estoppa@cloudflare.com> Co-authored-by: Houston (Bot) <108291165+astrobot-houston@users.noreply.github.com> Co-authored-by: Chris Swithinbank <swithinbank@gmail.com> Co-authored-by: Armand Philippot <git@armand.philippot.eu> Co-authored-by: Muhammad Umer Aamir <93091750+umeraamir69@users.noreply.github.com> Co-authored-by: ematipico <602478+ematipico@users.noreply.github.com> Co-authored-by: Nikolas Sapalidis <84yk8btb9f@privaterelay.appleid.com> Co-authored-by: knj <kenji.tomita1996@gmail.com> Co-authored-by: Waleed Rostom 🐦⬛ <waleed.rostom@meetsmore.com> Co-authored-by: Edmund Hung <me@edmund.dev>
Changes
astro sync(also run byastro checkandastro build) creates a temporary Vite server withoptimizeDeps: { noDiscovery: true }. Astro itself (dev toolbar deps) and integrations such as@astrojs/reactand@astrojs/preactaddoptimizeDeps.includeentries, so Vite still runs the dependency optimizer on that server. It wrote to the project's default Vite cache,node_modules/.vite, which is the cache a runningastro devreads from. The dev server's optimized dependencies were replaced with ones built by the temporary server, for example React's productionjsx-dev-runtimewherejsxDEVisundefined, and islands broke with_jsxDEV is not a functionorInvalid hook calluntil the dev server was restarted with--force.cacheDir,<cacheDir>/vite-sync/under Astro'scacheDir. It optimizes the same dependencies as before and plugins see the same config; only where the output is written changes.Fixes #18449
Testing
test/astro-sync.test.ts. It writes a placeholdernode_modules/.vite/deps/_metadata.json(standing in for a running dev server's cache) into a fixture that no other test starts a dev server on, runs sync, and asserts the file is unchanged. Without the change insync/index.tsit fails, because sync replaces the placeholder with its own optimizer metadata. With the change,pnpm -C packages/astro exec astro-scripts test "test/astro-sync.test.ts"passes 10/10.@astrojs/react): withastro devrunning,node_modules/.vite/depsis no longer modified byastro sync,astro checkorastro build, and sync's output goes tonode_modules/.astro/vite-sync/deps.Docs
No docs change. There is no API or config change; the only visible effect is a
vite-syncdirectory inside Astro'scacheDir.