Skip to content

Commit a10422d

Browse files
fix(console): a stage move refused with a 409 in a record drawer re-reads the record (#36394)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbVF7sWPNE4HmjkgyaVxQYif)_ repo:objectstack#7 · zhuangjianguo · session_01QsR2jRaJbQ4vqdv4J5peqA Fixes #36309 Clause-②: yes (widening) — measured: the claim expected `no`; `RecordContextValue` gains the optional member `reread` (built `dist/context/RecordContext.d.ts` carries `reread?: () => void | Promise<void>;`, exported through `@object-ui/react`'s root); nothing removed or renamed. The seat amends the claim. Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:在列表抽屉(以及记录页上打开的抽屉)里改阶段被「别人刚改过」拒绝后,记录会重新读取,再点一次「移动」就能成功;抽屉里依旧没有「刷新」按钮,整页记录页不变。 - 为什么做:修的是阶段菜单在抽屉里的一个缺陷(之前只修好了整页),属于记录页阶段推进这条线。 - 出错会怎样:最坏是抽屉里阶段被拒后仍要关掉抽屉重开才能移动,和改前一样;改动可直接撤回。 - 要你做什么:无 ## What changes The card's step 1, measured: the record header's stage menu **does** draw in a drawer. `RecordDetailView` mounts the header's stage slot with no `embedded` gate, and the new pin below finds the menu trigger, opens it and writes a Move in an `embedded` view. The "split preview" no longer exists (`NavigationOverlayMode` lists `page | drawer | new_window | none`; the split face retired), so the embedded surfaces today are the list's record drawer (`objectViewRecordOverlay`'s `RecordStackDrawer`, and `NavigationOverlay` in `ObjectDataPage` / `InterfaceListPage`) and the drawer a record page opens over itself (`RecordPageDrawerHost`). All mount `RecordDetailView` with `embedded`. Step 2, as ruled ("separate 'show a refresh button' from 're-read the record' instead of overloading `refresh`"): - `@object-ui/react` — `RecordContextValue` gains `reread`, the record re-read with no affordance of its own; `refresh` is documented as what it is, the host's opt-in to the header's Refresh entry. `reread` joins the provider's memo dep list. - `@object-ui/plugin-detail` — the stage path (`useStageChange`, shared by the header's `RecordStageMenu` and `record:path`'s stage press) re-reads after a move and after a 409 through `ctx.reread`, and through `ctx.refresh` when the host gives no `reread` (so a host that provides only `refresh` behaves as before). - `@object-ui/app-shell` — `RecordDetailView` hands the header's provider `reread` on the page and in a drawer alike (the same `'*'` notice the Refresh entry publishes: a 409 is a write this client never saw); `refresh` stays `undefined` when embedded, so the drawer still draws no Refresh entry. On the record page the stage path's behaviour is byte-for-byte what it was. ## Tests - New block `RecordDetailView.embeddedStageReread-36309` in the shared harness `RecordDetailView.harness.test.tsx` (the file's rule for new `RecordDetailView` pins): - in a drawer, a 409 on Move re-reads the record and the second Move carries the new version (`ifMatch` of read 2); - CONTROL: the drawer draws no Refresh entry; - CONTROL: on the record page the same 409 re-reads, the second Move carries the new version, and the Refresh entry is still offered. - Red on the base before the fix (commit 4253dfd, test only): `× in a drawer, a 409 on Move re-reads the record …` failing at the `findOne` second-call assertion; both controls green. Green after. - Fixture spelling: `RecordStageMenu-35891.test.tsx` and `record-path.stageChange-28199.test.tsx` handed the stage path `refresh={refresh}`; they now hand `reread={refresh}` (they only used the member the path called). - New block in `RecordStageMenu-35891.test.tsx` (`#36309 a host with only refresh still re-reads; reread wins where both are given`): a provider with only `refresh` calls it after a 409 on Move; CONTROL: with both, `reread` is called and `refresh` is not. - `RecordContext.valueShape.pin.test.tsx` lists `reread` (its compile-time half red the react type-check until it did, which is the pin working). <details><summary>Local readings on head 6e09b30 (round 1; round 2 readings are in the os-dev-report comment on the card)</summary> - `pnpm --dir ui exec vitest run packages/react/src/context/__tests__/RecordContext.valueShape.pin.test.tsx packages/app-shell/src/views/RecordDetailView.harness.test.tsx packages/app-shell/src/views/RecordDetailView.headerRefresh.test.tsx packages/plugin-detail/src/__tests__/RecordStageMenu-35891.test.tsx packages/plugin-detail/src/renderers/__tests__/record-path.stageChange-28199.test.tsx packages/components/src/__tests__/page-header-refresh.test.tsx`: `Test Files 6 passed (6)`, `Tests 160 passed (160)`. - `pnpm --filter @object-ui/react type-check`: exit 0. `@object-ui/plugin-detail`, `@object-ui/components`, `@object-ui/app-shell` `type-check`: exit 0 each (on 7341588, after a build of the app-shell dependency closure; the later head changes only a react test file). - `pnpm --dir ui exec vitest run scripts/`: `Test Files 172 passed | 2 skipped (174)`. - Derived gate families (`dispatch-gates.mjs --commands`): 38 run, all exit 0; `--ran`: `38 derived famil(ies) accounted for — 38 run, 0 NOT-MEASURED`. Ratchets re-run on 6e09b30: `check:type-check-coverage`, `check:type-check-debt`, `check:cross-package-test-inputs`, `check:test-source-alias`, `check:nul-bytes`, `check:published-files`, `check:undeclared-dep-imports`, `check:tier-file-adoption`, all exit 0. - Red on the base (4253dfd, pin only): `1 failed | 2 passed`; the failure is the drawer case at its `findOne` second-call assertion. </details> ## Acceptance notes - `RecordContextProvider` has two other producers, `RecordDetailPanel` (the board/calendar record panel) and `recordBinding`; neither passed `refresh`, so neither re-read after a stage write before, and neither draws a stage surface that writes (the panel draws the inline save bar, which takes its own `refresh` prop; the binding is `canEdit={false}`). Unchanged. - No narrowing: a host that passes only `refresh` keeps its re-read (the stage path falls back to it); `reread` is the added, optional member. Within this repo `RecordDetailView` is the only producer of either. - `content/docs/frontend/` and the react README document no `RecordContext` member, so there is no docs page to update. - Overlap: `overlap-check.mjs` clean against #36343 (shares `RecordDetailView.tsx`) and #36316 (shares the stage files; it adds no `refresh` call there). ## Verification Read first: `ui/packages/plugin-detail/src/renderers/recordPathStageChange.tsx` (the four `reread` calls), `ui/packages/app-shell/src/views/RecordDetailView.tsx` (`headerReread` beside `headerRefresh`), `ui/packages/react/src/context/RecordContext.tsx` (the two members' contract). Two-minute check: `pnpm --dir ui exec vitest run packages/app-shell/src/views/RecordDetailView.harness.test.tsx -t embeddedStageReread` — expect 3 passed. Browser screenshot: NOT MEASURED (no dev app driven in this run; the harness pin renders the real `RecordDetailView` embedded). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01QsR2jRaJbQ4vqdv4J5peqA <!-- signed: repo:objectstack#7 · zhuangjianguo · session_01QsR2jRaJbQ4vqdv4J5peqA --> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
1 parent 9f6f306 commit a10422d

8 files changed

Lines changed: 266 additions & 13 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@object-ui/react': patch
3+
'@object-ui/plugin-detail': patch
4+
'@object-ui/app-shell': patch
5+
---
6+
7+
fix(console): a stage move refused with a 409 in a record drawer re-reads the record, so the next Move sends the stored version
8+
9+
Clause-②: yes (widening) — `RecordContextValue` (and so `RecordContextProviderProps`) gains one optional member, `reread`; nothing is removed or renamed, and `refresh` keeps its type
10+
Metadata-protocol: none
11+
12+
The record header's stage menu also draws in a record drawer (the list's drawer, and the drawer a record page opens over itself). Its save path answered a `409 CONCURRENT_UPDATE` by calling the record context's `refresh`, which the record view leaves out in a drawer so the header draws no Refresh entry there. In a drawer the record was therefore never read again: the dialog kept the old row, and a second Move sent the same stale version and was refused again.
13+
14+
`RecordContextValue` now keeps the two apart. `refresh` stays the host's opt-in to the header's Refresh entry and is still left out in a drawer. The new `reread` reads the record again with no affordance of its own; the record view provides it on the page and in a drawer alike, and the stage menu and `record:path`'s stage press call it after a move and after a 409. On the record page nothing changes: `reread` publishes the same `'*'` notice the Refresh entry does.
15+
16+
A host that mounts `RecordContextProvider` with only `refresh` keeps its behaviour: the stage surfaces call `reread` when the host provides it and `refresh` otherwise. Nothing to migrate; a host that wants the re-read without the Refresh entry passes `reread` alone.

