From 68e742a16e35af31e47cf39532dcad4de9bb1f18 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 25 Sep 2026 06:50:33 +0000 Subject: [PATCH 1/2] test(plugin-gantt): pin the in-place refresh on a real query change The A-prime half of ruling C+A-prime on objectui#7237. Once the chart has painted, a real sort, filter or permissions change must keep GanttView mounted, show a visible refreshing state on the chart while the query runs, and replace the rows when it returns; the initial load keeps the loading placeholder. Red on the base: the re-query unmounts GanttView through the placeholder and nothing marks the refresh. Claude-Session: https://claude.ai/code/session_014mXUNuFomfj24w7s1pZzhN Co-authored-by: Claude --- .../ObjectGantt.refreshInPlace-7237.test.tsx | 288 ++++++++++++++++++ 1 file changed, 288 insertions(+) create mode 100644 packages/plugin-gantt/src/ObjectGantt.refreshInPlace-7237.test.tsx diff --git a/packages/plugin-gantt/src/ObjectGantt.refreshInPlace-7237.test.tsx b/packages/plugin-gantt/src/ObjectGantt.refreshInPlace-7237.test.tsx new file mode 100644 index 0000000000..12faf67ff1 --- /dev/null +++ b/packages/plugin-gantt/src/ObjectGantt.refreshInPlace-7237.test.tsx @@ -0,0 +1,288 @@ +/** + * 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. + */ + +/** + * objectui#7237, ruling A′ — once the chart has painted, a REAL change to the + * query (sort, filter, permissions) refreshes the rows IN PLACE: the chart + * stays mounted with its scroll, collapsed groups and in-flight edits, a + * visible refreshing state sits on the chart while the query runs, and the rows + * are replaced when it returns. It never tears down to the loading + * placeholder. The initial load keeps the placeholder. + * + * `GanttView` is a stand-in that takes an instance id from a `useState` + * initializer, which runs once per mount. A changed id means `GanttView` was + * unmounted, and the only thing on this path that unmounts it is the loading + * placeholder a non-silent reload swaps in. Every `find` is held open by hand, + * so each assertion about the in-flight state is made while the query really + * is in flight. + * + * ⛔ This file does not pin "2 → 1 filter identities at the gantt node". That + * reading cannot fail on today's main (ListView's filter hold already gives 1), + * so it is no evidence for the behaviour this ruling asks for. + */ + +import React from 'react'; +import { render, screen, waitFor, act } from '@testing-library/react'; +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { I18nProvider } from '@object-ui/i18n'; +import { PermissionProvider } from '@object-ui/permissions'; +import type { DataSource } from '@object-ui/types'; +import { ObjectGantt } from './ObjectGantt'; +import { GANTT_DEFAULT_TRANSLATIONS } from './useGanttTranslation'; + +vi.mock('sonner', () => ({ toast: { error: vi.fn(), success: vi.fn() } })); + +let instanceSeq = 0; + +vi.mock('./GanttView', () => ({ + GanttView: ({ tasks }: any) => { + const [id] = React.useState(() => ++instanceSeq); + return ( +
+ {tasks.map((t: any) => ( +
{t.title}
+ ))} +
+ ); + }, +})); + +const PLACEHOLDER = 'Loading Gantt chart...'; + +const FIRST_ROWS = [ + { id: '1', name: 'From the first query', start_date: '2024-01-01', end_date: '2024-01-05' }, +]; +const NEXT_ROWS = [ + { id: '2', name: 'From the changed query', start_date: '2024-02-01', end_date: '2024-02-05' }, +]; + +const OBJECT_SCHEMA = { + fields: { + name: { type: 'text' }, + start_date: { type: 'date' }, + end_date: { type: 'date' }, + }, +}; + +function schemaWith(extra: Record = {}): any { + return { + type: 'object-gantt', + gantt: { titleField: 'name', startDateField: 'start_date', endDateField: 'end_date' }, + data: { provider: 'object', object: 'tasks' }, + ...extra, + }; +} + +interface Deferred { + promise: Promise; + resolve: (value: T) => void; + reject: (reason: unknown) => void; +} + +function deferred(): Deferred { + let resolve!: (value: T) => void; + let reject!: (reason: unknown) => void; + const promise = new Promise((res, rej) => { + resolve = res; + reject = rej; + }); + return { promise, resolve, reject }; +} + +/** Every `find` returns a promise the test settles by hand. */ +function makeDeferredDataSource() { + const finds: Deferred[] = []; + const dataSource = { + find: vi.fn(() => { + const d = deferred(); + finds.push(d); + return d.promise; + }), + findOne: vi.fn(), + create: vi.fn(), + update: vi.fn(), + delete: vi.fn(), + getObjectSchema: vi.fn().mockResolvedValue(OBJECT_SCHEMA), + } as unknown as DataSource; + return { dataSource, finds, find: dataSource.find as unknown as ReturnType }; +} + +async function answer(d: Deferred, rows: unknown[]) { + await act(async () => { + d.resolve({ data: rows }); + await Promise.resolve(); + }); +} + +const view = () => screen.getByTestId('gantt-view'); +const indicator = () => screen.queryByTestId('refresh-indicator'); + +/** + * The three real changes the ruling names. Each builds the element for the + * first render and for the changed one. The permissions case goes through a + * real `PermissionProvider`: a different role set publishes a new context + * value, which is how a permission change reaches the gantt's query. + */ +const CHANGES: Array<[string, (ds: DataSource) => [React.ReactElement, React.ReactElement]]> = [ + [ + 'sort', + (ds) => [ + , + , + ], + ], + [ + 'filter', + (ds) => [ + , + , + ], + ], + [ + 'permissions', + (ds) => { + const schema = schemaWith(); + const withRoles = (userRoles: string[]) => ( + + + + ); + return [withRoles(['planner']), withRoles(['viewer'])]; + }, + ], +]; + +beforeEach(() => { + instanceSeq = 0; + // The I18nProvider persists the last language; keep the zh case from leaking. + window.localStorage.clear(); +}); + +describe('ObjectGantt refreshes in place on a real query change (objectui#7237, ruling A′)', () => { + it.each(CHANGES)('a real %s change keeps the chart mounted, shows the refreshing state, then replaces the rows', async (_name, build) => { + const { dataSource, finds, find } = makeDeferredDataSource(); + const [first, changed] = build(dataSource); + + const { rerender } = render(first); + await waitFor(() => expect(find).toHaveBeenCalledTimes(1)); + await answer(finds[0], FIRST_ROWS); + await waitFor(() => expect(screen.getByText('From the first query')).toBeTruthy()); + const mountedAs = view().dataset.instance; + expect(indicator(), 'no refreshing state while nothing is in flight').toBeNull(); + + rerender(changed); + await waitFor(() => expect(find).toHaveBeenCalledTimes(2)); + + // The changed query is in flight. Soft assertions, so each of the three + // readings reports on its own rather than the first one hiding the rest. + expect.soft( + screen.queryByTestId('gantt-view')?.dataset.instance ?? 'unmounted', + '(a) GanttView was unmounted by the re-query, which loses its scroll, collapsed groups and in-flight edits', + ).toBe(mountedAs); + expect.soft( + indicator() ? 'present' : 'absent', + '(b) no visible refreshing state on the chart while the changed query is in flight', + ).toBe('present'); + expect.soft(indicator()?.getAttribute('aria-label'), 'the refreshing state has no localized name').toBe('Refreshing…'); + expect.soft( + screen.queryByText(PLACEHOLDER)?.textContent ?? 'no placeholder', + 'the re-query tore the chart down to the loading placeholder', + ).toBe('no placeholder'); + // The rows on screen until then are the previous answer, marked as refreshing. + expect.soft(screen.queryByText('From the first query')?.textContent ?? 'absent').toBe('From the first query'); + + await answer(finds[1], NEXT_ROWS); + + await waitFor(() => + expect( + screen.queryByText('From the changed query'), + '(c) the answer to the changed query never replaced the rows', + ).not.toBeNull(), + ); + expect(screen.queryByText('From the first query')).toBeNull(); + expect(indicator(), 'the refreshing state outlived the query').toBeNull(); + expect(view().dataset.instance, '(a) after the answer: not the GanttView that painted the first rows').toBe(mountedAs); + expect(find).toHaveBeenCalledTimes(2); + }); + + it('the re-query really carries the changed query', async () => { + const { dataSource, finds, find } = makeDeferredDataSource(); + const [first, changed] = CHANGES[0][1](dataSource); + + const { rerender } = render(first); + await waitFor(() => expect(find).toHaveBeenCalledTimes(1)); + await answer(finds[0], FIRST_ROWS); + rerender(changed); + await waitFor(() => expect(find).toHaveBeenCalledTimes(2)); + + expect(find.mock.calls[0][1].$orderby).toEqual({ start_date: 'asc' }); + expect(find.mock.calls[1][1].$orderby).toEqual({ start_date: 'desc' }); + }); + + it('(d) control: the initial load still shows the placeholder, and no refreshing state', async () => { + const { dataSource, finds, find } = makeDeferredDataSource(); + + render(); + await waitFor(() => expect(find).toHaveBeenCalledTimes(1)); + + expect(screen.getByText(PLACEHOLDER)).toBeTruthy(); + expect(screen.queryByTestId('gantt-view')).toBeNull(); + expect(indicator()).toBeNull(); + + await answer(finds[0], FIRST_ROWS); + await waitFor(() => expect(screen.getByText('From the first query')).toBeTruthy()); + expect(screen.queryByText(PLACEHOLDER)).toBeNull(); + }); + + it('a failed re-query reports the error instead of leaving the previous query\'s rows on screen', async () => { + const { dataSource, finds, find } = makeDeferredDataSource(); + const [first, changed] = CHANGES[0][1](dataSource); + const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {}); + + const { rerender } = render(first); + await waitFor(() => expect(find).toHaveBeenCalledTimes(1)); + await answer(finds[0], FIRST_ROWS); + await waitFor(() => expect(screen.getByText('From the first query')).toBeTruthy()); + + rerender(changed); + await waitFor(() => expect(find).toHaveBeenCalledTimes(2)); + await act(async () => { + finds[1].reject(new Error('sort field not readable')); + await Promise.resolve(); + }); + + // A background refresh of the SAME query may keep its last good rows; an + // answer to a DIFFERENT query may not. Those rows do not match the sort the + // user just chose, and with the refreshing state gone nothing would say so. + await waitFor(() => expect(screen.getByText('Error: sort field not readable')).toBeTruthy()); + expect(screen.queryByText('From the first query')).toBeNull(); + consoleError.mockRestore(); + }); + + it('labels the refreshing state from the locale pack (zh)', async () => { + const { dataSource, finds, find } = makeDeferredDataSource(); + const withLang = (el: React.ReactElement) => ( + {el} + ); + const [first, changed] = CHANGES[0][1](dataSource); + + const { rerender } = render(withLang(first)); + await waitFor(() => expect(find).toHaveBeenCalledTimes(1)); + await answer(finds[0], FIRST_ROWS); + await waitFor(() => expect(screen.getByText('From the first query')).toBeTruthy()); + + rerender(withLang(changed)); + await waitFor(() => expect(find).toHaveBeenCalledTimes(2)); + + // `useGanttTranslation` falls back per key to the bundled English, so an + // English reading here could not tell a pack entry from a missing one. + await waitFor(() => expect(indicator()?.getAttribute('aria-label')).toBe('刷新中…')); + expect(indicator()!.getAttribute('aria-label')).not.toBe(GANTT_DEFAULT_TRANSLATIONS['gantt.aria.refreshing']); + expect(GANTT_DEFAULT_TRANSLATIONS['gantt.aria.refreshing']).toBe('Refreshing…'); + }); +}); From c1041d311423e550c3bee759149fd28eddc9b017 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 25 Sep 2026 07:04:16 +0000 Subject: [PATCH 2/2] feat(plugin-gantt): refresh in place on a real query change The A-prime half of ruling C+A-prime on objectui#7237. The fetch effect ran every reload non-silently, so a sort, filter or permissions change on a painted chart flipped `loading` and the early return swapped GanttView for the placeholder, losing scroll, collapsed groups and in-flight edits. `reload` now takes two independent options: `inPlace` (keep the chart mounted, set `refreshing`) and `silent` (a failure keeps the last good rows; implies in place). The fetch effect runs the initial load with the placeholder as before, and every run after rows have committed in place, not silent: a changed query that fails is still reported. The chart pane draws the shared RefreshIndicator while `refreshing` is set, named by the new `gantt.aria.refreshing` key in all ten locale packs. The objectui#7231 guard test generated its overlap from a post-paint filter change, which no longer holds `loading`; its pairs are regenerated from the ones that still put each flag in play, with every guard assertion kept and a post-paint `refreshing` twin added. Claude-Session: https://claude.ai/code/session_014mXUNuFomfj24w7s1pZzhN Co-authored-by: Claude --- .changeset/7237-gantt-refresh-in-place.md | 14 ++ packages/i18n/src/locales/ar.ts | 1 + packages/i18n/src/locales/de.ts | 1 + packages/i18n/src/locales/en.ts | 1 + packages/i18n/src/locales/es.ts | 1 + packages/i18n/src/locales/fr.ts | 1 + packages/i18n/src/locales/ja.ts | 1 + packages/i18n/src/locales/ko.ts | 1 + packages/i18n/src/locales/pt.ts | 1 + packages/i18n/src/locales/ru.ts | 1 + packages/i18n/src/locales/zh.ts | 1 + ...jectGantt.staleReloadFinally-7231.test.tsx | 153 ++++++++++++++---- packages/plugin-gantt/src/ObjectGantt.tsx | 84 +++++++--- .../plugin-gantt/src/useGanttTranslation.ts | 1 + 14 files changed, 214 insertions(+), 48 deletions(-) create mode 100644 .changeset/7237-gantt-refresh-in-place.md diff --git a/.changeset/7237-gantt-refresh-in-place.md b/.changeset/7237-gantt-refresh-in-place.md new file mode 100644 index 0000000000..d796a70dd9 --- /dev/null +++ b/.changeset/7237-gantt-refresh-in-place.md @@ -0,0 +1,14 @@ +--- +'@object-ui/plugin-gantt': minor +'@object-ui/i18n': patch +--- + +`ObjectGantt` refreshes in place when its query really changes, instead of tearing the chart down to the loading placeholder (objectui#7237). + +Once the chart has painted, a change to its sort, filter, permissions, search or bound source re-runs the query with the chart still mounted, so it keeps its scroll position, its collapsed groups and any inline edit in progress. While the query runs, a thin indeterminate bar over the chart marks the rows on screen as the previous answer, and the rows are replaced when the new answer lands. It is the same `RefreshIndicator` that `ObjectGrid`, `ListView` and `ObjectChart` draw over their rows. The initial load still shows the loading placeholder. + +The bar also shows during the chart's other in-place re-reads: the toolbar refresh, the re-read after a drag, a dependency link, a delete or a field edit, and a re-read triggered by the data-invalidation bus. Those already kept the chart mounted, but the only sign of them was a disabled refresh button. + +A changed query that fails is still reported as an error, as it was before. Only a re-read of the same query keeps its last good rows when it fails. + +`@object-ui/i18n`: new key `gantt.aria.refreshing`, the bar's accessible name, in all ten locale packs. diff --git a/packages/i18n/src/locales/ar.ts b/packages/i18n/src/locales/ar.ts index cbe06ce9e7..001c9129eb 100644 --- a/packages/i18n/src/locales/ar.ts +++ b/packages/i18n/src/locales/ar.ts @@ -781,6 +781,7 @@ const ar = { }, aria: { taskList: "قائمة المهام", + refreshing: "جارٍ التحديث…", }, tooltip: { days: "ي", diff --git a/packages/i18n/src/locales/de.ts b/packages/i18n/src/locales/de.ts index e875628905..dc8a6ab2f9 100644 --- a/packages/i18n/src/locales/de.ts +++ b/packages/i18n/src/locales/de.ts @@ -773,6 +773,7 @@ const de = { }, aria: { taskList: "Vorgangsliste", + refreshing: "Aktualisiere…", }, tooltip: { days: "T", diff --git a/packages/i18n/src/locales/en.ts b/packages/i18n/src/locales/en.ts index bf3ef25c91..b32b6132b6 100644 --- a/packages/i18n/src/locales/en.ts +++ b/packages/i18n/src/locales/en.ts @@ -941,6 +941,7 @@ const en = { }, aria: { taskList: 'Task list', + refreshing: 'Refreshing…', }, tooltip: { days: 'd', diff --git a/packages/i18n/src/locales/es.ts b/packages/i18n/src/locales/es.ts index dc9c119da6..cb8a026520 100644 --- a/packages/i18n/src/locales/es.ts +++ b/packages/i18n/src/locales/es.ts @@ -777,6 +777,7 @@ const es = { }, aria: { taskList: "Lista de tareas", + refreshing: "Actualizando…", }, tooltip: { days: "d", diff --git a/packages/i18n/src/locales/fr.ts b/packages/i18n/src/locales/fr.ts index ad82010c1c..0f067e9aa0 100644 --- a/packages/i18n/src/locales/fr.ts +++ b/packages/i18n/src/locales/fr.ts @@ -773,6 +773,7 @@ const fr = { }, aria: { taskList: "Liste des tâches", + refreshing: "Actualisation…", }, tooltip: { days: "j", diff --git a/packages/i18n/src/locales/ja.ts b/packages/i18n/src/locales/ja.ts index 49f9e978e7..0e6d73b1bc 100644 --- a/packages/i18n/src/locales/ja.ts +++ b/packages/i18n/src/locales/ja.ts @@ -773,6 +773,7 @@ const ja = { }, aria: { taskList: "タスク一覧", + refreshing: "更新中…", }, tooltip: { days: "日", diff --git a/packages/i18n/src/locales/ko.ts b/packages/i18n/src/locales/ko.ts index 4d75a5fffa..5df404f2c8 100644 --- a/packages/i18n/src/locales/ko.ts +++ b/packages/i18n/src/locales/ko.ts @@ -773,6 +773,7 @@ const ko = { }, aria: { taskList: "작업 목록", + refreshing: "새로고침 중…", }, tooltip: { days: "일", diff --git a/packages/i18n/src/locales/pt.ts b/packages/i18n/src/locales/pt.ts index f4aadcbdd4..9b446ebbd4 100644 --- a/packages/i18n/src/locales/pt.ts +++ b/packages/i18n/src/locales/pt.ts @@ -772,6 +772,7 @@ const pt = { }, aria: { taskList: "Lista de tarefas", + refreshing: "Atualizando…", }, tooltip: { days: "d", diff --git a/packages/i18n/src/locales/ru.ts b/packages/i18n/src/locales/ru.ts index 2db07986c1..7bfcadd859 100644 --- a/packages/i18n/src/locales/ru.ts +++ b/packages/i18n/src/locales/ru.ts @@ -783,6 +783,7 @@ const ru = { }, aria: { taskList: "Список задач", + refreshing: "Обновление…", }, tooltip: { days: "дн", diff --git a/packages/i18n/src/locales/zh.ts b/packages/i18n/src/locales/zh.ts index 10e53b1ae2..f7ec302b19 100644 --- a/packages/i18n/src/locales/zh.ts +++ b/packages/i18n/src/locales/zh.ts @@ -825,6 +825,7 @@ const zh = { }, aria: { taskList: '任务列表', + refreshing: '刷新中…', }, tooltip: { days: '天', diff --git a/packages/plugin-gantt/src/ObjectGantt.staleReloadFinally-7231.test.tsx b/packages/plugin-gantt/src/ObjectGantt.staleReloadFinally-7231.test.tsx index 4364c8565e..ec075cee54 100644 --- a/packages/plugin-gantt/src/ObjectGantt.staleReloadFinally-7231.test.tsx +++ b/packages/plugin-gantt/src/ObjectGantt.staleReloadFinally-7231.test.tsx @@ -24,7 +24,8 @@ * below as the control. * * The guard shape matters, hence the third case. The flags are per-MODE - * (`silent` → `refreshing`, otherwise `loading`), so a `finally` that clears + * (in place → `refreshing`, otherwise `loading`; a silent reload is always in + * place), so a `finally` that clears * only its own mode's flag when current leaks the other one: a silent reload * superseded by a non-silent one would never clear `refreshing`, leaving the * toolbar's refresh button stuck busy for the life of the component. What @@ -54,27 +55,59 @@ * been weakened — the orderings (stale-first, fresh-first), the flags and the * outcomes are the same. The `finally` guard itself is not modified by that * card or this one. + * + * ⚠️ …and it changed again with objectui#7237 (ruling A′). A filter change + * on a chart that has already PAINTED now refreshes in place: it sets + * `refreshing`, not `loading`, and never swaps in the placeholder. So "a + * toolbar refresh superseded by a filter change" no longer holds `loading` at + * all, and the cases that asserted the placeholder over it were asserting the + * teardown that ruling removed. The guard is unchanged; the pairs that still + * put each flag in play are these: + * + * - `loading`: two NON-silent reloads, i.e. a query change BEFORE the first + * paint (the mount's load superseded by it). Case 1. + * - `refreshing` held by two runs: the toolbar refresh superseded by an + * in-place filter change AFTER the paint. Case 1b, the post-paint twin of + * case 1, and case 2, the fresh-first control. + * - the mixed-mode pair case 3 needs (a silent run superseded by a + * non-silent one): only before the first paint, where an invalidation + * reload (silent) is overtaken by a query change (non-silent). + * + * Each assertion about the guard is kept, and each case still fails with the + * `finally` guard removed or narrowed to its own mode. */ import React from 'react'; import { render, screen, waitFor, fireEvent, act } from '@testing-library/react'; -import { describe, it, expect, vi } from 'vitest'; +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { notifyDataChanged } from '@object-ui/react'; import { ObjectGantt } from './ObjectGantt'; import type { DataSource } from '@object-ui/types'; +let instanceSeq = 0; + // Probe stand-in: the real chart is irrelevant here, but `refreshing` is not — -// case 3 reads it back off the DOM. +// cases 1b and 3 read it back off the DOM. The instance id (a `useState` +// initializer, once per mount) is what shows the post-paint pair stays in +// place. vi.mock('./GanttView', () => ({ - GanttView: ({ tasks, onRefresh, refreshing }: any) => ( -
- {tasks.map((t: any) => ( -
{t.title}
- ))} - -
- ), + GanttView: ({ tasks, onRefresh, refreshing }: any) => { + const [id] = React.useState(() => ++instanceSeq); + return ( +
+ {tasks.map((t: any) => ( +
{t.title}
+ ))} + +
+ ); + }, })); +beforeEach(() => { + instanceSeq = 0; +}); + const PLACEHOLDER = 'Loading Gantt chart...'; const ROWS_A = [ @@ -159,10 +192,11 @@ async function flush() { } /** - * Bring the component to the state every case below needs: painted, then two - * reloads in flight at once — a SILENT toolbar refresh (`finds[1]`, owns - * `refreshing`) superseded by a non-silent filter-change reload (`finds[2]`, - * owns `loading`). + * AFTER the paint: two reloads in flight at once — a SILENT toolbar refresh + * (`finds[1]`) superseded by an IN-PLACE filter-change reload (`finds[2]`). + * Both hold `refreshing` (objectui#7237: a query change on a painted chart + * refreshes in place), so this pair puts that flag in play, and the chart must + * stay mounted throughout. * * The mount issues exactly ONE `find` since objectui#7225's gate; that single * assertion is also this file's live control on the gate, because a @@ -188,19 +222,35 @@ async function paintThenOverlap( await waitFor(() => expect((dataSource.find as any).mock.calls.length).toBe(3)); } +/** + * BEFORE the paint: the mount's load (`finds[0]`) superseded by a filter + * change (`finds[1]`). Nothing has painted, so both are the initial load and + * both hold `loading` — the pair that still puts the placeholder in play. + */ +async function overlapBeforePaint( + dataSource: DataSource, + rerender: (ui: React.ReactElement) => void, +) { + await waitFor(() => expect((dataSource.find as any).mock.calls.length).toBe(1)); + rerender(); + await waitFor(() => expect((dataSource.find as any).mock.calls.length).toBe(2)); +} + +const refreshIndicator = () => screen.queryByTestId('refresh-indicator'); + describe('ObjectGantt — a superseded reload must not clear the loading state (objectui#7231)', () => { it('keeps the placeholder up when the STALE reload finishes first and the fresh one is still in flight', async () => { const { dataSource, finds } = makeDeferredDataSource(); const { rerender } = render(); - await paintThenOverlap(dataSource, finds, rerender); + await overlapBeforePaint(dataSource, rerender); - // The non-silent reload owns `loading`, so the placeholder is up and the - // chart is unmounted while both are in flight. + // Both reloads own `loading`, so the placeholder is up and the chart is + // not mounted while both are in flight. expect(screen.getByText(PLACEHOLDER)).toBeTruthy(); - // The superseded (silent) reload answers first — the ordinary ordering. - await settle(finds[1], ROWS_A); + // The superseded reload answers first — the ordinary ordering. + await settle(finds[0], ROWS_A); // Its `finally` must NOT clear `loading`: the fresh query has not answered, // so releasing the placeholder here paints an empty chart. @@ -208,13 +258,44 @@ describe('ObjectGantt — a superseded reload must not clear the loading state ( expect(screen.queryByTestId('gantt-view')).toBeNull(); // The current reload answers and owns the transition out of loading. - await settle(finds[2], ROWS_B); + await settle(finds[1], ROWS_B); await waitFor(() => expect(screen.getByTestId('gantt-view')).toBeTruthy()); expect(screen.getByText('From the fresh query')).toBeTruthy(); expect(screen.queryByText('From the stale query')).toBeNull(); }); + it('keeps the refreshing state up when the STALE reload finishes first after the paint (the in-place twin)', async () => { + const { dataSource, finds } = makeDeferredDataSource(); + + const { rerender } = render(); + await paintThenOverlap(dataSource, finds, rerender); + const mountedAs = screen.getByTestId('gantt-view').dataset.instance; + + // Both reloads are in place: no placeholder, the chart stays mounted, and + // the refreshing state is up. + expect(screen.queryByText(PLACEHOLDER)).toBeNull(); + expect(screen.getByTestId('gantt-view').getAttribute('data-refreshing')).toBe('true'); + expect(refreshIndicator()).not.toBeNull(); + + // The superseded (silent) reload answers first. + await settle(finds[1], ROWS_A); + + // Its `finally` must NOT clear `refreshing`: the changed query has not + // answered, so dropping the refreshing state here passes the previous + // query's rows off as the answer to the new one. + expect(screen.getByTestId('gantt-view').getAttribute('data-refreshing')).toBe('true'); + expect(refreshIndicator()).not.toBeNull(); + + await settle(finds[2], ROWS_B); + + await waitFor(() => expect(screen.getByText('From the fresh query')).toBeTruthy()); + expect(screen.getByTestId('gantt-view').getAttribute('data-refreshing')).toBe('false'); + expect(refreshIndicator()).toBeNull(); + expect(screen.getByTestId('gantt-view').dataset.instance).toBe(mountedAs); + expect(screen.queryByText(PLACEHOLDER)).toBeNull(); + }); + it('control — the fresh reload finishing FIRST paints its rows, and the late stale answer changes nothing', async () => { const { dataSource, finds } = makeDeferredDataSource(); @@ -224,11 +305,10 @@ describe('ObjectGantt — a superseded reload must not clear the loading state ( // Out-of-order: the current reload answers before the superseded one. await settle(finds[2], ROWS_B); - await waitFor(() => expect(screen.getByTestId('gantt-view')).toBeTruthy()); - expect(screen.getByText('From the fresh query')).toBeTruthy(); + await waitFor(() => expect(screen.getByText('From the fresh query')).toBeTruthy()); // The late stale answer must neither clobber the data (the pre-existing - // `setData` guard) nor put the placeholder back. + // `setData` guard) nor put the placeholder or the refreshing state back. await settle(finds[1], ROWS_A); await flush(); @@ -236,13 +316,23 @@ describe('ObjectGantt — a superseded reload must not clear the loading state ( expect(screen.getByText('From the fresh query')).toBeTruthy(); expect(screen.queryByText('From the stale query')).toBeNull(); expect(screen.queryByText(PLACEHOLDER)).toBeNull(); + expect(screen.getByTestId('gantt-view').getAttribute('data-refreshing')).toBe('false'); }); it('does not strand `refreshing` when a SILENT reload is superseded by a non-silent one', async () => { const { dataSource, finds } = makeDeferredDataSource(); const { rerender } = render(); - await paintThenOverlap(dataSource, finds, rerender); + // Before the paint: the mount's load (`finds[0]`, `loading`), then an + // invalidation for the object (`finds[1]`, silent, `refreshing`), then a + // filter change (`finds[2]`, the initial load again, `loading`). + await waitFor(() => expect((dataSource.find as any).mock.calls.length).toBe(1)); + await act(async () => { + notifyDataChanged({ objectName: 'tasks' }); + }); + await waitFor(() => expect((dataSource.find as any).mock.calls.length).toBe(2)); + rerender(); + await waitFor(() => expect((dataSource.find as any).mock.calls.length).toBe(3)); expect(screen.getByText(PLACEHOLDER)).toBeTruthy(); @@ -250,13 +340,20 @@ describe('ObjectGantt — a superseded reload must not clear the loading state ( await settle(finds[1], ROWS_A); expect(screen.getByText(PLACEHOLDER)).toBeTruthy(); - // The current reload answers. Nothing is in flight any more, so BOTH flags - // must be honest — a guard that only cleared `loading` here would leave the - // refresh button spinning forever. + // The current reload answers. Nothing current is in flight any more, so + // BOTH flags must be honest — a guard that only cleared `loading` here + // would leave the refreshing state up for the life of the component. await settle(finds[2], ROWS_B); await waitFor(() => expect(screen.getByTestId('gantt-view')).toBeTruthy()); expect(screen.getByTestId('gantt-view').getAttribute('data-refreshing')).toBe('false'); + expect(refreshIndicator()).toBeNull(); expect(screen.getByText('From the fresh query')).toBeTruthy(); + + // The mount's own load, superseded twice, answering last changes nothing. + await settle(finds[0], ROWS_A); + await flush(); + expect(screen.getByText('From the fresh query')).toBeTruthy(); + expect(screen.getByTestId('gantt-view').getAttribute('data-refreshing')).toBe('false'); }); }); diff --git a/packages/plugin-gantt/src/ObjectGantt.tsx b/packages/plugin-gantt/src/ObjectGantt.tsx index 85bd313b6a..cdd9bca992 100644 --- a/packages/plugin-gantt/src/ObjectGantt.tsx +++ b/packages/plugin-gantt/src/ObjectGantt.tsx @@ -55,6 +55,7 @@ import { AlertDialogHeader, AlertDialogTitle, NavigationOverlay, + RefreshIndicator, legacyRecordDrawerWidthKey, recordOverlayWidthStorageKey, useOverlayAnchor, @@ -778,26 +779,45 @@ export const ObjectGantt: React.FC = ({ : undefined; const searchFieldsKey = searchFields ? JSON.stringify(searchFields) : ''; - // Load (and re-load) data through the resolved adapter. `silent: true` - // re-reads the source WITHOUT flipping `loading`, so GanttView stays mounted - // and keeps its scroll/collapse state — used by the write-readback below and - // the toolbar refresh button (write-readback / manual refresh, #2436 items 6 - // and 7). Concurrent - // reloads are sequenced: only the newest request may commit its result, - // so a slow earlier response can't clobber a fresher one. + // Load (and re-load) data through the resolved adapter. The two options are + // independent choices (objectui#7237): + // + // - `inPlace` decides whether the chart stays MOUNTED. In place, the run + // sets `refreshing`, which draws the refreshing state over the chart, and + // GanttView keeps its scroll, collapsed groups and in-flight edits. + // Otherwise it sets `loading`, which swaps in the placeholder. Only the + // first load does that; see `loadedOnceRef`. + // - `silent` decides what a FAILURE does. A background re-read of the SAME + // query (write-readback, the toolbar refresh, an invalidation; #2436 + // items 6 and 7) logs it and keeps the last good rows, which still + // answer that query. A silent reload is always in place. + // + // Concurrent reloads are sequenced: only the newest request may commit its + // result, so a slow earlier response can't clobber a fresher one. const [refreshing, setRefreshing] = useState(false); const reloadSeqRef = useRef(0); - const reload = useCallback(async ({ silent = false }: { silent?: boolean } = {}) => { + /** + * Has any reload committed rows yet? (objectui#7237, ruling A′) + * + * This separates the initial load, which keeps the loading placeholder, from + * every later change to the query. A later change refreshes in place, so the + * chart is never torn down to the placeholder after it has painted. A ref, not + * state: nothing renders from it, and it only ever flips once, from false to + * true. + */ + const loadedOnceRef = useRef(false); + const reload = useCallback(async ({ silent = false, inPlace = silent }: { silent?: boolean; inPlace?: boolean } = {}) => { const seq = ++reloadSeqRef.current; const isCurrent = () => reloadSeqRef.current === seq; try { - if (silent) setRefreshing(true); + if (inPlace) setRefreshing(true); else setLoading(true); // 1. Check for data prop (Unified ListView) if ((rest as any).data && Array.isArray((rest as any).data)) { if (isCurrent()) { setData((rest as any).data); setRowCeiling(null); + loadedOnceRef.current = true; } return; } @@ -887,12 +907,16 @@ export const ObjectGantt: React.FC = ({ if (isCurrent()) { setData(capped.rows); setRowCeiling(capped); + loadedOnceRef.current = true; } } catch (err) { if (silent) { // Background refresh failure keeps the last good data on screen. console.error('[ObjectGantt] Failed to refresh data:', err); } else if (isCurrent()) { + // A failed query that CHANGED (in place or not) is reported. The rows + // on screen answer the previous query, and once the refreshing state + // clears nothing would tell the user that (objectui#7237). setError(err as Error); } } finally { @@ -907,9 +931,9 @@ export const ObjectGantt: React.FC = ({ // nothing is in flight any more — a newer reload would have made this // one stale, and an older one has no claim on the flags. Clearing only // this run's own mode would strand the other one whenever the - // superseded reload ran in the OTHER mode (a silent toolbar refresh - // overtaken by a filter-change reload would leave `refreshing` on for - // the life of the component). + // superseded reload ran in the OTHER mode (a silent invalidation reload + // overtaken by a query change before the first paint would leave + // `refreshing` on for the life of the component). if (isCurrent()) { setRefreshing(false); setLoading(false); @@ -969,9 +993,21 @@ export const ObjectGantt: React.FC = ({ const reloadRef = useRef(reload); reloadRef.current = reload; + /** + * objectui#7237, ruling A′ — the first run is the initial load and keeps the + * loading placeholder. Every run after rows have painted is a REAL change to + * the query (sort, filter, permissions, search, the bound source), and it + * refreshes IN PLACE: GanttView stays mounted with its scroll, collapsed + * groups and in-flight edits, the refreshing state sits over the chart, and + * the rows are replaced when the answer lands. ⛔ Never a teardown to the + * placeholder once the chart has painted. + * + * In place but NOT silent: the query changed, so a failure is reported + * rather than leaving the previous query's rows on screen. + */ useEffect(() => { if (recordQueryDerivesExpand && !objectSchemaReady) return; - reloadRef.current(); + reloadRef.current(loadedOnceRef.current ? { inPlace: true } : {}); }, [adapterInputsKey, dataSource, apiFetch, resource, hasInlineData, dataProvider, schema.filter, schema.sort, searchTerm, searchFieldsKey, objectSchema, perms, recordQueryDerivesExpand, objectSchemaReady]); /** @@ -981,12 +1017,13 @@ export const ObjectGantt: React.FC = ({ * reports a change to the object this gantt reads. * * ⭐ A SILENT reload, deliberately not the fetch effect above. That effect's - * reload flips `loading`, which swaps `GanttView` for the placeholder — the - * same loss of scroll, collapsed groups and zoom a remount causes, one level - * down. `reload({ silent: true })` is the path the toolbar refresh and every - * write-readback here already take for exactly that reason, and it keeps - * `reload`'s sequencing, so an invalidation that lands mid-load cannot let a - * stale answer win. + * first reload flips `loading`, which swaps `GanttView` for the placeholder + * — the same loss of scroll, collapsed groups and zoom a remount causes, one + * level down — and its later ones report a failure, which is right for a + * changed query and wrong for a re-read of the same one. `reload({ silent: + * true })` is the path the toolbar refresh and every write-readback here + * already take for exactly that reason, and it keeps `reload`'s sequencing, + * so an invalidation that lands mid-load cannot let a stale answer win. * * Subscribed only when the rows come from an adapter this gantt queries * (`recordQueryDerivesExpand`): a host `data` array and an inline `value` @@ -2160,7 +2197,14 @@ export const ObjectGantt: React.FC = ({ the pane's bottom edge — swallowing the horizontal scrollbar. flex-1/min-h-0 tracks the real available height; the min-h keeps standalone embeds (no sized parent) usable. */} -
+
+ {/* objectui#7237 (ruling A′) — the visible refreshing state ON the + chart while an in-place reload runs, so the rows still on screen + read as the previous answer rather than as the current one. The + same indeterminate bar ObjectGrid, ListView and ObjectChart draw + over their rows; `refreshing` is the flag the toolbar refresh + button already reads. */} + {ganttConfig?.resourceView && assigneeAccessor ? ( = { 'gantt.row.collapse': 'Collapse', 'gantt.row.open': 'Open details', 'gantt.aria.taskList': 'Task list', + 'gantt.aria.refreshing': 'Refreshing…', 'gantt.tooltip.days': 'd', 'gantt.menu.view': 'View details', 'gantt.menu.edit': 'Edit inline',