marmelab/react-admin · error
The record cannot be updated because no record has been pass
Error message
The record cannot be updated because no record has been passed
What it means
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.
Source
Thrown at packages/ra-core/src/controller/button/useUpdateController.tsx:125
type: 'error',
messageArgs: {
_:
typeof error === 'string'
? error
: (error as Error)?.message,
},
}
);
},
mutationMode,
...otherMutationOptions,
}
);
const handleUpdate = useCallback(
(data: Partial<RecordType>) => {
if (!record) {
throw new Error(
'The record cannot be updated because no record has been passed'
);
}
updateOne(resource, {
id: record.id,
data,
previousData: record,
meta: mutationMeta,
});
},
[updateOne, mutationMeta, record, resource]
);
return useMemo(
() => ({
isPending,
isLoading: isPending,
handleUpdate,View on GitHub (pinned to 051f511bb0)
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
Example fix
// before
const MyForm = () => {
const { handleUpdate } = useUpdateController();
return <SaveButton onClick={() => handleUpdate(values)} />;
};
// after
const MyForm = props => {
const record = useRecordContext();
const { handleUpdate } = useUpdateController({ ...props, record });
if (!record) return null;
return <SaveButton onClick={() => handleUpdate(values)} />;
}; Defensive patterns
Strategy: validation
Validate before calling
const record = useRecordContext();
const canUpdate = Boolean(record && record.id != null);
{canUpdate && <SaveButton /> /* handleUpdate only reachable when record exists */} Type guard
const hasRecord = (r: unknown): r is { id: unknown } =>
r != null && typeof r === 'object' && 'id' in r; Try / catch
try {
handleUpdate(values);
} catch (e) {
if (e instanceof Error && e.message.includes('no record has been passed')) {
notify('Cannot save: record not loaded yet', { type: 'warning' });
return;
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Custom forms placed outside Edit's record context; page-level buttons without record prop; optimistic UI rendering before the record query resolves.
Related errors
- The record cannot be deleted because no record has been pass
- useTranslatableContext must be used inside a TranslatableCon
- useCloseNotification must be used within a CloseNotification
- usePreference cannot be used outside of a Configurable compo
- usePreferencesEditor must be used within a PreferencesEditor
AI-assisted analysis of marmelab/react-admin@051f511bb0 (2026-08-30).
Data as JSON: /api/errors/02c7a964d4159a3f.
Report an issue: GitHub.