{"record":{"id":"f88428368614250a","repo":"solidjs/solid","slug":"getnextcontextid-cannot-be-used-under-non-hydratin","errorCode":null,"errorMessage":"getNextContextId cannot be used under non-hydrating context","messagePattern":"getNextContextId cannot be used under non-hydrating context","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/solid/src/server/rendering.ts","lineNumber":119,"sourceCode":"  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}\n\nfunction nextHydrateContext(): HydrationContext | undefined {\n  return sharedConfig.context\n    ? {\n        ...sharedConfig.context,","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/solidjs/solid/blob/f47845f9cc16ecbb316aa6560c7161f45af9a3d8/packages/solid/src/server/rendering.ts#L101-L137","documentation":"sharedConfig.getNextContextId() increments and returns the hydration context counter, which only exists during server rendering/hydration. Calling it with no sharedConfig.context (outside a render pass) throws. createUniqueId and hydration-aware code paths call this internally, so the error frequently surfaces indirectly.","triggerScenarios":"Calling createUniqueId() or sharedConfig.getNextContextId() on the server outside the render tree; module-level initialization code that creates components/ids before render starts; utilities extracted out of the render lifecycle.","commonSituations":"Top-level const id = createUniqueId() in a server-rendered module; refactoring component code into module scope; library initialization running before renderToString/renderToStream establishes a context.","solutions":["Move createUniqueId()/getNextContextId() calls inside component bodies so they run during render","Guard with sharedConfig.context before calling the API directly","Use your own id source for values needed before rendering begins"],"exampleFix":"// before (module scope, SSR)\nconst uid = createUniqueId(); // getNextContextId throws: no context\n\n// after\nlet uid: string;\nconst MyComponent = () => {\n  uid = createUniqueId(); // runs inside render\n  return <div id={uid} />;\n};","handlingStrategy":"validation","validationCode":"import { sharedConfig } from 'solid-js/web';\nlet uid: string;\nif (sharedConfig.context) uid = createUniqueId();\nelse uid = crypto.randomUUID();","typeGuard":"const hasHydrationContext = (sc: typeof sharedConfig): boolean => !!sc.context;","tryCatchPattern":"try { return sharedConfig.getNextContextId(); } catch (e) { if (/non-hydrating context/.test(String(e))) return fallbackId(); throw e; }","preventionTips":["Call createUniqueId inside component bodies, never at module scope","Guard direct sharedConfig calls with a context check","Own the id strategy for values needed before render"],"tags":["solid","ssr","hydration","createuniqueid","server"],"backgroundTag":"missing-hydration-context","analyzedSha":"f47845f9cc16ecbb316aa6560c7161f45af9a3d8","analyzedAt":"2026-08-27T05:39:24.283Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}