From 5d0a4b8db4ac0a08dbb477dd04245687322c5ec8 Mon Sep 17 00:00:00 2001 From: Marc Bickel Date: Sun, 14 Jun 2026 06:10:24 +0200 Subject: [PATCH] fix(twenty-front): keep paging record board columns past the second page (#21348) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #21355 ## Problem On a Record Board (Kanban) view, columns that contain more than 20 records stop loading at exactly 20. The initial query loads the first page, one automatic fetch brings the column to 20, and then the loading placeholder at the bottom of the column **spins forever** — scrolling all the way down triggers no further requests. Every column is permanently capped at `2 * RECORD_BOARD_QUERY_PAGE_SIZE` (20) records. ### Steps to reproduce 1. Open any object in board view, grouped by a field where at least one group has > 20 matching records. 2. Wait for the board to load — the first 20 cards in the large column appear. 3. Scroll that column to the bottom. **Expected:** more cards load as you approach the bottom, until the column is exhausted. **Actual:** the placeholder stays forever; no additional group-by request is fired. ## Root cause An **edge-triggered consumer reading a level signal that is stuck high.** The fetch-more trigger (`RecordBoardFetchMoreInViewTriggerComponent`) is an `IntersectionObserver` sentinel that writes its `inView` state into the board-level `recordBoardShouldFetchMoreComponentState`. Its `rootMargin` is: ```ts const rootMargin = `${estimatedCardHeight * RECORD_BOARD_QUERY_PAGE_SIZE * 2}px`; ``` With `estimatedCardHeight ≈ 130px` and `RECORD_BOARD_QUERY_PAGE_SIZE = 10`, that's ~2600px — roughly two pages, i.e. as tall as the entire already-loaded board. So the sentinel reports `inView = true` across the whole loaded board, and the boolean **latches `true` after the first auto-fetch and never toggles back**. The consumer in `RecordBoardQueryEffect` only reacts to the **false→true edge** of that boolean, and `triggerRecordBoardFetchMore` is a stable `useCallback`. Once the boolean is stuck `true` and the dependency array stops changing, the effect never re-runs — so it fetches exactly once. The signal is *level* ("the bottom is in view, keep loading") but it's consumed as an *edge* ("the bottom just appeared, load once"), and the oversized `rootMargin` guarantees the level is permanently high so the single edge never repeats. The large `rootMargin` is intentional prefetch buffering and is not the bug; the consumer simply needs to keep paging while the signal is high. ## Fix Make the consumer **re-arm** the trigger after every page that actually returned records: 1. `useTriggerRecordBoardFetchMore` now returns a `boolean` — `true` only once at least one column received records this round, `false` on every early-exit / empty result. 2. `RecordBoardQueryEffect` resets `recordBoardShouldFetchMoreComponentState` to `false` after a **productive** fetch. The sentinel is still inside the inflated `rootMargin`, so the observer immediately re-asserts `true`, which re-runs the effect and fetches the next page. The loop terminates naturally and never spins: - **Buffer filled** — enough cards load that the sentinel finally leaves the `rootMargin` → observer reports `false` → loop stops. As the user scrolls, it re-arms (normal infinite scroll). - **Columns exhausted** — `triggerRecordBoardFetchMore` returns `false` (per-column `shouldFetchMore` flags already get set `false` when a page returns `< PAGE_SIZE`), so the boolean is not reset and no further fetch fires — no busy-loop on a fully-loaded board. The existing `recordBoardIsFetchingMore` re-entrancy guard prevents any overlapping/double fetch during the round-trip. ## Test - `npx nx typecheck twenty-front` → passes - `npx nx lint twenty-front` (oxlint --type-aware + oxfmt) → 0 warnings, 0 errors, formatting clean - Manually verified on a board with columns of 38 and 74 records: pre-fix both froze at 20; post-fix they page to completion on scroll, and a fully-loaded board issues no extra requests. ## Notes / alternatives considered - **Shrinking `rootMargin`** would mask the bug for tall boards but defeat the intended prefetch buffering and reintroduce it whenever the buffer is smaller than the loaded content. The level/edge mismatch is the real defect. - **Moving the loop into the trigger component** was rejected — it only knows `inView`, not whether a fetch was productive or whether columns are exhausted, so self-looping there would increase coupling. The query effect is the right owner of fetch orchestration. --------- Co-authored-by: Claude Opus 4.8 Co-authored-by: Félix Malfait Co-authored-by: Félix Malfait --- .../components/RecordBoardQueryEffect.tsx | 17 ++++++++++++- .../hooks/useTriggerRecordBoardFetchMore.ts | 6 ++--- ...dHasColumnsToFetchMoreComponentSelector.ts | 25 +++++++++++++++++++ .../opportunity-data-seeds.constant.ts | 6 +++-- 4 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 packages/twenty-front/src/modules/object-record/record-board/states/selectors/recordBoardHasColumnsToFetchMoreComponentSelector.ts diff --git a/packages/twenty-front/src/modules/object-record/record-board/components/RecordBoardQueryEffect.tsx b/packages/twenty-front/src/modules/object-record/record-board/components/RecordBoardQueryEffect.tsx index f59acbdb6c..eda346b723 100644 --- a/packages/twenty-front/src/modules/object-record/record-board/components/RecordBoardQueryEffect.tsx +++ b/packages/twenty-front/src/modules/object-record/record-board/components/RecordBoardQueryEffect.tsx @@ -3,7 +3,9 @@ import { useTriggerRecordBoardInitialQuery } from '@/object-record/record-board/ import { lastRecordBoardQueryIdentifierComponentState } from '@/object-record/record-board/states/lastRecordBoardQueryIdentifierComponentState'; import { lastRecordGroupIdsComponentState } from '@/object-record/record-board/states/lastRecordGroupIdsComponentState'; import { recordBoardCurrentGroupByQueryOffsetComponentState } from '@/object-record/record-board/states/recordBoardCurrentGroupByQueryOffsetComponentState'; +import { recordBoardIsFetchingMoreComponentState } from '@/object-record/record-board/states/recordBoardIsFetchingMoreComponentState'; import { recordBoardShouldFetchMoreComponentState } from '@/object-record/record-board/states/recordBoardShouldFetchMoreComponentState'; +import { recordBoardHasColumnsToFetchMoreComponentSelector } from '@/object-record/record-board/states/selectors/recordBoardHasColumnsToFetchMoreComponentSelector'; import { isDraggingRecordComponentState } from '@/object-record/record-drag/states/isDraggingRecordComponentState'; import { recordGroupIdsComponentState } from '@/object-record/record-group/states/recordGroupIdsComponentState'; import { useRecordIndexContextOrThrow } from '@/object-record/record-index/contexts/RecordIndexContext'; @@ -12,6 +14,7 @@ import { useRecordIndexGroupCommonQueryVariables } from '@/object-record/record- import { recordIndexRecordGroupsAreInInitialLoadingComponentState } from '@/object-record/record-index/states/recordIndexRecordGroupsAreInInitialLoadingComponentState'; import { getQueryIdentifier } from '@/object-record/utils/getQueryIdentifier'; import { useScrollWrapperHTMLElement } from '@/ui/utilities/scroll/hooks/useScrollWrapperHTMLElement'; +import { useAtomComponentSelectorValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentSelectorValue'; import { useAtomComponentState } from '@/ui/utilities/state/jotai/hooks/useAtomComponentState'; import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue'; import { useSetAtomComponentState } from '@/ui/utilities/state/jotai/hooks/useSetAtomComponentState'; @@ -59,6 +62,14 @@ export const RecordBoardQueryEffect = () => { recordBoardShouldFetchMoreComponentState, ); + const recordBoardIsFetchingMore = useAtomComponentStateValue( + recordBoardIsFetchingMoreComponentState, + ); + + const recordBoardHasColumnsToFetchMore = useAtomComponentSelectorValue( + recordBoardHasColumnsToFetchMoreComponentSelector, + ); + const { triggerRecordBoardFetchMore } = useTriggerRecordBoardFetchMore(); const { triggerRecordBoardInitialQuery } = @@ -86,7 +97,9 @@ export const RecordBoardQueryEffect = () => { } else if ( !recordIndexRecordGroupsAreInInitialLoading && recordBoardShouldFetchMore && - !queryIdentifierHasChanged + recordBoardHasColumnsToFetchMore && + !queryIdentifierHasChanged && + !recordBoardIsFetchingMore ) { triggerRecordBoardFetchMore(); } @@ -99,6 +112,8 @@ export const RecordBoardQueryEffect = () => { scrollWrapperHTMLElement, recordIndexRecordGroupsAreInInitialLoading, recordBoardShouldFetchMore, + recordBoardIsFetchingMore, + recordBoardHasColumnsToFetchMore, triggerRecordBoardFetchMore, setLastRecordGroupIds, recordGroupIds, diff --git a/packages/twenty-front/src/modules/object-record/record-board/hooks/useTriggerRecordBoardFetchMore.ts b/packages/twenty-front/src/modules/object-record/record-board/hooks/useTriggerRecordBoardFetchMore.ts index cf140b7a6f..4cbcdb0ba1 100644 --- a/packages/twenty-front/src/modules/object-record/record-board/hooks/useTriggerRecordBoardFetchMore.ts +++ b/packages/twenty-front/src/modules/object-record/record-board/hooks/useTriggerRecordBoardFetchMore.ts @@ -116,9 +116,7 @@ export const useTriggerRecordBoardFetchMore = () => { ...recordGroupOptionsFilter, }, }, - }); - - store.set(recordBoardCurrentGroupByQueryOffsetCallbackState, newOffset); + }).catch(() => null); if (!isDefined(recordIndexGroupsRecordsGroupByLazyQueryResult)) { cleanStateBeforeExit(); @@ -126,6 +124,8 @@ export const useTriggerRecordBoardFetchMore = () => { return; } + store.set(recordBoardCurrentGroupByQueryOffsetCallbackState, newOffset); + const queryFieldName = getGroupByQueryResultGqlFieldName(objectMetadataItem); diff --git a/packages/twenty-front/src/modules/object-record/record-board/states/selectors/recordBoardHasColumnsToFetchMoreComponentSelector.ts b/packages/twenty-front/src/modules/object-record/record-board/states/selectors/recordBoardHasColumnsToFetchMoreComponentSelector.ts new file mode 100644 index 0000000000..bf11a6dce4 --- /dev/null +++ b/packages/twenty-front/src/modules/object-record/record-board/states/selectors/recordBoardHasColumnsToFetchMoreComponentSelector.ts @@ -0,0 +1,25 @@ +import { RecordBoardComponentInstanceContext } from '@/object-record/record-board/states/contexts/RecordBoardComponentInstanceContext'; +import { recordBoardShouldFetchMoreInColumnComponentFamilyState } from '@/object-record/record-board/states/recordBoardShouldFetchMoreInColumnComponentFamilyState'; +import { recordGroupDefinitionsComponentSelector } from '@/object-record/record-group/states/selectors/recordGroupDefinitionsComponentSelector'; +import { createAtomComponentSelector } from '@/ui/utilities/state/jotai/utils/createAtomComponentSelector'; + +export const recordBoardHasColumnsToFetchMoreComponentSelector = + createAtomComponentSelector({ + key: 'recordBoardHasColumnsToFetchMoreComponentSelector', + componentInstanceContext: RecordBoardComponentInstanceContext, + get: + ({ instanceId }) => + ({ get }) => { + const recordGroupDefinitions = get( + recordGroupDefinitionsComponentSelector, + { instanceId }, + ); + + return recordGroupDefinitions.some((recordGroupDefinition) => + get(recordBoardShouldFetchMoreInColumnComponentFamilyState, { + instanceId, + familyKey: recordGroupDefinition.id, + }), + ); + }, + }); diff --git a/packages/twenty-server/src/engine/workspace-manager/dev-seeder/data/constants/opportunity-data-seeds.constant.ts b/packages/twenty-server/src/engine/workspace-manager/dev-seeder/data/constants/opportunity-data-seeds.constant.ts index 0ce21bb5f8..37d634d633 100644 --- a/packages/twenty-server/src/engine/workspace-manager/dev-seeder/data/constants/opportunity-data-seeds.constant.ts +++ b/packages/twenty-server/src/engine/workspace-manager/dev-seeder/data/constants/opportunity-data-seeds.constant.ts @@ -45,10 +45,12 @@ export const OPPORTUNITY_DATA_SEED_COLUMNS: (keyof OpportunityDataSeed)[] = [ 'updatedByName', ]; +const OPPORTUNITY_DATA_SEED_COUNT = 150; + const GENERATE_OPPORTUNITY_IDS = (): Record => { const OPPORTUNITY_IDS: Record = {}; - for (let INDEX = 1; INDEX <= 50; INDEX++) { + for (let INDEX = 1; INDEX <= OPPORTUNITY_DATA_SEED_COUNT; INDEX++) { const HEX_INDEX = INDEX.toString(16).padStart(4, '0'); OPPORTUNITY_IDS[`ID_${INDEX}`] = @@ -173,7 +175,7 @@ const OPPORTUNITY_TEMPLATES = [ const GENERATE_OPPORTUNITY_SEEDS = (): OpportunityDataSeed[] => { const OPPORTUNITY_SEEDS: OpportunityDataSeed[] = []; - for (let INDEX = 1; INDEX <= 50; INDEX++) { + for (let INDEX = 1; INDEX <= OPPORTUNITY_DATA_SEED_COUNT; INDEX++) { const TEMPLATE_INDEX = (INDEX - 1) % OPPORTUNITY_TEMPLATES.length; const TEMPLATE = OPPORTUNITY_TEMPLATES[TEMPLATE_INDEX];