‎ui/packages/app-shell/src/views/RecordDetailView.harness.test.tsx‎

Lines changed: 161 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
import * as React from 'react';
4848
import { describe, it, expect, vi, beforeEach, afterEach, beforeAll, afterAll } from 'vitest';
49-
import { render, waitFor, cleanup, screen, act, fireEvent } from '@testing-library/react';
49+
import { render, waitFor, cleanup, screen, act, fireEvent, within } from '@testing-library/react';
5050
import { MemoryRouter, Route, Routes, BrowserRouter } from 'react-router-dom';
5151
import { toast } from 'sonner';
5252
import { RelatedCountStore } from '@object-ui/components';
@@ -3430,3 +3430,163 @@ describe('RecordDetailView.approvalSubjectTitle-35415', () => {
34303430
});
34313431
});
34323432
});
3433+
3434+
// ── RecordDetailView.embeddedStageReread-36309 ──────────────────────────────
3435+
3436+
/**
3437+
* objectstack#36309 — the header's stage menu draws in a drawer too (the list
3438+
* drawer, and the drawer a record page opens over itself, both mount this view
3439+
* `embedded`). A 409 on a Move there re-reads the record, so the next Move
3440+
* carries the version that is stored. The drawer still draws no Refresh entry:
3441+
* showing the entry and re-reading the record are two context members.
3442+
*/
3443+
describe('RecordDetailView.embeddedStageReread-36309', () => {
3444+
restoreAfterBlock();
3445+
3446+
const OBJECT = 'crm_deal_36309';
3447+
const ID = 'd1';
3448+
const DEF = {
3449+
name: OBJECT,
3450+
label: 'Deal',
3451+
nameField: 'name',
3452+
fields: {
3453+
id: { label: 'Id', type: 'text' },
3454+
name: { label: 'Name', type: 'text' },
3455+
stage: {
3456+
label: 'Stage',
3457+
type: 'select',
3458+
options: [
3459+
{ value: 'prospecting', label: 'Prospecting' },
3460+
{ value: 'negotiation', label: 'Negotiation' },
3461+
],
3462+
},
3463+
},
3464+
};
3465+
const versionAt = (read: number) => `2026-11-22T0${read}:00:00.000Z`;
3466+
3467+
function makeMetadata() {
3468+
const pages: any[] = [];
3469+
return {
3470+
objects: [DEF], pages, loading: false, error: null,
3471+
refresh: async () => {}, invalidate: () => {},
3472+
ensureType: async () => pages, getItem: async () => null,
3473+
getItemsByType: () => pages,
3474+
} as any;
3475+
}
3476+
3477+
/** Every read answers a newer version; the first Move is refused with a 409. */
3478+
function renderDeal(embedded: boolean) {
3479+
let reads = 0;
3480+
const conflict = Object.assign(new Error('CONCURRENT_UPDATE'), { code: 'CONCURRENT_UPDATE', status: 409 });
3481+
let writes = 0;
3482+
const ds = {
3483+
find: vi.fn(async () => ({ data: [], total: 0, hasMore: false, pageSize: 50 })),
3484+
findOne: vi.fn(async () => {
3485+
reads += 1;
3486+
return { id: ID, name: 'Wayne deal', stage: 'prospecting', updated_at: versionAt(reads) };
3487+
}),
3488+
create: vi.fn(async (_o: string, r: any) => r),
3489+
update: vi.fn(async () => {
3490+
writes += 1;
3491+
if (writes === 1) throw conflict;
3492+
return {};
3493+
}),
3494+
delete: vi.fn(async () => ({})),
3495+
getObjectSchema: async () => DEF,
3496+
} as Record<string, any>;
3497+
render(
3498+
<MemoryRouter initialEntries={[`/apps/demo/${OBJECT}/record/${ID}`]}>
3499+
<MetadataCtx.Provider value={makeMetadata()}>
3500+
<NavigationProvider>
3501+
<RecordDetailView
3502+
dataSource={ds as never}
3503+
objects={[DEF] as never}
3504+
onEdit={() => {}}
3505+
objectNameOverride={OBJECT}
3506+
recordIdOverride={ID}
3507+
embedded={embedded}
3508+
/>
3509+
</NavigationProvider>
3510+
</MetadataCtx.Provider>
3511+
</MemoryRouter>,
3512+
);
3513+
return { ds };
3514+
}
3515+
3516+
const stageMenu = () => document.querySelector('[data-record-stage-menu]') as HTMLElement | null;
3517+
const moreTrigger = () =>
3518+
document.querySelector('header [aria-label="More actions"], [data-record-top-bar-actions] [aria-label="More actions"]') as HTMLElement | null;
3519+
3520+
async function pickNegotiation() {
3521+
await waitFor(() => expect(stageMenu()).toBeTruthy());
3522+
fireEvent.pointerDown(stageMenu()!, { button: 0, ctrlKey: false, pointerType: 'mouse' });
3523+
const option = await waitFor(() => {
3524+
const el = document.querySelector('[data-record-stage-menu-list] [data-stage-value="negotiation"]') as HTMLElement | null;
3525+
expect(el).toBeTruthy();
3526+
return el!;
3527+
});
3528+
fireEvent.click(option);
3529+
return screen.findByRole('dialog');
3530+
}
3531+
3532+
beforeAll(() => {
3533+
Object.defineProperty(window, 'innerWidth', { configurable: true, value: 1280 });
3534+
});
3535+
3536+
beforeEach(() => {
3537+
vi.stubGlobal('fetch', vi.fn(async () => ({
3538+
ok: true,
3539+
status: 200,
3540+
json: async () => ({ allowed: true, data: [] }),
3541+
text: async () => '{}',
3542+
})) as never);
3543+
});
3544+
3545+
afterEach(() => {
3546+
cleanup();
3547+
vi.unstubAllGlobals();
3548+
});
3549+
3550+
it('in a drawer, a 409 on Move re-reads the record and the second Move carries the new version', async () => {
3551+
const { ds } = renderDeal(true);
3552+
const dialog = await pickNegotiation();
3553+
expect(ds.findOne).toHaveBeenCalledTimes(1);
3554+
3555+
fireEvent.click(within(dialog).getByRole('button', { name: 'Move' }));
3556+
await waitFor(() => expect(ds.update).toHaveBeenCalledTimes(1));
3557+
expect(ds.update).toHaveBeenLastCalledWith(OBJECT, ID, { stage: 'negotiation' }, { ifMatch: versionAt(1) });
3558+
// The refusal re-reads the record in place.
3559+
await waitFor(() => expect(ds.findOne).toHaveBeenCalledTimes(2));
3560+
3561+
fireEvent.click(within(await screen.findByRole('dialog')).getByRole('button', { name: 'Move' }));
3562+
await waitFor(() => expect(ds.update).toHaveBeenCalledTimes(2));
3563+
expect(ds.update).toHaveBeenLastCalledWith(OBJECT, ID, { stage: 'negotiation' }, { ifMatch: versionAt(2) });
3564+
});
3565+
3566+
it('CONTROL — the drawer still draws no Refresh entry in the header', async () => {
3567+
const { ds } = renderDeal(true);
3568+
await waitFor(() => expect(ds.findOne).toHaveBeenCalled());
3569+
await waitFor(() => expect(stageMenu()).toBeTruthy());
3570+
const trigger = moreTrigger();
3571+
if (trigger) {
3572+
fireEvent.pointerDown(trigger, { button: 0, ctrlKey: false, pointerType: 'mouse' });
3573+
await waitFor(() => expect(document.querySelector('[role="menu"]')).toBeTruthy());
3574+
}
3575+
expect(document.querySelector('[data-page-refresh]')).toBeNull();
3576+
});
3577+
3578+
it('CONTROL — on the record page the same 409 re-reads too, and the page keeps its Refresh entry', async () => {
3579+
const { ds } = renderDeal(false);
3580+
const dialog = await pickNegotiation();
3581+
fireEvent.click(within(dialog).getByRole('button', { name: 'Move' }));
3582+
await waitFor(() => expect(ds.update).toHaveBeenCalledTimes(1));
3583+
await waitFor(() => expect(ds.findOne).toHaveBeenCalledTimes(2));
3584+
fireEvent.click(within(await screen.findByRole('dialog')).getByRole('button', { name: 'Move' }));
3585+
await waitFor(() => expect(ds.update).toHaveBeenLastCalledWith(OBJECT, ID, { stage: 'negotiation' }, { ifMatch: versionAt(2) }));
3586+
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
3587+
3588+
await waitFor(() => expect(moreTrigger()).toBeTruthy());
3589+
fireEvent.pointerDown(moreTrigger()!, { button: 0, ctrlKey: false, pointerType: 'mouse' });
3590+
await waitFor(() => expect(document.querySelector('[data-page-refresh]')).toBeTruthy());
3591+
});
3592+
});

