在 React 19 中的 `TabbedForm` 中出现了 `Maximum update depth exceeded` (`useFormGroup` 会在每次验证时安排一次提交阶段的更新)
作者: yarkovaleksei创建于 2026年9月9日更新于 2026年9月9日
useFormGroup (packages/ra-core/src/form/groups/useFormGroup.ts) derives its return value in a useState + useEffect:
const [state, setState] = useState<FormGroupState>({ ... });
const updateGroupState = useEvent(() => {
// ... compute newState from useFormState()'s dirtyFields/touchedFields/validatingFields/errors
setState(oldState => isEqual(oldState, newState) ? oldState : newState);
});
useEffect(() => {
updateGroupState();
}, [JSON.stringify(dirtyFieldsNames), JSON.stringify(errorsNames), JSON.stringify(touchedFieldsNames), JSON.stringify(validatingFieldsNames), updateGroupState, name, formGroups]);
Because this `setState` fires from a `useEffect` that reacts to `useFormState()`'s snapshot, it lands in a **separate commit** from the one that already re-rendered `FormTabHeader` for the new form state — an extra "commit-phase update" per tick.内容来源: marmelab/react-admin