{"record":{"id":"02c7a964d4159a3f","repo":"marmelab/react-admin","slug":"the-record-cannot-be-updated-because-no-record-has","errorCode":null,"errorMessage":"The record cannot be updated because no record has been passed","messagePattern":"The record cannot be updated because no record has been passed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/ra-core/src/controller/button/useUpdateController.tsx","lineNumber":125,"sourceCode":"                        type: 'error',\n                        messageArgs: {\n                            _:\n                                typeof error === 'string'\n                                    ? error\n                                    : (error as Error)?.message,\n                        },\n                    }\n                );\n            },\n            mutationMode,\n            ...otherMutationOptions,\n        }\n    );\n\n    const handleUpdate = useCallback(\n        (data: Partial<RecordType>) => {\n            if (!record) {\n                throw new Error(\n                    'The record cannot be updated because no record has been passed'\n                );\n            }\n            updateOne(resource, {\n                id: record.id,\n                data,\n                previousData: record,\n                meta: mutationMeta,\n            });\n        },\n        [updateOne, mutationMeta, record, resource]\n    );\n\n    return useMemo(\n        () => ({\n            isPending,\n            isLoading: isPending,\n            handleUpdate,","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-core/src/controller/button/useUpdateController.tsx#L107-L143","documentation":"useUpdateController's handleUpdate callback requires the current record to know the record id to update. When record is undefined, the update has no target id, so it throws synchronously. As with useDeleteController, this indicates the component was rendered without record context or before data arrived.","triggerScenarios":"Clicking a <SaveButton>/<UpdateButton> in a form rendered outside RecordContext so props.record is undefined; calling useUpdateController directly without a record; the update button becoming clickable while record is still undefined.","commonSituations":"Custom forms placed outside Edit's record context; page-level buttons without record prop; optimistic UI rendering before the record query resolves.","solutions":["Pass record explicitly or render inside RecordContext: <UpdateButton record={record} />","Guard rendering until the record is loaded (isLoading from useGetOne or Edit's isPending)","When using useUpdateController directly, supply a record prop"],"exampleFix":"// before\nconst MyForm = () => {\n    const { handleUpdate } = useUpdateController();\n    return <SaveButton onClick={() => handleUpdate(values)} />;\n};\n// after\nconst MyForm = props => {\n    const record = useRecordContext();\n    const { handleUpdate } = useUpdateController({ ...props, record });\n    if (!record) return null;\n    return <SaveButton onClick={() => handleUpdate(values)} />;\n};","handlingStrategy":"validation","validationCode":"const record = useRecordContext();\nconst canUpdate = Boolean(record && record.id != null);\n{canUpdate && <SaveButton />  /* handleUpdate only reachable when record exists */}","typeGuard":"const hasRecord = (r: unknown): r is { id: unknown } =>\n    r != null && typeof r === 'object' && 'id' in r;","tryCatchPattern":"try {\n    handleUpdate(values);\n} catch (e) {\n    if (e instanceof Error && e.message.includes('no record has been passed')) {\n        notify('Cannot save: record not loaded yet', { type: 'warning' });\n        return;\n    }\n    throw e;\n}","preventionTips":["Render update UI only inside a record context (Edit page or RecordContext)","Gate the save button on record presence/isLoading","Supply a record prop when using useUpdateController in custom components","Wrap custom forms in tests with RecordContext and a fixture record"],"tags":["react","record","update-button"],"backgroundTag":"missing-record-context","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}