‎ui/packages/app-shell/src/views/RecordDetailView.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,11 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri
11711171
// keeps ⟳ off those surfaces for now. `undefined` is the opt-out
11721172
// `page:header` reads, so nothing renders there.
11731173
const headerRefresh = embedded ? undefined : handleManualRefresh;
1174+
// objectstack#36309 — the header's re-read (`RecordContext.reread`) is not
1175+
// the ⟳: the stage menu draws in a drawer too, and its 409 answer must read
1176+
// the record again there, so every host provides it. Same `'*'` scope as the
1177+
// ⟳: a 409 is exactly a write this client never saw.
1178+
const headerReread = handleManualRefresh;
11741179

11751180
// Record-scoped presence ("who else is viewing this record"). The default
11761181
// PresenceProvider source is a no-op, so this resolves to `[]` until a
@@ -5958,6 +5963,7 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri
59585963
dataSource={dataSource}
59595964
embedded={embedded}
59605965
refresh={headerRefresh}
5966+
reread={headerReread}
59615967
headerSystemActions={synthSystemActions}
59625968
objectLabelNote={inSetupApp ? managedByNote ?? undefined : undefined}
59635969
>

‎ui/packages/plugin-detail/src/__tests__/RecordStageMenu-35891.test.tsx‎

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function mount(opts: MountOptions = {}) {
120120
data={{ id: 'o1', name: 'Wayne deal', stage, loss_reason: null, updated_at: VERSION }}
121121
objectSchema={opts.schema ?? OPPORTUNITY}
122122
dataSource={dataSource as any}
123-
refresh={refresh}
123+
reread={refresh}
124124
>
125125
<InlineEditProvider canEdit={opts.canEdit ?? true}>
126126
<RecordStageMenu field="stage" label={label} tag={tag} />
@@ -423,7 +423,7 @@ describe('#36036 after a 409 re-read, the stage dialog asks what the re-read rec
423423
} as unknown as typeof OPPORTUNITY;
424424

425425
/**
426-
* The page's refresh as the record page wires it: a notice that returns at
426+
* The page's re-read as the record page wires it: a notice that returns at
427427
* once, the re-read row landing in the record context afterwards.
428428
*/
429429
function mountReRead(reread: Record<string, unknown>, schema: typeof OPPORTUNITY = OPPORTUNITY) {
@@ -444,7 +444,7 @@ describe('#36036 after a 409 re-read, the stage dialog asks what the re-read rec
444444
data={row}
445445
objectSchema={schema}
446446
dataSource={dataSource as any}
447-
refresh={refresh}
447+
reread={refresh}
448448
>
449449
<InlineEditProvider canEdit>
450450
<RecordStageMenu field="stage" label="Prospecting" tag={<span>Prospecting</span>} />
@@ -540,6 +540,51 @@ describe('#35891 who sees the plain tag', () => {
540540
});
541541
});
542542

543+
describe('#36309 a host with only refresh still re-reads; reread wins where both are given', () => {
544+
const conflict = () => Object.assign(new Error('CONCURRENT_UPDATE'), { code: 'CONCURRENT_UPDATE', status: 409 });
545+
546+
function mountWith(members: { refresh?: () => Promise<void>; reread?: () => Promise<void> }) {
547+
const dataSource = makeDataSource(async () => { throw conflict(); });
548+
render(
549+
<RecordContextProvider
550+
objectName="crm_opportunity"
551+
recordId="o1"
552+
data={{ id: 'o1', name: 'Wayne deal', stage: 'prospecting', loss_reason: null, updated_at: VERSION }}
553+
objectSchema={OPPORTUNITY}
554+
dataSource={dataSource as any}
555+
{...members}
556+
>
557+
<InlineEditProvider canEdit>
558+
<RecordStageMenu field="stage" label="Prospecting" tag={<span>Prospecting</span>} />
559+
</InlineEditProvider>
560+
</RecordContextProvider>,
561+
);
562+
return { dataSource };
563+
}
564+
565+
it('a provider with only refresh: a 409 on Move calls refresh', async () => {
566+
const refresh = vi.fn(async () => {});
567+
const { dataSource } = mountWith({ refresh });
568+
fireEvent.click(item(openMenu(), 'Negotiation'));
569+
const dialog = await screen.findByRole('dialog');
570+
fireEvent.click(within(dialog).getByRole('button', { name: 'Move' }));
571+
await waitFor(() => expect(dataSource.update).toHaveBeenCalledTimes(1));
572+
await waitFor(() => expect(refresh).toHaveBeenCalledTimes(1));
573+
});
574+
575+
it('CONTROL — a provider with both: a 409 on Move calls reread, not refresh', async () => {
576+
const refresh = vi.fn(async () => {});
577+
const reread = vi.fn(async () => {});
578+
const { dataSource } = mountWith({ refresh, reread });
579+
fireEvent.click(item(openMenu(), 'Negotiation'));
580+
const dialog = await screen.findByRole('dialog');
581+
fireEvent.click(within(dialog).getByRole('button', { name: 'Move' }));
582+
await waitFor(() => expect(dataSource.update).toHaveBeenCalledTimes(1));
583+
await waitFor(() => expect(reread).toHaveBeenCalledTimes(1));
584+
expect(refresh).not.toHaveBeenCalled();
585+
});
586+
});
587+
543588
describe('#35891 the keyboard', () => {
544589
it('Enter opens the menu; Escape closes it without a write', async () => {
545590
const { dataSource } = mount();

‎ui/packages/plugin-detail/src/renderers/__tests__/record-path.stageChange-28199.test.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function mount(opts: MountOptions = {}) {
111111
data={{ id: 'q1', status: 'draft', updated_at: VERSION }}
112112
objectSchema={opts.objectSchema ?? OBJECT_SCHEMA}
113113
dataSource={dataSource as any}
114-
refresh={refresh}
114+
reread={refresh}
115115
>
116116
<InlineEditProvider canEdit={opts.canEdit ?? true}>
117117
{opts.editing && <EnterEditing />}
@@ -330,7 +330,7 @@ function mountNode(node: unknown, opts: Omit<MountOptions, 'allowStageChange'> =
330330
data={{ id: 'q1', status: 'draft', updated_at: VERSION }}
331331
objectSchema={opts.objectSchema ?? QUOTE_DEF}
332332
dataSource={dataSource as any}
333-
refresh={refresh}
333+
reread={refresh}
334334
>
335335
<InlineEditProvider canEdit={opts.canEdit ?? true}>
336336
<SchemaRenderer schema={node as never} />

‎ui/packages/plugin-detail/src/renderers/recordPathStageChange.tsx‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@
5858
*
5959
* The fields asked are judged against the record AS IT STANDS, on every
6060
* render, not frozen at the pick (objectstack#36036). A 409 re-reads the
61-
* record, and the re-read row reaches this hook later through the record
62-
* context (the page's refresh is a bus notice, not a fetch it can await), so
61+
* record (`RecordContextValue.reread`, else the host's `refresh`; the record
62+
* view provides `reread` on the page and in a drawer alike), and the re-read row reaches this hook later through the record
63+
* context (the page's re-read is a bus notice, not a fetch it can await), so
6364
* the list follows that row when it lands: a field another writer filled in
6465
* the meantime leaves the dialog, the move no longer sends it, and a value the
6566
* reader typed for it stops counting toward the fields it would chain in. When
@@ -211,6 +212,9 @@ export function useStageChange(
211212
): StageChange {
212213
const collectFields = options.collectFields === true;
213214
const ctx = useRecordContext();
215+
// The record's re-read after a move or a 409: the host's `reread`, else its
216+
// `refresh` (a host that provides only `refresh` keeps re-reading).
217+
const rereadRecord = async () => { await (ctx?.reread ?? ctx?.refresh)?.(); };
214218
const inline = useInlineEdit();
215219
const perms = usePermissions();
216220
const { t } = useDetailTranslation();
@@ -288,12 +292,12 @@ export function useStageChange(
288292
setBusy(true);
289293
try {
290294
await updateVia(dataSource, objectName!, recordId!, { [statusField!]: stage.value }, ifMatchOf());
291-
await ctx?.refresh?.();
295+
await rereadRecord();
292296
} catch (err) {
293297
setRefusal(stageRefusalLines(err, statusField!, labelOf, t));
294298
// A stale token means the reader is looking at an old record: show the
295299
// current one, so a second press is judged against what is stored.
296-
if (isConcurrentUpdateError(err)) await ctx?.refresh?.();
300+
if (isConcurrentUpdateError(err)) await rereadRecord();
297301
} finally {
298302
setBusy(false);
299303
}
@@ -314,7 +318,7 @@ export function useStageChange(
314318
await updateVia(dataSource, objectName!, recordId!, { ...values, [statusField!]: stage.value }, ifMatchOf());
315319
} catch (err) {
316320
const concurrent = isConcurrentUpdateError(err);
317-
if (concurrent) await ctx?.refresh?.();
321+
if (concurrent) await rereadRecord();
318322
const named = concurrent ? [] : (extractFieldErrors(err) ?? []).filter((e) => !!e.message);
319323
if (named.length > 0 && !declaredUserMessage(err)) throw err;
320324
const line = stageRefusalLines(err, statusField!, labelOf, t).join(' ');
@@ -323,7 +327,7 @@ export function useStageChange(
323327
setBusy(false);
324328
}
325329
setTarget(null);
326-
await ctx?.refresh?.();
330+
await rereadRecord();
327331
};
328332

329333
const dialog = collectFields

‎ui/packages/react/src/context/RecordContext.tsx‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,26 @@ export interface RecordContextValue<TData = any, TObjectSchema = any> {
153153
data?: TData;
154154
/** Resolved object metadata schema (fields, label, etc.). */
155155
objectSchema?: TObjectSchema;
156-
/** Re-fetch the record from the source. */
156+
/**
157+
* The host's opt-in to the header's Refresh entry (the first item of its
158+
* `⋯` menu): present, `page:header` draws the entry and calls this when it
159+
* is picked; absent, the header draws none. A host that keeps the entry off
160+
* a surface (a drawer) leaves it out. It also re-reads the record: a
161+
* renderer that needs a re-read calls {@link RecordContextValue.reread}
162+
* when the host provides one, and this otherwise.
163+
*/
157164
refresh?: () => void | Promise<void>;
165+
/**
166+
* Read the record again from the source, with no affordance of its own.
167+
* A renderer that must judge its next write against what is stored calls
168+
* it: after a write it made, and after a `409 CONCURRENT_UPDATE` refusal, so
169+
* the next write carries the stored version. A host provides it wherever it
170+
* reads the record, drawers included, whether or not it offers
171+
* {@link RecordContextValue.refresh}; a renderer falls back to `refresh`
172+
* when a host provides only that. It may be a notice that returns before
173+
* the re-read row lands; the row reaches readers through `data` afterwards.
174+
*/
175+
reread?: () => void | Promise<void>;
158176
/**
159177
* Optional system-level header actions (Edit / Share / Delete) that the
160178
* host (e.g. RecordDetailView) wants to inject into the page header
@@ -235,6 +253,7 @@ export const RecordContextProvider: React.FC<RecordContextProviderProps> = ({
235253
value.data,
236254
value.objectSchema,
237255
value.refresh,
256+
value.reread,
238257
value.embedded,
239258
value.headerSystemActions,
240259
value.isFavorite,

0 commit comments

Comments
 (0)