{"record":{"id":"4fbf0d251508d16c","repo":"sveltejs/kit","slug":"cannot-access-event-property-in-a-query-pass-t","errorCode":null,"errorMessage":"Cannot access event.${property} in a query. Pass the value as an argument to the query instead","messagePattern":"Cannot access event\\.(.+?) in a query\\. Pass the value as an argument to the query instead","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/kit/src/runtime/app/server/remote/shared.js","lineNumber":122,"sourceCode":"\t\t\t\t\tthrow new Error('Cannot delete cookies in `query` or `prerender` functions');\n\t\t\t\t}\n\n\t\t\t\tif (opts.path && !opts.path.startsWith('/')) {\n\t\t\t\t\tthrow new Error('Cookies deleted in remote functions must have an absolute path');\n\t\t\t\t}\n\n\t\t\t\treturn event.cookies.delete(name, opts);\n\t\t\t}\n\t\t}\n\t};\n\n\tif (state.is_in_remote_query) {\n\t\tfor (const property of ['url', 'params', 'route']) {\n\t\t\t// non-enumerable so spreading for a nested derivation doesn't invoke the getter\n\t\t\tObject.defineProperty(derived, property, {\n\t\t\t\tenumerable: false,\n\t\t\t\tget() {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Cannot access event.${property} in a query. Pass the value as an argument to the query instead`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\treturn {\n\t\tevent: derived,\n\t\tstate: {\n\t\t\t...state,\n\t\t\tis_in_remote_function: true\n\t\t}\n\t};\n}\n\n/**\n * Like `with_event` but removes things from `event` you cannot see/call in remote functions, such as `setHeaders`.","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/app/server/remote/shared.js#L104-L140","documentation":"Inside a remote `query` function, the request `event.url`, `event.params` and `event.route` properties are deliberately poisoned with throwing getters. SvelteKit requires query inputs to be explicit arguments so the query can be cached and re-run correctly on the client; reading request-bound state would make results non-deterministic. Pass the needed values as query arguments instead.","triggerScenarios":"Accessing `event.url`, `event.params`, or `event.route` (even via spread/destructuring that enumerates them is blocked, but direct access triggers it) inside a function created with `query(...)` while it executes in remote-query state.","commonSituations":"Migrating a `load` function to a remote `query` and keeping `const { params, url } = event`; building URLs from `event.url.origin` inside a query; reading route ids for conditional logic.","solutions":["Pass the needed values explicitly as arguments to the query function, e.g. `query(async (slug) => ...)` and call it with `event.params.slug` from the client/caller","Use `url`/`params` from the calling context (e.g. page state in `load` or the component) rather than the query's event","If the value is constant per request, compute it outside the query and pass it in"],"exampleFix":"// before\nexport const getPost = query(async (event) => {\n  const post = await db.getPost(event.params.slug);\n  return post;\n});\n// after\nexport const getPost = query(async (slug) => {\n  const post = await db.getPost(slug);\n  return post;\n});\n// caller: getPost(event.params.slug)","handlingStrategy":"type-guard","validationCode":"// Never destructure request-bound properties inside a query body.\n// Instead, extract needed values at the call site:\nconst { params, url } = event; // outside the query\nconst result = await myQuery(params.slug, url.searchParams.get('q'));","typeGuard":"const canReadEventProp = (event, prop) => {\n  try { void event[prop]; return true; } catch { return false; }\n};","tryCatchPattern":"try {\n  return await queryFn(event);\n} catch (e) {\n  if (e.message.includes('Pass the value as an argument')) {\n    throw new Error('Refactor: pass event.url/params/route as query arguments');\n  }\n  throw e;\n}","preventionTips":["Design query functions to take all request-derived values as arguments","Avoid `...event` spreads or deep destructuring of the event inside remote queries","Copy load-function code into queries only after stripping event.url/params/route access"],"tags":["remote-functions","query","request-state"],"backgroundTag":"request-state-in-query","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}