{"record":{"id":"8643b8c096d44db9","repo":"marmelab/react-admin","slug":"the-dataprovider-is-not-initialized","errorCode":null,"errorMessage":"The dataProvider is not initialized.","messagePattern":"The dataProvider is not initialized\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/ra-data-local-forage/src/index.ts","lineNumber":95,"sourceCode":"            initializePromise = initializeProvider();\n        }\n        return initializePromise;\n    };\n\n    const initializeProvider = async () => {\n        const localForageData = await getLocalForageData();\n        data = localForageData ?? defaultData;\n\n        baseDataProvider = fakeRestProvider(\n            data,\n            loggingEnabled\n        ) as DataProvider;\n    };\n\n    // Persist in localForage\n    const updateLocalForage = (resource: string) => {\n        if (!data) {\n            throw new Error('The dataProvider is not initialized.');\n        }\n        localforage.setItem(\n            `${prefixLocalForageKey}${resource}`,\n            data[resource]\n        );\n    };\n\n    return {\n        // read methods are just proxies to FakeRest\n        getList: async <RecordType extends RaRecord = any>(\n            resource: string,\n            params: GetListParams\n        ) => {\n            await initialize();\n            if (!baseDataProvider) {\n                throw new Error('The dataProvider is not initialized.');\n            }\n            return baseDataProvider","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-data-local-forage/src/index.ts#L77-L113","documentation":"In ra-data-local-forage, the internal localForage persistence helper writes the current in-memory data for a resource to IndexedDB/localStorage. It throws when the in-memory `data` cache has not been populated yet — the provider factory hasn't finished initialization. This signals a lifecycle/initialization bug in the provider itself.","triggerScenarios":"Calling a mutating method (create/update/delete) before the async initialization (loading data from localForage and the base data provider) has completed, causing updateLocalForage to run with `data === undefined`.","commonSituations":"Using the provider before the async factory promise resolves (calling the sync-looking function directly instead of awaiting localForageTestable/localForageProvider); calling mutation methods from outside react-admin's lifecycle very early at app startup.","solutions":["Always await the async localForage provider factory before passing it to <Admin dataProvider={...}>.","Do not invoke the provider's mutation methods directly before initialization; route calls through react-admin after mount.","Check for code that captured the unfinished provider object and calls it early.","Upgrade ra-data-local-forage; modern versions initialize before returning the provider."],"exampleFix":"// before\nconst dp = localForageProvider({ localStorageUpdateTransform: fn });\n<Admin dataProvider={dp}>\n// after\n<Admin dataProvider={localForageProvider({ localStorageUpdateTransform: fn })}>","handlingStrategy":"try-catch","validationCode":"// ensure the provider is fully initialized before use\nconst dataProvider = await localForageProvider({ dataProvider: baseDataProvider });\nif (typeof dataProvider.update !== 'function') throw new Error('provider not ready');","typeGuard":"function isInitializedDataProvider(dp: any): dp is DataProvider {\n    return dp != null && typeof dp.getList === 'function' && typeof dp.update === 'function';\n}","tryCatchPattern":"try {\n    await dataProvider.update(resource, params);\n} catch (e) {\n    if (e.message === 'The dataProvider is not initialized.') {\n        // re-run init or surface a loading error\n    } else throw e;\n}","preventionTips":["Always await localForageProvider before passing it to <Admin>.","Never store the pre-init provider reference for direct calls.","Check the browser console for earlier init errors.","Keep ra-data-local-forage current."],"tags":["initialization","localforage","async","lifecycle"],"backgroundTag":"dataprovider-not-initialized","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}