@@ -31,50 +31,38 @@ interface FetchNextPageResult {
3131}
3232
3333export interface UseTableReturn {
34- /** Table definition (name, schema, metadata, etc.). */
3534 tableData : TableDefinition | undefined
3635 isLoadingTable : boolean
37- /** Flattened rows across every fetched page. */
36+ /** Flattened across every fetched infinite-query page. */
3837 rows : TableRow [ ]
3938 isLoadingRows : boolean
4039 refetchRows : ( ) => void
4140 /**
42- * Fetch the next page of rows. The resolved value's `hasNextPage` reflects
43- * the post-fetch cache state — read from this rather than the parent's
44- * `hasNextPage` state, which only updates on the next React render.
41+ * The resolved value's `hasNextPage` reflects the post-fetch cache state —
42+ * read from this rather than the hook's `hasNextPage`, which only updates on
43+ * the next React render.
4544 */
4645 fetchNextPage : ( ) => Promise < FetchNextPageResult >
4746 hasNextPage : boolean
4847 isFetchingNextPage : boolean
49- /** Workspace-wide workflow metadata used by header chips and the column sidebar. */
5048 workflows : WorkflowMetadata [ ] | undefined
51- /** Stable reference to `tableData?.schema?.columns ?? []`. */
5249 columns : ColumnDefinition [ ]
53- /** Stable reference to `tableData?.schema?.workflowGroups ?? []`. */
5450 tableWorkflowGroups : WorkflowGroup [ ]
55- /** Pre-fetched live state for every unique workflow id used by the table. */
5651 workflowStates : Map < string , WorkflowState | null >
57- /** Pre-resolved icon + block-name info per output column name. Headers read
58- * from this map instead of each subscribing to its own workflow-state query. */
52+ /** Headers read from this map instead of each subscribing to its own workflow-state query. */
5953 columnSourceInfo : Map < string , ColumnSourceInfo >
6054 /**
61- * Fetches any missing row pages and returns the full flat row list directly
62- * from cache — safe to read immediately without waiting for a React re-render.
63- * Gate bulk ops that must act on the complete row set with this.
55+ * Fetches any missing pages then returns the full flat row list from cache.
56+ * Safe to read immediately — no React re-render required. Gate bulk ops that
57+ * need the complete row set behind this.
6458 */
6559 ensureAllRowsLoaded : ( ) => Promise < TableRow [ ] >
6660}
6761
6862/**
69- * Coordinator hook for the table view's data layer. Wraps row/schema/workflow
70- * fetching and exposes the derived collections every consumer needs (display
71- * columns, source-info map, workflow-name lookup). Mirrors the shape of
72- * `use-chat`'s coordinator: one hook returning a typed bundle the surface
73- * component destructures.
74- *
75- * Local interaction state (drag, resize, selection, editing) stays in the
76- * `Table` component — moving that here would push every keystroke through a
77- * single hook return and re-render the world.
63+ * Local interaction state (drag, resize, selection, editing) intentionally
64+ * stays in the `Table` component — moving it here would push every keystroke
65+ * through this hook's return value and re-render everything.
7866 */
7967export function useTable ( { workspaceId, tableId, queryOptions } : UseTableParams ) : UseTableReturn {
8068 const queryClient = useQueryClient ( )
@@ -96,10 +84,8 @@ export function useTable({ workspaceId, tableId, queryOptions }: UseTableParams)
9684 enabled : Boolean ( workspaceId && tableId ) ,
9785 } )
9886
99- // Background drain: TanStack's prefetchInfiniteQuery is a no-op when the first page is
100- // already fresh (staleTime not exceeded). Drive the drain through fetchNextPage instead
101- // — it only fetches the *next* page (not from scratch) and fires whenever a full page
102- // is sitting in cache, chaining until getNextPageParam returns undefined.
87+ // prefetchInfiniteQuery is a no-op when data is fresh (staleTime not exceeded),
88+ // so drive the drain through fetchNextPage — it appends one page at a time.
10389 useEffect ( ( ) => {
10490 if ( ! workspaceId || ! tableId || ! hasNextPage || isFetchingNextPage ) return
10591 void fetchNextPage ( )
@@ -125,14 +111,11 @@ export function useTable({ workspaceId, tableId, queryOptions }: UseTableParams)
125111 sort : queryOptions . sort ,
126112 } )
127113
128- // Drain pages one at a time using the cache as the source of truth.
129- // fetchNextPage appends exactly one new page without re-fetching existing
130- // ones. getQueryData reads the live cache synchronously — bypassing React's
131- // render cycle — so updated pages are visible immediately after each await.
114+ // getQueryData bypasses React's render cycle — pages added by fetchNextPage
115+ // are visible synchronously after each await without waiting for a re-render.
132116 while ( true ) {
133117 const data = queryClient . getQueryData ( opts . queryKey )
134118 const lastPage = data ?. pages [ data . pages . length - 1 ]
135- // A partial (or absent) last page means all available rows are in cache.
136119 if ( ! lastPage || lastPage . rows . length < TABLE_LIMITS . MAX_QUERY_LIMIT ) break
137120 const result = await fetchNextPage ( )
138121 if ( result . status === 'error' ) {
0 commit comments