Skip to content

Commit cb6d1ca

Browse files
committed
duplicate cookies in .html case
1 parent b0ac9ef commit cb6d1ca

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

packages/kit/src/runtime/server/cookie.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { parse, serialize } from 'cookie';
2-
import { normalize_path, resolve } from '../../utils/url.js';
2+
import { add_data_suffix, normalize_path, resolve } from '../../utils/url.js';
33

44
/**
55
* Tracks all cookies set during dev mode so we can emit warnings
@@ -245,6 +245,14 @@ export function add_cookies_to_headers(headers, cookies) {
245245
for (const new_cookie of cookies) {
246246
const { name, value, options } = new_cookie;
247247
headers.append('set-cookie', serialize(name, value, options));
248+
249+
// special case — for routes ending with .html, the route data lives in a sibling
250+
// `.html__data.json` file rather than a child `/__data.json` file, which means
251+
// we need to duplicate the cookie
252+
if (options.path.endsWith('.html')) {
253+
const path = add_data_suffix(options.path);
254+
headers.append('set-cookie', serialize(name, value, { ...options, path }));
255+
}
248256
}
249257
}
250258

0 commit comments

Comments
 (0)