From 67f8e561b620508ce957bac608a8157e58dcbfc3 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 12:20:56 +0000 Subject: [PATCH 1/2] fix(plugin-form): a placed row editor is not drawn inside the slot's wrapper form The expanded row editor is an ObjectForm of its own, so its placement in a group slot draws no wrapper form: a form inside a form is a nesting React refuses. Pinned: the editor's inputs are owned by its own form and no nesting warning is logged. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01L6bhgW85kwjGaz7HqsmEuv --- ...erDetailForm.groupPlacement-35889.test.tsx | 37 +++++++++++++++++++ .../plugin-form/src/MasterDetailForm.tsx | 18 ++++++--- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/ui/packages/plugin-form/src/MasterDetailForm.groupPlacement-35889.test.tsx b/ui/packages/plugin-form/src/MasterDetailForm.groupPlacement-35889.test.tsx index d3187bf3cbb..68afd3d7d89 100644 --- a/ui/packages/plugin-form/src/MasterDetailForm.groupPlacement-35889.test.tsx +++ b/ui/packages/plugin-form/src/MasterDetailForm.groupPlacement-35889.test.tsx @@ -150,6 +150,43 @@ describe('MasterDetailForm — a group-placed collection sits at its group (obje expect(submitted).not.toHaveBeenCalled(); }); + it('an expanded row editor opens in the slot beside its collection, a form of its own, with no nesting warning', async () => { + const errors = vi.spyOn(console, 'error').mockImplementation(() => {}); + const parent = parentWith([HEADER_GROUP, LINES_GROUP, TOTALS_GROUP]); + const child = { name: 'po_line', fields: { qty: { type: 'number', label: 'Qty' }, note: { type: 'text', label: 'Note' }, po: { type: 'master_detail', label: 'PO', reference: 'po' } } }; + const ds = makeDataSource(parent, { + getObjectSchema: vi.fn(async (object: string) => (object === 'po_line' ? child : parent)), + findOne: vi.fn().mockResolvedValue({ id: 'po1', ref: 'PO-7', memo: 'm' }), + find: vi.fn().mockImplementation((object: string) => + Promise.resolve({ data: object === 'po_line' ? [{ id: 'l1', po: 'po1', qty: 3, note: 'n' }] : [] }), + ), + }); + const withEditor = [{ ...details[0], formFields: ['qty', 'note'] }]; + const { container } = render( + , + ); + const expand = await waitFor(() => { + const el = container.querySelector('[data-form-slot] [data-testid="line-items-expand-0"]') as HTMLElement | null; + if (!el) throw new Error('no expand in the placed collection'); + return el; + }); + fireEvent.click(expand); + const editor = await waitFor(() => { + const el = container.querySelector('[data-testid="md-row-form"]') as HTMLElement | null; + if (!el || !el.querySelector('input')) throw new Error('editor not open'); + return el; + }); + const header = container.querySelector('[data-form-section="__section_header"]')!.closest('form')!; + expect(editor.closest('[data-form-slot]')).toBe(container.querySelector('[data-form-slot]')); + for (const input of editor.querySelectorAll('input')) { + expect((input as HTMLInputElement).form).not.toBe(header); + expect(editor.contains((input as HTMLInputElement).form)).toBe(true); + } + const nesting = errors.mock.calls.filter((call) => /cannot be a descendant of|cannot contain a nested|validateDOMNesting/i.test(call.map(String).join(' '))); + expect(nesting).toEqual([]); + errors.mockRestore(); + }); + it('saves the record and its lines in one batch from the placed table', async () => { const batchTransaction = vi.fn().mockResolvedValue({ results: [{ id: 'po1' }] }); const ds = makeDataSource(parentWith([HEADER_GROUP, LINES_GROUP, TOTALS_GROUP]), { batchTransaction }); diff --git a/ui/packages/plugin-form/src/MasterDetailForm.tsx b/ui/packages/plugin-form/src/MasterDetailForm.tsx index b892cd7097f..144a7cae67f 100644 --- a/ui/packages/plugin-form/src/MasterDetailForm.tsx +++ b/ui/packages/plugin-form/src/MasterDetailForm.tsx @@ -913,18 +913,24 @@ interface MasterDetailLinesProps { * never blocks Save with a browser bubble), a line button without a `type` * submits only the wrapper, which does nothing, and Enter in a cell finds the * wrapper's disabled default button and submits nothing. + * + * `ownsForm` says `children` already are a form of their own (an expanded row + * editor is an `ObjectForm`, its only other control a `type="button"`), so no + * wrapper is drawn: a form inside a form is a nesting React refuses. */ const preventSubmit = (event: React.FormEvent) => event.preventDefault(); -const FormSlotPlacement: React.FC<{ store: FormSlotStore; id: string; children: React.ReactNode }> = ({ - store, - id, - children, -}) => { +const FormSlotPlacement: React.FC<{ + store: FormSlotStore; + id: string; + ownsForm?: boolean; + children: React.ReactNode; +}> = ({ store, id, ownsForm = false, children }) => { useSyncExternalStore(store.subscribe, store.getVersion, store.getVersion); const at = store.placement(id); if (at === 'inline') return <>{children}; if (!at) return null; + if (ownsForm) return createPortal(children, at); return createPortal(