{"record":{"id":"3afd8c7eaadb25de","repo":"sveltejs/kit","slug":"a-load-function-location-description-returned","errorCode":null,"errorMessage":"a load function ${location_description} returned ${typeof data !== 'object' ? `a ${typeof data}` : data instanceof Response ? 'a Response object' : Array.isArray(data) ? 'an array' : 'a non-plain object'}","messagePattern":"a load function (.+?) returned (.+?)` : data instanceof Response \\? 'a Response object' : Array\\.isArray\\(data\\) \\? 'an array' : 'a non-plain object'\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/kit/src/runtime/shared.js","lineNumber":28,"sourceCode":"\tconst match = /^(moz-icon|view-source|jar):/.exec(dep);\n\tif (match) {\n\t\tconsole.warn(\n\t\t\t`${route_id}: Calling \\`depends('${dep}')\\` will throw an error in Firefox because \\`${match[1]}\\` is a special URI scheme`\n\t\t);\n\t}\n}\n\nexport const INVALIDATED_PARAM = 'x-sveltekit-invalidated';\n\nexport const TRAILING_SLASH_PARAM = 'x-sveltekit-trailing-slash';\n\n/**\n * @param {any} data\n * @param {string} [location_description]\n */\nexport function validate_load_response(data, location_description) {\n\tif (data != null && Object.getPrototypeOf(data) !== Object.prototype) {\n\t\tthrow new Error(\n\t\t\t`a load function ${location_description} returned ${\n\t\t\t\ttypeof data !== 'object'\n\t\t\t\t\t? `a ${typeof data}`\n\t\t\t\t\t: data instanceof Response\n\t\t\t\t\t\t? 'a Response object'\n\t\t\t\t\t\t: Array.isArray(data)\n\t\t\t\t\t\t\t? 'an array'\n\t\t\t\t\t\t\t: 'a non-plain object'\n\t\t\t}, but must return a plain object at the top level (i.e. \\`return {...}\\`)`\n\t\t);\n\t}\n}\n\nconst object_proto_names = /* @__PURE__ */ Object.getOwnPropertyNames(Object.prototype)\n\t.sort()\n\t.join('\\0');\n\n/**","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/shared.js#L10-L46","documentation":"Load functions (+page.js/.server.js, +layout.js/.server.js) must return a plain object (or undefined). validate_load_response rejects primitives, arrays, Response objects, and class instances because the serialized load data contract expects plain JSON-able objects.","triggerScenarios":"return fetch(url) (a Response) instead of return { ...(await res.json()) } or fetch with load's built-in fetch; returning an array directly; returning new Date() or a class instance; returning a string/number.","commonSituations":"Migrating from SvelteKit versions where returning a Response from load was allowed; accidental `return data.map(...)` at the wrong level; wrapping data in a Map/Set.","solutions":["Return a plain object: { items: [...] } instead of the raw array or Response","If you need the raw Response semantics, use the response's json()/text() and spread into an object","Check class instances — serialize to plain objects (JSON.parse(JSON.stringify(x)) or explicit mapping)"],"exampleFix":"// before\nexport async function load({ fetch }) {\n  return fetch('/api/items'); // Response object\n}\n// after\nexport async function load({ fetch }) {\n  const res = await fetch('/api/items');\n  return { items: await res.json() };\n}","handlingStrategy":"type-guard","validationCode":"function isPlainObject(v) {\n  return v == null || Object.getPrototypeOf(v) === Object.prototype;\n}\n// assert isPlainObject(result) before returning from load","typeGuard":"function isPlainObject(v) {\n  return v !== null && typeof v === 'object' && Object.getPrototypeOf(v) === Object.prototype;\n}","tryCatchPattern":null,"preventionTips":["Always return an object literal from load: return { ... }","Never return fetch() Responses directly — await and spread json()","Convert class instances/Dates to plain data before returning"],"tags":["load","sveltekit","serialization"],"backgroundTag":"invalid-load-return-value","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}