{"record":{"id":"9bda7f8f6e66aa20","repo":"solidjs/solid","slug":"getcontextid-cannot-be-used-under-non-hydrating-co","errorCode":null,"errorMessage":"getContextId cannot be used under non-hydrating context","messagePattern":"getContextId cannot be used under non-hydrating context","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/solid/src/server/rendering.ts","lineNumber":114,"sourceCode":"      if (typeof prev !== \"object\" && typeof node[i] !== \"object\") mapped += `<!--!$-->`;\n      mapped += resolveSSRNode((prev = node[i]));\n    }\n    return mapped;\n  }\n  if (t === \"object\") return node.t;\n  if (t === \"function\") return resolveSSRNode(node());\n  return String(node);\n}\n\ntype SharedConfig = {\n  context?: HydrationContext;\n  getContextId(): string;\n  getNextContextId(): string;\n};\nexport const sharedConfig: SharedConfig = {\n  context: undefined,\n  getContextId() {\n    if (!this.context) throw new Error(`getContextId cannot be used under non-hydrating context`);\n    return getContextId(this.context.count);\n  },\n  getNextContextId() {\n    if (!this.context)\n      throw new Error(`getNextContextId cannot be used under non-hydrating context`);\n    return getContextId(this.context.count++);\n  }\n};\n\nfunction getContextId(count: number) {\n  const num = String(count),\n    len = num.length - 1;\n  return sharedConfig.context!.id + (len ? String.fromCharCode(96 + len) : \"\") + num;\n}\n\nfunction setHydrateContext(context?: HydrationContext): void {\n  sharedConfig.context = context;\n}","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/solidjs/solid/blob/f47845f9cc16ecbb316aa6560c7161f45af9a3d8/packages/solid/src/server/rendering.ts#L96-L132","documentation":"On the server, sharedConfig.getContextId() returns a hydration context id derived from sharedConfig.context.count. That context only exists while Solid is inside a hydrating/render pass (createComponent/hydration). Calling getContextId outside such a pass throws because there is no context to derive an id from.","triggerScenarios":"Calling sharedConfig.getContextId() (directly or via APIs that use it, like certain hydration-aware components) at module scope or outside renderToString/renderToStream's component tree on the server.","commonSituations":"Calling hydration utilities in plain Node code; running server code outside the render lifecycle; library code assuming a hydration context that a non-hydrating entry point never sets up.","solutions":["Only call getContextId/getNextContextId inside the component tree during SSR or hydration","Check sharedConfig.context exists before calling: if (sharedConfig.context) ...","If you need ids outside rendering, generate them with your own counter or crypto.randomUUID"],"exampleFix":"// before\nconst id = sharedConfig.getContextId(); // outside render -> throws\n\n// after\nconst id =\n  sharedConfig.context\n    ? sharedConfig.getContextId()\n    : crypto.randomUUID();","handlingStrategy":"validation","validationCode":"import { sharedConfig } from 'solid-js/web';\nconst id = sharedConfig.context ? sharedConfig.getContextId() : crypto.randomUUID();","typeGuard":"const hasHydrationContext = (sc: typeof sharedConfig): boolean => !!sc.context;","tryCatchPattern":"try { return sharedConfig.getContextId(); } catch (e) { if (/non-hydrating context/.test(String(e))) return crypto.randomUUID(); throw e; }","preventionTips":["Call context-id APIs only inside the SSR render tree","Check sharedConfig.context before direct calls","Keep module-scope code free of hydration utilities"],"tags":["solid","ssr","hydration","context","server"],"backgroundTag":"missing-hydration-context","analyzedSha":"f47845f9cc16ecbb316aa6560c7161f45af9a3d8","analyzedAt":"2026-08-27T05:39:24.283Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}