Repository navigation
fix: respect user Vite CORS config - #16924
Merged
elliott-with-the-longest-name-on-github merged 5 commits intoAug 25, 2026
Merged
elliott-with-the-longest-name-on-github merged 5 commits into
elliott-with-the-longest-name-on-github merged 5 commits into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/136c14a9fc0b3f1ce3c73bf666f49fdcbe0035e1Open in |
🦋 Changeset detectedLatest commit: 136c14a 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 |
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
…ndlers during `vite build`, even though `server.cors`/`preview.cors` are irrelevant to building.
This commit fixes the issue reported at packages/kit/src/exports/vite/index.js:51
## Bug
In `packages/kit/src/exports/vite/index.js`, the plugin's `config` hook always builds and returns `new_config` regardless of `config_env.command`. It sets `is_build = config_env.command === 'build'` (line 335) but never uses it to gate CORS resolution:
```js
server: {
cors: resolve_cors(config.server?.cors, 'server.cors'),
...
},
preview: {
cors: resolve_cors(config.preview?.cors, 'preview.cors')
},
```
`resolve_cors` emits a `console.warn` whenever preflight is disabled:
```js
if (preflight_disabled) {
console.warn(styleText(['yellow', 'bold'],
`OPTIONS request handlers will not work unless ...`));
return undefined;
}
```
### Trigger
A user who sets `server.cors: false` (or `true`, or an object with `preflightContinue: false`) in `vite.config.js` and runs **`vite build`** sees this yellow warning. During `build`, neither `server.cors` (dev) nor `preview.cors` (preview) has any effect, so the warning is pure noise unrelated to building.
## Fix
Added a `warn` parameter to `resolve_cors` and gated the `console.warn` on it. The two call sites pass `!is_build`, so the warning only fires for `serve`/`preview` commands where the CORS setting is actually used. The returned config value is unchanged, so build behavior is unaffected.
*(Rebased against the formatting-only commit `d2bde94`; `resolve_cors` is now defined at line 51 and the `preflight_disabled` check was collapsed onto a single line, but the warning remains ungated.)*
Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Co-authored-by: teemingc <chewteeming01@gmail.com>
Co-authored-by: Nic Polumeyv <nicolas.polum@outlook.com>
elliott-with-the-longest-name-on-github
merged commit Aug 25, 2026
84411cc
into
version-3
40 checks passed
elliott-with-the-longest-name-on-github
deleted the
teemingc-fix-log-overridden-cors
branch
August 25, 2026 21:14
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.
closes #12574
SvelteKit currently silently overrides user-provided
server.corsandpreview.corsvalues to ensure OPTIONS handlers work during development and preview. This change preserves explicit user configuration instead, while continuing to addpreflightContinue: truewhen it has not been configured. A warning explains that OPTIONS handlers requirepreflightContinue: truewhen the user's CORS setting disables it.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkTargeted verification:
pnpm -F @sveltejs/kit test:unit(748 passed, 110 skipped).Changesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Edits