Fix astro preview ignoring vite.preview.allowedHosts from astro.config.mjs#16104
Merged
Fix astro preview ignoring vite.preview.allowedHosts from astro.config.mjs#16104
Conversation
The static preview server was building its own Vite config from scratch and only reading from settings.config.server.*, completely ignoring settings.config.vite. This meant that vite.preview.allowedHosts (and other vite.preview.* options) set via the vite field in astro.config.mjs were silently dropped. Fix by merging the user's vite config as the base before applying Astro's overrides, matching how the dev server handles this via createVite(). allowedHosts is handled separately after the merge to avoid array concatenation — Astro's server.allowedHosts takes precedence when explicitly set, otherwise vite.preview.allowedHosts is preserved. Closes #16088
🦋 Changeset detectedLatest commit: 8b8dc99 The changes in this PR will be included in the next version bump. 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
Comparing |
Princesseuh
approved these changes
Mar 30, 2026
Merged
1 task
1 task
dadezzz
pushed a commit
to dadezzz/ice-notes
that referenced
this pull request
Apr 5, 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.1.1` → `6.1.3`](https://renovatebot.com/diffs/npm/astro/6.1.1/6.1.3) |  |  | --- ### Release Notes <details> <summary>withastro/astro (astro)</summary> ### [`v6.1.3`](https://github.com/withastro/astro/blob/HEAD/packages/astro/CHANGELOG.md#613) [Compare Source](https://github.com/withastro/astro/compare/astro@6.1.2...astro@6.1.3) ##### Patch Changes - [#​16161](withastro/astro#16161) [`b51f297`](withastro/astro@b51f297) Thanks [@​matthewp](https://github.com/matthewp)! - Fixes a dev rendering issue with the Cloudflare adapter where head metadata could be missing and dev CSS/scripts could be injected in the wrong place - [#​16110](withastro/astro#16110) [`de669f0`](withastro/astro@de669f0) Thanks [@​tmimmanuel](https://github.com/tmimmanuel)! - Fixes skew protection query parameters not being appended to inter-chunk JavaScript imports in client bundles, which could cause version mismatches during rolling deployments on Vercel - [#​16162](withastro/astro#16162) [`a0a49e9`](withastro/astro@a0a49e9) Thanks [@​rururux](https://github.com/rururux)! - Fixes an issue where HMR would not trigger when modifying files while using [@​astrojs/cloudflare](https://github.com/astrojs/cloudflare) with prerenderEnvironment: 'node' enabled. - [#​16142](withastro/astro#16142) [`7454854`](withastro/astro@7454854) Thanks [@​rururux](https://github.com/rururux)! - Fixes HTML content being incorrectly escaped as plain text when rendering a MDX component using the `AstroContainer` APIs. - [#​16116](withastro/astro#16116) [`12602a9`](withastro/astro@12602a9) Thanks [@​riderx](https://github.com/riderx)! - Fixes a bug where page-level CSS could leak between unrelated pages when traversing style parents across top-level route boundaries - [#​16178](withastro/astro#16178) [`a7e7567`](withastro/astro@a7e7567) Thanks [@​matthewp](https://github.com/matthewp)! - Fixes SSR builds failing with "No matching renderer found" when a project only has injected routes and no `src/pages/` directory ### [`v6.1.2`](https://github.com/withastro/astro/blob/HEAD/packages/astro/CHANGELOG.md#612) [Compare Source](https://github.com/withastro/astro/compare/astro@6.1.1...astro@6.1.2) ##### Patch Changes - [#​16104](withastro/astro#16104) [`47a394d`](withastro/astro@47a394d) Thanks [@​matthewp](https://github.com/matthewp)! - Fixes `astro preview` ignoring `vite.preview.allowedHosts` set in `astro.config.mjs` - [#​16047](withastro/astro#16047) [`711f837`](withastro/astro@711f837) Thanks [@​matthewp](https://github.com/matthewp)! - Fixes catch-all routes incorrectly intercepting requests for static assets when using the `@astrojs/node` adapter in middleware mode. - [#​15981](withastro/astro#15981) [`a60cbb6`](withastro/astro@a60cbb6) Thanks [@​moktamd](https://github.com/moktamd)! - Fix Zod v4 validation error formatting to show human-readable messages instead of raw JSON </details> --- ### Configuration 📅 **Schedule**: 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 [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My45OS4xIiwidXBkYXRlZEluVmVyIjoiNDMuOTkuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==--> Co-authored-by: Renovate Bot <renovate@zarantonello.dev> Co-committed-by: Renovate Bot <renovate@zarantonello.dev>
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
astro previewnow respectsvite.preview.allowedHostsviteconfig as the base before applying Astro's own overrides with our configuration winning.Testing
test/astro-preview-allowed-hosts.test.jswith five cases: allowing a listed host viavite.preview.allowedHosts, blocking an unlisted host, allowing all hosts whenallowedHosts: true, and verifying thatserver.allowedHoststakes precedence overvite.preview.allowedHostswhen both are set.Docs
N/A bug fix
Closes #16088