{"record":{"id":"ed73efaea951f3e0","repo":"Stirling-Tools/Stirling-PDF","slug":"indexeddb-context-not-available","errorCode":null,"errorMessage":"IndexedDB context not available","messagePattern":"IndexedDB context not available","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"frontend/editor/src/core/hooks/useFileManager.ts","lineNumber":83,"sourceCode":"          \"rtf\",\n          \"html\",\n          \"epub\",\n        ];\n        for (const ext of knownInnerExt) {\n          if (lowerName.endsWith(`.${ext}.zip`)) {\n            return fallback.slice(0, fallback.length - 4) || fallback;\n          }\n        }\n      }\n      return fallback;\n    },\n    [],\n  );\n\n  const convertToFile = useCallback(\n    async (fileStub: StirlingFileStub): Promise<File> => {\n      if (!indexedDB) {\n        throw new Error(\"IndexedDB context not available\");\n      }\n\n      // Regular file loading\n      if (fileStub.id) {\n        const file = await indexedDB.loadFile(fileStub.id);\n        if (file) {\n          return file;\n        }\n      }\n      throw new Error(\n        `File not found in storage: ${fileStub.name} (ID: ${fileStub.id})`,\n      );\n    },\n    [indexedDB],\n  );\n\n  const loadRecentFiles = useCallback(async (): Promise<StirlingFileStub[]> => {\n    setLoading(true);","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/Stirling-Tools/Stirling-PDF/blob/9ef20dcab80b85041912f045e17a6aea1d08f969/frontend/editor/src/core/hooks/useFileManager.ts#L65-L101","documentation":"Thrown by `convertToFile` in useFileManager when the `indexedDB` context value is null. The IndexedDB provider (which exposes loadFile/saveFile) is not available in the React tree above this hook — meaning file persistence is offline, so any file conversion/load is impossible.","triggerScenarios":"useFileManager (or a consumer) is rendered outside the IndexedDBProvider; the provider failed to mount; the context value is intentionally null in an environment without IndexedDB (SSR, restricted iframe with storage disabled).","commonSituations":"Component tree refactored so a consumer of useFileManager is mounted above the provider; running in a privacy mode / cookie-blocking iframe where IndexedDB is unavailable; testing without wrapping the provider.","solutions":["Ensure useFileManager consumers are always descendants of the IndexedDBProvider in the component tree.","Detect IndexedDB availability up front and show a user-facing 'storage unavailable' state instead of letting operations throw.","Provide a memory-only fallback storage implementation when IndexedDB is absent (if the product tolerates it).","Add a test wrapper that mounts the provider so this never regresses."],"exampleFix":"// before\nconst convertToFile = useCallback(async (fileStub) => {\n  if (!indexedDB) throw new Error(\"IndexedDB context not available\");\n  ...\n}, [indexedDB]);\n\n// after — fail fast at hook init with a typed error\nif (!indexedDB) {\n  throw new Error(\"IndexedDB context not available — mount IndexedDBProvider above useFileManager consumers.\");\n}","handlingStrategy":"validation","validationCode":"// Ensure the provider is present before using the hook\nif (!indexedDB) {\n  // render a 'storage unavailable' state instead of calling convertToFile\n}","typeGuard":"function hasIndexedDB(ctx: unknown): ctx is { loadFile: (id: string) => Promise<File | null>; saveFile: (f: File, id: string) => Promise<unknown> } {\n  return !!ctx && typeof (ctx as { loadFile?: unknown }).loadFile === \"function\";\n}","tryCatchPattern":null,"preventionTips":["Always mount IndexedDBProvider above any useFileManager consumer.","Detect storage availability at app init and show a 'storage unavailable' state.","Wrap test renders with the provider so this never regresses."],"tags":["indexeddb","react-context","provider","storage"],"backgroundTag":null,"analyzedSha":"9ef20dcab80b85041912f045e17a6aea1d08f969","analyzedAt":"2026-08-13T22:11:39.827Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}