Skip to content

fix: make cookie options optional - #17201

Merged
Rich-Harris merged 7 commits into
version-3from
optional-cookie-options
Sep 24, 2026
Merged

Rich-Harris merged 7 commits into
version-3from
optional-cookie-options

Conversation

@teemingc

@teemingc teemingc commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Since cookie paths now default to '/', we can make the third argument optional. This PR changes the types and updates docs/tests


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@pkg-svelte-dev

pkg-svelte-dev Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from 8f66621:

pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/8f666211f89b9d01d32ac5b3473af1dbecd88594

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/kit/pr/17201

@changeset-bot

changeset-bot Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8f66621

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

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

Comment thread packages/kit/test/apps/options-2/src/hooks.server.js
vercel Bot and others added 5 commits September 24, 2026 15:58
… options-2's `hooks.server.js`, so `count.remote.js` can no longer isolate its in-memory count per browser session, reintroducing parallel-test state clobbering.

This commit fixes the issue reported at packages/kit/test/apps/options-2/src/hooks.server.js:3

## Bug

The commit **"path: '/' is the default"** (whose stated intent was to make cookie `options` optional, since `path` defaults to `'/'`) removed the *entire* session-cookie-setting block from `packages/kit/test/apps/options-2/src/hooks.server.js`, rather than just the now-unnecessary `{ path: '/' }` argument.

Git diff confirms:

```diff
 export async function handle({ event, resolve }) {
-	// isolates the in-memory count in count.remote.js per browser session
-	if (!event.cookies.get('session')) {
-		event.cookies.set('session', crypto.randomUUID(), { path: '/' });
-	}
 
 	return resolve(event, {
```

## Why it matters

`src/routes/remote/count.remote.js` keys its in-memory `counts` Map by the `session` cookie:

```js
const session_id = () => getRequestEvent().cookies.get('session') ?? 'default';
```

with the comment: *"count is keyed by the `session` cookie from hooks.server.js so the parallel tests that read and set it can't see each other's mutations."*

**Trigger:** With the block removed, no request ever sets a `session` cookie, so `session_id()` always returns `'default'`. All parallel Playwright workers/browsers then share the single `'default'` entry in `counts`, so concurrent `get_count` / `set_count` / `set_count_form` calls clobber each other — exactly the cross-test flakiness the code was designed to prevent.

The sibling `async` app's `hooks.server.js` in the same PR correctly kept its equivalent session-isolation block and only dropped `path`, confirming this deletion was accidental.

## Fix

Restore the block, dropping only the `{ path: '/' }` argument (matching the PR's intent):

```js
// isolates the in-memory count in count.remote.js per browser session
if (!event.cookies.get('session')) {
	event.cookies.set('session', crypto.randomUUID());
}
```

Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Co-authored-by: teemingc <chewteeming01@gmail.com>
@svelte-docs-bot

Copy link
Copy Markdown

@Rich-Harris
Rich-Harris merged commit 5e11958 into version-3 Sep 24, 2026
41 checks passed
@Rich-Harris
Rich-Harris deleted the optional-cookie-options branch September 24, 2026 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants