Skip to content

Fix astro preview ignoring vite.preview.allowedHosts from astro.config.mjs#16104

Merged
matthewp merged 2 commits intomainfrom
fix/preview-allowed-hosts
Mar 30, 2026
Merged

Fix astro preview ignoring vite.preview.allowedHosts from astro.config.mjs#16104
matthewp merged 2 commits intomainfrom
fix/preview-allowed-hosts

Conversation

@matthewp
Copy link
Copy Markdown
Contributor

@matthewp matthewp commented Mar 26, 2026

Changes

  • astro preview now respects vite.preview.allowedHosts
  • Nerging the user's vite config as the base before applying Astro's own overrides with our configuration winning.

Testing

  • Added test/astro-preview-allowed-hosts.test.js with five cases: allowing a listed host via vite.preview.allowedHosts, blocking an unlisted host, allowing all hosts when allowedHosts: true, and verifying that server.allowedHosts takes precedence over vite.preview.allowedHosts when both are set.

Docs

N/A bug fix

Closes #16088

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-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 26, 2026

🦋 Changeset detected

Latest 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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Mar 26, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 26, 2026

Merging this PR will not alter performance

✅ 18 untouched benchmarks


Comparing fix/preview-allowed-hosts (8b8dc99) with main (88fcc98)

Open in CodSpeed

@matthewp matthewp marked this pull request as ready for review March 26, 2026 21:06
@matthewp matthewp merged commit 47a394d into main Mar 30, 2026
44 of 45 checks passed
@matthewp matthewp deleted the fix/preview-allowed-hosts branch March 30, 2026 15:15
@astrobot-houston astrobot-houston mentioned this pull request Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

astro preview ignores vite.preview.allowedHosts configuration

2 participants