{"record":{"id":"009ecf0facf39514","repo":"sveltejs/kit","slug":"cookie-name-is-too-large-and-will-be-discard","errorCode":null,"errorMessage":"Cookie \"${name}\" is too large, and will be discarded by the browser","messagePattern":"Cookie \"(.+?)\" is too large, and will be discarded by the browser","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/kit/src/runtime/server/cookie.js","lineNumber":253,"sourceCode":"\t\tlet path = options.path ?? '/';\n\n\t\tif (!options.domain || options.domain === url.hostname) {\n\t\t\tpath = resolve(normalized_url, path);\n\t\t}\n\n\t\t// Generate unique key for cookie storage\n\t\tconst cookie_key = generate_cookie_key(options.domain, path, name);\n\t\tconst cookie = { name, value, options: { ...options, path } };\n\t\tnew_cookies.set(cookie_key, cookie);\n\n\t\tif (DEV) {\n\t\t\tconst size =\n\t\t\t\t// only the name/value pair counts towards MAX_COOKIE_SIZE, not the other attributes\n\t\t\t\ttext_encoder.encode(name).byteLength +\n\t\t\t\ttext_encoder.encode((options.encode ?? encodeURIComponent)(value)).byteLength;\n\n\t\t\tif (size > MAX_COOKIE_SIZE) {\n\t\t\t\tthrow new Error(`Cookie \"${name}\" is too large, and will be discarded by the browser`);\n\t\t\t}\n\n\t\t\tcookie_paths[name] ??= new Set();\n\n\t\t\tif (!value) {\n\t\t\t\tcookie_paths[name].delete(path);\n\t\t\t} else {\n\t\t\t\tcookie_paths[name].add(path);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * @param {import('types').TrailingSlash} trailing_slash\n\t */\n\tfunction set_trailing_slash(trailing_slash) {\n\t\tnormalized_url = normalize_path(url.pathname, trailing_slash);\n\t\tinternal_queue.forEach((fn) => fn());","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/server/cookie.js#L235-L271","documentation":"Dev-only size check in the internal cookie setter: the encoded name+value pair exceeds SvelteKit's MAX_COOKIE_SIZE (4096 bytes, the browser cookie limit). In development SvelteKit throws so the problem is caught early; in production browsers would silently drop the cookie, losing session data.","triggerScenarios":"Thrown at packages/kit/src/runtime/server/cookie.js:253 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Store large data server-side (e.g. in a database or session store) and keep only a session id in the cookie","Shorten the cookie value or use a less verbose encoding"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}