From 305b7674ab6768f2e37f24d38f6955a070dbabc9 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Nov 2026 13:40:30 +0000 Subject: [PATCH 1/5] fix(plugin-form): default ObjectForm edit of a missing record shows the not-found state A null findOne answer in edit mode now fails the record read with RecordNotFoundError and draws the shared RecordNotFoundState, as the modal, drawer, tabbed and wizard layouts already do, instead of seeding a blank editable form. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jS5aiikUDKUDJZeY1u --- .../29354-object-form-record-not-found.md | 10 ++ .../ObjectForm.recordNotFound-29354.test.tsx | 131 ++++++++++++++++++ ui/packages/plugin-form/src/ObjectForm.tsx | 13 ++ 3 files changed, 154 insertions(+) create mode 100644 .changeset/29354-object-form-record-not-found.md create mode 100644 ui/packages/plugin-form/src/ObjectForm.recordNotFound-29354.test.tsx diff --git a/.changeset/29354-object-form-record-not-found.md b/.changeset/29354-object-form-record-not-found.md new file mode 100644 index 00000000000..99a96416706 --- /dev/null +++ b/.changeset/29354-object-form-record-not-found.md @@ -0,0 +1,10 @@ +--- +'@object-ui/plugin-form': patch +--- + +fix(plugin-form): an edit `ObjectForm` in its default layout whose record does not exist shows the record not-found state instead of an empty editable form + +Clause-②: no +Metadata-protocol: none + +`DataSource.findOne` answers `null` for a record that does not exist (the ObjectStack adapter maps the server's 404 to it). The default `object-form` layout seeded its form from that answer, so editing a deleted or unknown record opened a blank form with an enabled Update button, and the 404 surfaced only after submit. It now draws the record not-found state ("Record not found", the same copy the record page and the modal, drawer, tabbed and wizard forms show) with no fields and no submit, both on the first read and when a background re-read finds the record deleted. Create, and an edit of a record that exists, are unchanged. diff --git a/ui/packages/plugin-form/src/ObjectForm.recordNotFound-29354.test.tsx b/ui/packages/plugin-form/src/ObjectForm.recordNotFound-29354.test.tsx new file mode 100644 index 00000000000..67d489781c4 --- /dev/null +++ b/ui/packages/plugin-form/src/ObjectForm.recordNotFound-29354.test.tsx @@ -0,0 +1,131 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * An edit `ObjectForm` in its default (`simple`) layout whose record does not + * exist shows the record not-found state, never an empty editable form + * (objectstack#29354; the four other record layouts got the same state in + * objectstack#29157 and objectstack#29247, `recordNotFound-29247.test.tsx`). + * + * `DataSource.findOne` answers `null` for a record that is not there (the + * ObjectStack adapter maps the server's 404 to it). This layout used to seed + * its form from that answer: a blank form with an enabled Update button, whose + * submit then failed against the missing record. + * + * Pinned on the flat and the sectioned render paths: a `null` edit read draws + * the not-found state (the console's shared `empty.recordNotFound` copy) with + * no field and no Update button, on the first read and on a background re-read + * that finds the record deleted. Controls: a found record and a create still + * draw the form. + */ +import React from 'react'; +import { describe, it, expect, vi, afterEach } from 'vitest'; +import { render, screen, waitFor, act, cleanup } from '@testing-library/react'; +import { notifyDataChanged } from '@object-ui/react'; +import { registerAllFields } from '@object-ui/fields'; +import type { DataSource } from '@object-ui/types'; +import { ObjectForm } from './ObjectForm'; + +registerAllFields(); + +afterEach(() => cleanup()); + +const NOT_FOUND_TITLE = 'Record not found'; +const NOT_FOUND_DESCRIPTION = + 'The record you are looking for does not exist, may have been deleted, or you may not have access to it.'; + +function makeDS(record: Record | null) { + return { + getObjectSchema: vi.fn().mockResolvedValue({ + name: 'task', + fields: { title: { type: 'text', label: 'Title' } }, + }), + findOne: vi.fn().mockResolvedValue(record), + find: vi.fn().mockResolvedValue({ data: [] }), + create: vi.fn(async (_o: string, d: Record) => ({ id: 'n1', ...d })), + update: vi.fn(async (_o: string, id: string, d: Record) => ({ id, ...d })), + }; +} + +// The default layout draws a flat field list, or its sections when it has any. +const SHAPES = [ + ['flat', {}], + ['sectioned', { sections: [{ name: 'basics', label: 'Basics', fields: ['title'] }] }], +] as const; + +function open( + shape: Record, + ds: ReturnType, + mode: 'edit' | 'create', + recordId?: string, +) { + const schema = { + type: 'object-form', + objectName: 'task', + mode, + recordId, + fields: ['title'], + ...shape, + }; + render(); +} + +const titleBox = () => + document.body.querySelector('[data-field="title"] input'); +const button = (label: string) => screen.queryByRole('button', { name: label }); + +describe.each(SHAPES)('ObjectForm (%s) — an edit read that finds no record (objectstack#29354)', (_name, shape) => { + it('draws the not-found state with no field and no Update button', async () => { + const ds = makeDS(null); + open(shape, ds, 'edit', 'NOPE_x'); + + expect(await screen.findByText(NOT_FOUND_TITLE)).toBeInTheDocument(); + expect(screen.getByText(NOT_FOUND_DESCRIPTION)).toBeInTheDocument(); + expect(screen.getByTestId('simple-form-record-not-found')).toBeInTheDocument(); + expect(ds.findOne).toHaveBeenCalledWith('task', 'NOPE_x'); + expect(titleBox()).toBeNull(); + expect(button('Update')).toBeNull(); + // Not the generic load-failure screen: nothing failed to load. + expect(screen.queryByText('Error loading form')).toBeNull(); + }); + + it('draws the not-found state when a background re-read finds the record deleted', async () => { + const ds = makeDS({ id: 't1', title: 'Write report' }); + open(shape, ds, 'edit', 't1'); + await waitFor(() => expect(titleBox()?.value).toBe('Write report')); + + ds.findOne.mockResolvedValue(null); + await act(async () => { + notifyDataChanged({ objectName: 'task', recordId: 't1' }); + }); + + expect(await screen.findByText(NOT_FOUND_TITLE)).toBeInTheDocument(); + expect(titleBox()).toBeNull(); + expect(button('Update')).toBeNull(); + }); + + it('control: a found record still draws its form and the Update button', async () => { + const ds = makeDS({ id: 't1', title: 'Write report' }); + open(shape, ds, 'edit', 't1'); + + await waitFor(() => expect(titleBox()?.value).toBe('Write report')); + expect(button('Update')).not.toBeNull(); + expect(screen.queryByText(NOT_FOUND_TITLE)).toBeNull(); + }); + + it('control: a create draws an empty form, with no read', async () => { + const ds = makeDS(null); + open(shape, ds, 'create'); + + await waitFor(() => expect(titleBox()).not.toBeNull()); + expect(titleBox()?.value).toBe(''); + expect(button('Create')).not.toBeNull(); + expect(ds.findOne).not.toHaveBeenCalled(); + expect(screen.queryByText(NOT_FOUND_TITLE)).toBeNull(); + }); +}); diff --git a/ui/packages/plugin-form/src/ObjectForm.tsx b/ui/packages/plugin-form/src/ObjectForm.tsx index ce7f25b1ab0..9076fe06c49 100644 --- a/ui/packages/plugin-form/src/ObjectForm.tsx +++ b/ui/packages/plugin-form/src/ObjectForm.tsx @@ -68,6 +68,8 @@ import { import { useOccSave } from './occSave'; import { NO_LOAD_FAILURES, + RecordNotFoundError, + RecordNotFoundState, beginLoadRun, shownLoadFailure, type LoadFailures, @@ -859,6 +861,14 @@ const SimpleObjectForm: React.FC<{ schema: LocalizedObjectFormSchema; dataSource try { const data = await dataSource.findOne(schema.objectName, schema.recordId); if (cancelled) return; + // `findOne` answers `null` for a record that does not exist: there is + // nothing to edit, so the read failed, and the form is not seeded. On a + // bus re-read this is the record deleted while the form is open, drawn + // the same way. + if (data == null) { + run.fail(new RecordNotFoundError(schema.objectName, schema.recordId)); + return; + } // Tagged with the object and record it was read for, so a save that // runs against a different one finds no baseline and sends everything. loadedRecordRef.current = snapshotLoadedRecord(schema, data); @@ -1500,6 +1510,9 @@ const SimpleObjectForm: React.FC<{ schema: LocalizedObjectFormSchema; dataSource const [collapsedSections, setCollapsedSections] = useState>({}); // Render error state + if (error instanceof RecordNotFoundError) { + return ; + } if (error) { return (
From bde6a7fa3a2b47f35ceb2ab994f14fe54683a1b2 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Nov 2026 13:47:55 +0000 Subject: [PATCH 2/5] docs(plugin-form): name the default ObjectForm arm among RecordNotFoundState callers Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jS5aiikUDKUDJZeY1u --- ui/packages/plugin-form/src/loadFailure.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/packages/plugin-form/src/loadFailure.ts b/ui/packages/plugin-form/src/loadFailure.ts index f1460edfd19..95a79b469c4 100644 --- a/ui/packages/plugin-form/src/loadFailure.ts +++ b/ui/packages/plugin-form/src/loadFailure.ts @@ -123,8 +123,8 @@ const useRecordNotFoundTranslation = createSafeTranslation( * What a record form draws in place of its form for a `RecordNotFoundError`: * the record not-found state, never the "Error loading form" box (nothing * failed to load) and never an empty form. One drawing for every layout that - * reads a record (`ModalForm`, `DrawerForm`, `TabbedForm`, `WizardForm`), so - * each host shows the same state. The caller draws no footer or submit beside + * reads a record (`ObjectForm`'s default arm, `ModalForm`, `DrawerForm`, + * `TabbedForm`, `WizardForm`), so each host shows the same state. The caller draws no footer or submit beside * it: each already keeps those off while a load failure is shown. */ export function RecordNotFoundState({ testId }: { testId: string }): ReactElement { From 471030580df16cae03ae13df0a14e8a8385441f8 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Nov 2026 14:03:17 +0000 Subject: [PATCH 3/5] test(plugin-form): type the not-found pin's schema without any Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jS5aiikUDKUDJZeY1u --- .../plugin-form/src/ObjectForm.recordNotFound-29354.test.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/packages/plugin-form/src/ObjectForm.recordNotFound-29354.test.tsx b/ui/packages/plugin-form/src/ObjectForm.recordNotFound-29354.test.tsx index 67d489781c4..1af812d2fc0 100644 --- a/ui/packages/plugin-form/src/ObjectForm.recordNotFound-29354.test.tsx +++ b/ui/packages/plugin-form/src/ObjectForm.recordNotFound-29354.test.tsx @@ -29,7 +29,7 @@ import { render, screen, waitFor, act, cleanup } from '@testing-library/react'; import { notifyDataChanged } from '@object-ui/react'; import { registerAllFields } from '@object-ui/fields'; import type { DataSource } from '@object-ui/types'; -import { ObjectForm } from './ObjectForm'; +import { ObjectForm, type ObjectFormComponentProps } from './ObjectForm'; registerAllFields(); @@ -72,7 +72,7 @@ function open( fields: ['title'], ...shape, }; - render(); + render(); } const titleBox = () => From 578fe25612241764dac9215c542f3c81c6fe7efe Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Nov 2026 14:40:37 +0000 Subject: [PATCH 4/5] test(schema-catalog): give the provenance control an empty record, not a missing one An edit form now draws the record not-found state for a null read, so the control case answers an empty record for its own id to keep a surface with controls and no fixture values behind it. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jS5aiikUDKUDJZeY1u --- .../test/catalog-gallery-render.test.tsx | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/ui/examples/schema-catalog/test/catalog-gallery-render.test.tsx b/ui/examples/schema-catalog/test/catalog-gallery-render.test.tsx index e11e12742fb..b0f4e3dcdff 100644 --- a/ui/examples/schema-catalog/test/catalog-gallery-render.test.tsx +++ b/ui/examples/schema-catalog/test/catalog-gallery-render.test.tsx @@ -1081,10 +1081,16 @@ describe('objectui#6024 — the derivation this pin is built on', () => { * it newly admits are admitted by relaxation. * * The control is the `plugin-form` entries' own shape with ONE thing changed: - * a `recordId` the fixture does not serve. Same renderer, same object, same - * mode, same harness — so what it measures is the record and nothing else. - * Its controls still render, which is asserted first: without that, a form - * that painted nothing would satisfy the line below while measuring nothing. + * a `recordId` whose record holds none of the fixture's values. Same + * renderer, same object, same mode, same harness — so what it measures is the + * record and nothing else. Its controls still render, which is asserted + * first: without that, a form that painted nothing would satisfy the line + * below while measuring nothing. + * + * That record is an EMPTY one, answered by `findOne` for this case's id only. + * It cannot be a record the fixture lacks: `findOne` answers `null` for such + * an id, and an edit form draws the record not-found state for `null` + * (objectstack#29354), with no controls to measure. * * (`mode: 'create'` was tried first and is NOT usable here: it paints its * shell before the object schema resolves, so `renderEntry` — which settles @@ -1092,13 +1098,20 @@ describe('objectui#6024 — the derivation this pin is built on', () => { * its first paint until the fetch lands, which is why this shape settles.) */ it('the provenance instrument still fails on a surface with no record behind it', async () => { + // An empty record for this case's id alone; every other id reads the fixture. + const findOne = galleryDataSource.findOne; + const emptyRecord = vi + .spyOn(galleryDataSource, 'findOne') + .mockImplementation(async (objectName, id) => + String(id) === 'empty-record' ? {} : findOne(objectName, id), + ); // The entries' spelling: the props in the `properties` bag (objectui#10859 batch 4). const r = await renderEntry({ type: 'object-form', properties: { objectName: 'users', mode: 'edit', - recordId: 'no-such-record', + recordId: 'empty-record', fields: ['name', 'email', 'department'], }, }); @@ -1111,6 +1124,7 @@ describe('objectui#6024 — the derivation this pin is built on', () => { expect(carriesFixtureRecord(r)).toBe(false); } finally { teardown(r); + emptyRecord.mockRestore(); } }); From 86d9bc9cbf99cefbdbb96917a6c5d473e5747c15 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Nov 2026 14:48:02 +0000 Subject: [PATCH 5/5] test(schema-catalog): type the control's empty record as a fixture row Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jS5aiikUDKUDJZeY1u --- .../schema-catalog/test/catalog-gallery-render.test.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ui/examples/schema-catalog/test/catalog-gallery-render.test.tsx b/ui/examples/schema-catalog/test/catalog-gallery-render.test.tsx index b0f4e3dcdff..f5555fbbbc6 100644 --- a/ui/examples/schema-catalog/test/catalog-gallery-render.test.tsx +++ b/ui/examples/schema-catalog/test/catalog-gallery-render.test.tsx @@ -1099,11 +1099,14 @@ describe('objectui#6024 — the derivation this pin is built on', () => { */ it('the provenance instrument still fails on a surface with no record behind it', async () => { // An empty record for this case's id alone; every other id reads the fixture. + // Typed as a fixture row because the spy keeps `findOne`'s signature; it + // carries none of a row's values, which is the point. const findOne = galleryDataSource.findOne; + const EMPTY_RECORD = {} as (typeof USERS_ROWS)[number]; const emptyRecord = vi .spyOn(galleryDataSource, 'findOne') .mockImplementation(async (objectName, id) => - String(id) === 'empty-record' ? {} : findOne(objectName, id), + String(id) === 'empty-record' ? EMPTY_RECORD : findOne(objectName, id), ); // The entries' spelling: the props in the `properties` bag (objectui#10859 batch 4). const r = await renderEntry({