From 34936e90dbaeac61985ba0e490642bf4045c181f Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 04:07:07 +0000 Subject: [PATCH 1/6] fix(plugin-detail): a related list that answered 0 keeps its badge through a refetch Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D --- ui/packages/plugin-detail/src/RelatedList.tsx | 12 +++- .../RelatedList.countPending-36235.test.tsx | 59 +++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/ui/packages/plugin-detail/src/RelatedList.tsx b/ui/packages/plugin-detail/src/RelatedList.tsx index b4c79e4a546..5e2eb2328c1 100644 --- a/ui/packages/plugin-detail/src/RelatedList.tsx +++ b/ui/packages/plugin-detail/src/RelatedList.tsx @@ -4028,7 +4028,17 @@ export const RelatedList: React.FC = ({ // the 0 an empty first read holds: while the first rows are in flight (or a // card out of view has not asked) and no count answers for them, the badge // waits. A refetch over rows already drawn keeps their count. - const countPending = !countAnswers && loading && relatedData.length === 0 && !(windowed && total != null); + // objectstack#36822 — and so does a refetch over a list that already + // answered 0: once a read has settled the count is known, so a later read + // in flight keeps drawing the last answer instead of blanking the badge. + // A failed or refused read answers no count, so it never marks one known. + const [countKnown, setCountKnown] = React.useState(false); + const readSettled = !loading && !loadFailure && !filterRefusal; + React.useEffect(() => { + if (readSettled) setCountKnown(true); + }, [readSettled]); + const countPending = + !countAnswers && loading && !countKnown && relatedData.length === 0 && !(windowed && total != null); // In windowed mode an empty page beyond page 0 is a transient overflow (the // step-back effect above corrects it), not an empty collection. // A failed read is never empty: it draws its own line (objectstack#26415). diff --git a/ui/packages/plugin-detail/src/__tests__/RelatedList.countPending-36235.test.tsx b/ui/packages/plugin-detail/src/__tests__/RelatedList.countPending-36235.test.tsx index cf83caffa46..72b65f2bb1a 100644 --- a/ui/packages/plugin-detail/src/__tests__/RelatedList.countPending-36235.test.tsx +++ b/ui/packages/plugin-detail/src/__tests__/RelatedList.countPending-36235.test.tsx @@ -134,3 +134,62 @@ describe('a related list\'s count before it is known (objectstack#36235)', () => await waitFor(() => expect(cardCount()).toBe('2')); }); }); + +/** + * objectstack#36822 — a refetch over a list whose count is already known keeps + * drawing that count. A list that answered 0 used to blank its badge for the + * length of the refetch, because an empty list in flight read as a first read. + */ +describe('a related list\'s count across a refetch (objectstack#36822)', () => { + /** Every badge reading the DOM goes through, from now until `stop()`. */ + function watchBadge() { + const seen: Array = [headBadge()]; + const observer = new MutationObserver(() => seen.push(headBadge())); + observer.observe(document.body, { subtree: true, childList: true, characterData: true, attributes: true }); + return { seen, stop: () => observer.disconnect() }; + } + + const refetch = () => + act(async () => { + window.dispatchEvent(new CustomEvent('objectui:related-changed', { detail: { objectName: 'contact' } })); + }); + + it('a list that answered 0 keeps drawing 0 through a refetch that answers no rows', async () => { + const read = deferredFind(); + renderList(read.find); + await waitFor(() => expect(read.find).toHaveBeenCalledTimes(1)); + await read.answer([]); + await waitFor(() => expect(headBadge()).toBe('0')); + + const watch = watchBadge(); + await refetch(); + await waitFor(() => expect(read.find).toHaveBeenCalledTimes(2)); + await flush(); + // The refetch is held in flight here: the badge still reads 0. + expect(headBadge()).toBe('0'); + await read.answer([]); + await flush(); + watch.stop(); + expect(headBadge()).toBe('0'); + expect(watch.seen.length).toBeGreaterThan(1); + expect(watch.seen.filter((v) => v !== '0')).toEqual([]); + }); + + it('a list that answered rows draws their count through a refetch, then the 0 it answers', async () => { + const read = deferredFind(); + renderList(read.find); + await waitFor(() => expect(read.find).toHaveBeenCalledTimes(1)); + await read.answer(ROWS); + await waitFor(() => expect(headBadge()).toBe('2')); + + const watch = watchBadge(); + await refetch(); + await waitFor(() => expect(read.find).toHaveBeenCalledTimes(2)); + await flush(); + expect(headBadge()).toBe('2'); + await read.answer([]); + await waitFor(() => expect(headBadge()).toBe('0')); + watch.stop(); + expect(watch.seen.filter((v) => v !== '2' && v !== '0')).toEqual([]); + }); +}); From adfe34959431666411ce5a1a54535496a6274526 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 04:14:33 +0000 Subject: [PATCH 2/6] chore(changeset): plugin-detail patch for the related list refetch badge Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D --- .changeset/36822-related-list-zero-badge-refetch.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .changeset/36822-related-list-zero-badge-refetch.md diff --git a/.changeset/36822-related-list-zero-badge-refetch.md b/.changeset/36822-related-list-zero-badge-refetch.md new file mode 100644 index 00000000000..5ea928c2dda --- /dev/null +++ b/.changeset/36822-related-list-zero-badge-refetch.md @@ -0,0 +1,10 @@ +--- +'@object-ui/plugin-detail': patch +--- + +fix(plugin-detail): a related list that already shows 0 keeps showing 0 while it reloads + +Clause-②: no +Metadata-protocol: none + +A related list on a record page whose count was known to be 0 used to drop its count badge for as long as a reload took (after a delete, a filter change or any other refetch), because an empty list being read looked like a list read for the first time. Once a read has settled, the list's count is known, so a later reload keeps drawing the last count until the new one lands. A list read for the first time still draws no count until it is known, never a false 0. From 5743d468fcad6d225e22f9b6b916c53d019b1539 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 05:34:31 +0000 Subject: [PATCH 3/6] fix(plugin-detail): count known only from an issued read; a failed read forgets it Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D --- ui/packages/plugin-detail/src/RelatedList.tsx | 23 +++--- .../RelatedList.countPending-36235.test.tsx | 71 +++++++++++++++++++ 2 files changed, 86 insertions(+), 8 deletions(-) diff --git a/ui/packages/plugin-detail/src/RelatedList.tsx b/ui/packages/plugin-detail/src/RelatedList.tsx index 5e2eb2328c1..1426a1d5492 100644 --- a/ui/packages/plugin-detail/src/RelatedList.tsx +++ b/ui/packages/plugin-detail/src/RelatedList.tsx @@ -1515,6 +1515,13 @@ export const RelatedList: React.FC = ({ // value may itself be falsy. Cleared by every re-read (the fetch effect's // first statement) and by Retry. const [loadFailure, setLoadFailure] = React.useState<{ error: unknown } | null>(null); + // objectstack#36822 — whether `relatedData` holds the answer of a read this + // list actually issued, so the badge may keep drawing its count while a + // later read is in flight. Set only where an issued read resolves, cleared + // where one rejects (the rejection empties the rows, and 0 is not their + // count). A path that reads nothing (no scope yet, a refused filter, no + // adapter) never sets it, so the first real read still draws no count. + const [countKnown, setCountKnown] = React.useState(false); // Per-lookup-field cache of resolved labels: fieldName -> Map const [lookupLabels, setLookupLabels] = React.useState>>({}); const { t } = useDetailTranslation(); @@ -2280,6 +2287,7 @@ export const RelatedList: React.FC = ({ setRelatedData(result.rows as any[]); setTotal(result.total); setHasMore(result.total > result.rows.length); + setCountKnown(true); setLoading(false); }, (err) => { @@ -2287,6 +2295,7 @@ export const RelatedList: React.FC = ({ setRelatedData([]); setTotal(null); setHasMore(false); + setCountKnown(false); setLoadFailure({ error: err }); setLoading(false); }, @@ -2380,6 +2389,7 @@ export const RelatedList: React.FC = ({ setTotal(null); setHasMore(false); } + setCountKnown(true); setLoading(false); }).catch((err) => { console.error('Failed to fetch related data:', err); @@ -2389,6 +2399,7 @@ export const RelatedList: React.FC = ({ setRelatedData([]); setTotal(null); setHasMore(false); + setCountKnown(false); setLoadFailure({ error: err }); setLoading(false); }); @@ -2451,6 +2462,7 @@ export const RelatedList: React.FC = ({ setRelatedData(items); setTotal(null); setHasMore(false); + setCountKnown(true); }) .catch(err => { console.error('Failed to fetch related data:', err); @@ -2458,6 +2470,7 @@ export const RelatedList: React.FC = ({ setRelatedData([]); setTotal(null); setHasMore(false); + setCountKnown(false); setLoadFailure({ error: err }); }) .finally(() => { if (!cancelled) setLoading(false); }); @@ -4029,14 +4042,8 @@ export const RelatedList: React.FC = ({ // card out of view has not asked) and no count answers for them, the badge // waits. A refetch over rows already drawn keeps their count. // objectstack#36822 — and so does a refetch over a list that already - // answered 0: once a read has settled the count is known, so a later read - // in flight keeps drawing the last answer instead of blanking the badge. - // A failed or refused read answers no count, so it never marks one known. - const [countKnown, setCountKnown] = React.useState(false); - const readSettled = !loading && !loadFailure && !filterRefusal; - React.useEffect(() => { - if (readSettled) setCountKnown(true); - }, [readSettled]); + // answered 0: once a read has answered, the count is known (`countKnown`), + // so a later read in flight keeps drawing the last answer. const countPending = !countAnswers && loading && !countKnown && relatedData.length === 0 && !(windowed && total != null); // In windowed mode an empty page beyond page 0 is a transient overflow (the diff --git a/ui/packages/plugin-detail/src/__tests__/RelatedList.countPending-36235.test.tsx b/ui/packages/plugin-detail/src/__tests__/RelatedList.countPending-36235.test.tsx index 72b65f2bb1a..fa4bb0c497b 100644 --- a/ui/packages/plugin-detail/src/__tests__/RelatedList.countPending-36235.test.tsx +++ b/ui/packages/plugin-detail/src/__tests__/RelatedList.countPending-36235.test.tsx @@ -192,4 +192,75 @@ describe('a related list\'s count across a refetch (objectstack#36822)', () => { watch.stop(); expect(watch.seen.filter((v) => v !== '2' && v !== '0')).toEqual([]); }); + + /** A `find` whose current read is answered or refused by hand. */ + function heldFind() { + let settle = { resolve: (_: unknown) => {}, reject: (_: unknown) => {} }; + const find = vi.fn( + () => new Promise((resolve, reject) => { + settle = { resolve, reject }; + }), + ); + return { + find, + answer: (rows: unknown[]) => act(async () => { settle.resolve({ data: rows, total: rows.length }); }), + fail: () => act(async () => { settle.reject(new Error('network down')); }), + }; + } + + it('a read that fails after rows were known draws no count while Retry reads, never a false 0', async () => { + const quiet = vi.spyOn(console, 'error').mockImplementation(() => {}); + const read = heldFind(); + renderList(read.find); + await waitFor(() => expect(read.find).toHaveBeenCalledTimes(1)); + await read.answer(ROWS); + await waitFor(() => expect(headBadge()).toBe('2')); + + await refetch(); + await waitFor(() => expect(read.find).toHaveBeenCalledTimes(2)); + await read.fail(); + const retry = await waitFor(() => { + const button = document.querySelector('[data-testid="related-list-load-failed-retry"]'); + expect(button).not.toBeNull(); + return button as HTMLElement; + }); + await act(async () => { retry.click(); }); + await waitFor(() => expect(read.find).toHaveBeenCalledTimes(3)); + await flush(); + // Retry's read is held in flight: the failed read emptied the rows, so + // their count is not known and the badge waits. + expect(document.querySelector('[data-related-list-head]')).not.toBeNull(); + expect(headBadge()).toBeNull(); + await read.answer([]); + await waitFor(() => expect(headBadge()).toBe('0')); + quiet.mockRestore(); + }); + + it('a list with no scope on its first render draws no count during its first real read', async () => { + const read = heldFind(); + const list = (parentId: string | null) => ( + + ); + // The parent is still loading: no scope, so nothing is read. + const view = render(list(null)); + await flush(); + expect(read.find).not.toHaveBeenCalled(); + // The parent lands: the first real read is held in flight. + view.rerender(list('ACC-1')); + await waitFor(() => expect(read.find).toHaveBeenCalledTimes(1)); + await flush(); + expect(document.querySelector('[data-related-list-head]')).not.toBeNull(); + expect(headBadge()).toBeNull(); + await read.answer(ROWS); + await waitFor(() => expect(headBadge()).toBe('2')); + }); }); From 8c0243b10f69bca4d9bcdcb1dd3926f5dfa7179d Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 05:44:02 +0000 Subject: [PATCH 4/6] chore(changeset): say what a failed read and a first read draw Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D --- .changeset/36822-related-list-zero-badge-refetch.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/36822-related-list-zero-badge-refetch.md b/.changeset/36822-related-list-zero-badge-refetch.md index 5ea928c2dda..df336704dd3 100644 --- a/.changeset/36822-related-list-zero-badge-refetch.md +++ b/.changeset/36822-related-list-zero-badge-refetch.md @@ -7,4 +7,4 @@ fix(plugin-detail): a related list that already shows 0 keeps showing 0 while it Clause-②: no Metadata-protocol: none -A related list on a record page whose count was known to be 0 used to drop its count badge for as long as a reload took (after a delete, a filter change or any other refetch), because an empty list being read looked like a list read for the first time. Once a read has settled, the list's count is known, so a later reload keeps drawing the last count until the new one lands. A list read for the first time still draws no count until it is known, never a false 0. +A related list on a record page whose count was known to be 0 used to drop its count badge for as long as a reload took (after a delete, a filter change or any other refetch), because an empty list being read looked like a list read for the first time. Once a read the list issued has answered, its count is known, so a later reload keeps drawing that count until the new one lands. A read that fails forgets the count, so its Retry draws no count until it answers, never a false 0. A list's first read, including one that starts only once its parent record has loaded, still draws no count while it is in flight. From 0d4e8afef0a1d632eaa3270787cb83073aca2660 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 09:29:39 +0000 Subject: [PATCH 5/6] fix(plugin-detail): rows emptied without a read forget the related list's count Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D --- ui/packages/plugin-detail/src/RelatedList.tsx | 8 ++++- .../RelatedList.countPending-36235.test.tsx | 33 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/ui/packages/plugin-detail/src/RelatedList.tsx b/ui/packages/plugin-detail/src/RelatedList.tsx index 1426a1d5492..c6a0a145161 100644 --- a/ui/packages/plugin-detail/src/RelatedList.tsx +++ b/ui/packages/plugin-detail/src/RelatedList.tsx @@ -1520,7 +1520,9 @@ export const RelatedList: React.FC = ({ // later read is in flight. Set only where an issued read resolves, cleared // where one rejects (the rejection empties the rows, and 0 is not their // count). A path that reads nothing (no scope yet, a refused filter, no - // adapter) never sets it, so the first real read still draws no count. + // adapter) never sets it, so the first real read still draws no count; one + // that empties the rows without reading (no scope, no adapter) clears it, + // so the next parent's read draws no count either. const [countKnown, setCountKnown] = React.useState(false); // Per-lookup-field cache of resolved labels: fieldName -> Map const [lookupLabels, setLookupLabels] = React.useState>>({}); @@ -2256,6 +2258,8 @@ export const RelatedList: React.FC = ({ setRelatedData([]); setTotal(null); setHasMore(false); + // Nothing is read, and the emptied rows hold no count (objectstack#36822). + setCountKnown(false); setLoading(false); return; } @@ -2417,6 +2421,7 @@ export const RelatedList: React.FC = ({ setRelatedData([]); setTotal(null); setHasMore(false); + setCountKnown(false); setLoading(false); } else if (referenceFieldIsMultiValue) { // The same refusal as the arm above, one cause earlier: this path's @@ -2443,6 +2448,7 @@ export const RelatedList: React.FC = ({ setRelatedData([]); setTotal(null); setHasMore(false); + setCountKnown(false); setLoading(false); } else { const qs = new URLSearchParams({ diff --git a/ui/packages/plugin-detail/src/__tests__/RelatedList.countPending-36235.test.tsx b/ui/packages/plugin-detail/src/__tests__/RelatedList.countPending-36235.test.tsx index fa4bb0c497b..f1575af12e1 100644 --- a/ui/packages/plugin-detail/src/__tests__/RelatedList.countPending-36235.test.tsx +++ b/ui/packages/plugin-detail/src/__tests__/RelatedList.countPending-36235.test.tsx @@ -263,4 +263,37 @@ describe('a related list\'s count across a refetch (objectstack#36822)', () => { await read.answer(ROWS); await waitFor(() => expect(headBadge()).toBe('2')); }); + + it('a list whose parent reloads through no scope draws no count during the new parent\'s read', async () => { + const read = heldFind(); + const list = (parentId: string | null) => ( + + ); + const view = render(list('ACC-1')); + await waitFor(() => expect(read.find).toHaveBeenCalledTimes(1)); + await read.answer(ROWS); + await waitFor(() => expect(headBadge()).toBe('2')); + // The parent reloads: no scope, so nothing is read and the rows empty. + view.rerender(list(null)); + await flush(); + expect(read.find).toHaveBeenCalledTimes(1); + // The new parent lands: its read is held in flight, and the emptied rows + // are no count of it. + view.rerender(list('ACC-2')); + await waitFor(() => expect(read.find).toHaveBeenCalledTimes(2)); + await flush(); + expect(document.querySelector('[data-related-list-head]')).not.toBeNull(); + expect(headBadge()).toBeNull(); + await read.answer([{ id: 'c3', name: 'Linus' }]); + await waitFor(() => expect(headBadge()).toBe('1')); + }); }); From 8bfd2f7057ccca24e4c27556cf9507cfec95cba9 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 09:39:42 +0000 Subject: [PATCH 6/6] chore(changeset): rows emptied without a read forget the count too Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D --- .changeset/36822-related-list-zero-badge-refetch.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/36822-related-list-zero-badge-refetch.md b/.changeset/36822-related-list-zero-badge-refetch.md index df336704dd3..9936b5ce674 100644 --- a/.changeset/36822-related-list-zero-badge-refetch.md +++ b/.changeset/36822-related-list-zero-badge-refetch.md @@ -7,4 +7,4 @@ fix(plugin-detail): a related list that already shows 0 keeps showing 0 while it Clause-②: no Metadata-protocol: none -A related list on a record page whose count was known to be 0 used to drop its count badge for as long as a reload took (after a delete, a filter change or any other refetch), because an empty list being read looked like a list read for the first time. Once a read the list issued has answered, its count is known, so a later reload keeps drawing that count until the new one lands. A read that fails forgets the count, so its Retry draws no count until it answers, never a false 0. A list's first read, including one that starts only once its parent record has loaded, still draws no count while it is in flight. +A related list on a record page whose count was known to be 0 used to drop its count badge for as long as a reload took (after a delete, a filter change or any other refetch), because an empty list being read looked like a list read for the first time. Once a read the list issued has answered, its count is known, so a later reload keeps drawing that count until the new one lands. A read that fails forgets the count, so its Retry draws no count until it answers, never a false 0; so do rows emptied without a read (the parent record reloading, or no data adapter), so the next parent's read draws no count either. A list's first read, including one that starts only once its parent record has loaded, still draws no count while it is in flight.