Skip to content
Merged
8 changes: 8 additions & 0 deletions .changeset/table-infinite-loading.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@astryxdesign/core': patch
'@astryxdesign/cli': patch
---

[feature] Add Table infinite loading with `useTableInfiniteScroll({hasMore, isLoading, onLoadMore})`. One Promise request latch coordinates automatic and manual loading, failures pause automatic retry, and the persistent busy Button owns progress announcements and focus continuity.

@humbertovirtudes @cixzhang
1 change: 1 addition & 0 deletions apps/sandbox/scripts/next-export-routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@
"/templates/IconShowcase/",
"/templates/IconSizes/",
"/templates/IconStatusIcons/",
"/templates/InfiniteScrollHookUsage/",
"/templates/InfoTipMetricDefinitions/",
"/templates/InfoTipPermissionNotes/",
"/templates/InfoTipShowcase/",
Expand Down
38 changes: 38 additions & 0 deletions apps/storybook/stories/TableInfiniteScroll.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.
import {useState} from 'react';
import type {Meta, StoryObj} from '@storybook/react-vite';
import {Table, useTableInfiniteScroll} from '@astryxdesign/core';
const rows = Array.from({length: 20}, (_, index) => ({
id: String(index),
name: `Product ${index + 1}`,
}));
const meta: Meta = {
title: 'Core/Table infinite loading',
component: Table,
};
export default meta;
function Example() {
const [data, setData] = useState(rows.slice(0, 4));
const [isLoading, setIsLoading] = useState(false);
const loading = useTableInfiniteScroll({
hasMore: data.length < 20,
isLoading,
onLoadMore: async () => {
setIsLoading(true);
await new Promise(resolve => setTimeout(resolve, 400));
setData(previous => rows.slice(0, previous.length + 4));
setIsLoading(false);
},
});
return (
<Table
data={data}
columns={[{key: 'name', header: 'Product'}]}
idKey="id"
plugins={{loading}}
/>
);
}
export const ManualAndAutomaticLoading: StoryObj = {
render: () => <Example />,
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ review_triggers:
verified_by:
[
packages/core/src/Table/plugins/infiniteScroll/useTableInfiniteScroll.test.tsx,
packages/core/src/Table/__tests__/TableInfiniteScroll.a11y.chromium.spec.ts,
packages/core/src/Table/Table.perf.test.tsx,
packages/core/src/Table/plugins/infiniteScroll/TableInfiniteScrollWide.a11y.chromium.spec.ts,
packages/core/src/Table/TablePluginLoading.test.tsx,
packages/core/src/Table/TableIncrementalCount.test.tsx,
packages/core/src/Table/TableLoadingViewport.test.tsx,
scripts/check-knowledge.mjs,
]
parent_component: component:Table
Expand Down Expand Up @@ -186,16 +188,16 @@ Required implementation checks remain pending; recommended spoken-timing follow-
is identified separately and is not a second announcement owner or release gate.
Frontmatter paths are verification targets, not assertions that files exist or pass.

| Contract | Verification | Representative states | Mutation or failure expectation |
| ----------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------- |
| FR1, FR3-FR7, FR14, ORD1-ORD5 | Pending deterministic observer/manual events and controlled-commit tests in the module unit suite. | Reentry; Promise pending/fulfilled/rejected with controlled true/false; synchronous fulfillment without a true phase; invalid non-Promise result and operable manual recovery; visible short batches; callback replacement; hook-owning reset versus child-only remount. | Overlap, stale-false rearm, same-stack recursion, immediate failure loop, dead-ended short batches, or prior-generation request/paint fails. |
| FR2, FR8-FR10, FR12-FR13, ORD6-ORD7 | Pending render/composition tests through the parent mode/render plan. | Data/children/unknown context; flat/non-flat/custom; empty initial loading; chrome/refs; caller errors. | Invalid DOM, children sentinel, repeated warning, replaced chrome, contradictory empty/progress, or duplicated error UI fails. |
| FR11, PR1-PR5 | Pending lifecycle and geometry tests under StrictMode. | Parent block root/viewport fallback/nested ancestor clipping; root/node replacement; ready/loading/exhausted/false-to-true; absent IO; unmount. | Ancestor discovery, leaked/multiple observers, stale entries, callback churn, or new-generation effects fails. |
| AR1, AR3-AR7 | Pending `TableInfiniteScroll.a11y.chromium.spec.ts`, DOM/tree, axe, browser keyboard/touch/zoom/motion/focus flows. | Ready/busy/manual/unsupported IO, append, focused and unrelated-focus exhaustion, fitting Scroll region. | Native disabling loses focus, busy requests fire, missing manual command, false row semantics, or focus handoff scroll/steal fails. |
| AR2 | Pending DOM/accessibility-tree and transition-count checks of the single Button region and silent Spinner; spoken timing is recommended follow-up. | Initial load, latch/controlled updates, repeated entries, short batches, completion/failure/exhaustion, replay, reset. | Duplicate/skipped/out-of-order or stale-generation progress, prefilled regions, and churn announcements fail. |
| Public API and docs | Pending compile fixture, inventory, `.doc.mjs`, Storybook, and generic async recipe. | Three fields; Promise completion and invalid void-result diagnostics/recovery; owning-hook React key reset; manual fallback. | Client/root/reset/look-ahead/renderer API leaks, wrong reset owner, or undocumented completion obligations fails. |
| Performance | Pending extensions to `Table.perf.test.tsx` for stable identities, callback work, and repeated appends. | No-op rerender, many batches, flat load/window composition. | Resource churn, row scans, or recorded budget regressions fails. |
| Structural ownership | `pnpm check:knowledge` structural check; implementation evidence is separate. | Current module/backlink, schema 3/template 4. | Missing, duplicate, wrong-kind, misnamed, or orphaned records must fail. |
| Contract | Verification | Representative states | Mutation or failure expectation |
| ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------- |
| FR1, FR3-FR7, FR14, ORD1-ORD5 | Pending deterministic observer/manual events and controlled-commit tests in the module unit suite. | Reentry; Promise pending/fulfilled/rejected with controlled true/false; synchronous fulfillment without a true phase; invalid non-Promise result and operable manual recovery; visible short batches; callback replacement; hook-owning reset versus child-only remount. | Overlap, stale-false rearm, same-stack recursion, immediate failure loop, dead-ended short batches, or prior-generation request/paint fails. |
| FR2, FR8-FR10, FR12-FR13, ORD6-ORD7 | Pending render/composition tests through the parent mode/render plan. | Data/children/unknown context; flat/non-flat/custom; empty initial loading; chrome/refs; caller errors. | Invalid DOM, children sentinel, repeated warning, replaced chrome, contradictory empty/progress, or duplicated error UI fails. |
| FR11, PR1-PR5 | Pending lifecycle and geometry tests under StrictMode. | Parent block root/viewport fallback/nested ancestor clipping; root/node replacement; ready/loading/exhausted/false-to-true; absent IO; unmount. | Ancestor discovery, leaked/multiple observers, stale entries, callback churn, or new-generation effects fails. |
| AR1, AR3-AR7 | `TableInfiniteScrollWide.a11y.chromium.spec.ts` checks that loading keeps a wide table's intrinsic width in LTR and RTL. Pending: DOM/tree, axe, browser keyboard/touch/zoom/motion/focus flows. | Ready/busy/manual/unsupported IO, append, focused and unrelated-focus exhaustion, fitting Scroll region. | Native disabling loses focus, busy requests fire, missing manual command, false row semantics, or focus handoff scroll/steal fails. |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: "Pending:" is temporary status; keep the checks this row requires without it. Also, verified_by (lines 14-24) drops Table.perf.test.tsx, which exists, while the Performance row (line 199) still names it: keep the path or update the row.

| AR2 | Pending DOM/accessibility-tree and transition-count checks of the single Button region and silent Spinner; spoken timing is recommended follow-up. | Initial load, latch/controlled updates, repeated entries, short batches, completion/failure/exhaustion, replay, reset. | Duplicate/skipped/out-of-order or stale-generation progress, prefilled regions, and churn announcements fail. |
| Public API and docs | Pending compile fixture, inventory, `.doc.mjs`, Storybook, and generic async recipe. | Three fields; Promise completion and invalid void-result diagnostics/recovery; owning-hook React key reset; manual fallback. | Client/root/reset/look-ahead/renderer API leaks, wrong reset owner, or undocumented completion obligations fails. |
| Performance | Pending extensions to `Table.perf.test.tsx` for stable identities, callback work, and repeated appends. | No-op rerender, many batches, flat load/window composition. | Resource churn, row scans, or recorded budget regressions fails. |
| Structural ownership | `pnpm check:knowledge` structural check; implementation evidence is separate. | Current module/backlink, schema 3/template 4. | Missing, duplicate, wrong-kind, misnamed, or orphaned records must fail. |

## Decision log

Expand Down
10 changes: 10 additions & 0 deletions internal/shadcn-registry/routes.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -3971,6 +3971,11 @@
"path": "examples/use-table-grouped-rows/collapsible-groups",
"aliases": []
},
{
"name": "example-use-table-infinite-scroll-load-more-products",
"path": "examples/use-table-infinite-scroll/load-more-products",
"aliases": []
},
{
"name": "example-use-table-row-expansion-tree-table",
"path": "examples/use-table-row-expansion/tree-table",
Expand Down Expand Up @@ -4396,6 +4401,11 @@
"path": "hooks/use-table-grouped-rows",
"aliases": []
},
{
"name": "hook-use-table-infinite-scroll",
"path": "hooks/use-table-infinite-scroll",
"aliases": []
},
{
"name": "hook-use-table-pagination",
"path": "hooks/use-table-pagination",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.

/** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
export const doc = {
type: 'block',
exampleFor: 'useTableInfiniteScroll',
name: 'useTableInfiniteScroll - Load More Products',
displayName: 'useTableInfiniteScroll - Load More Products',
description:
'A Table appends product batches automatically or through its Load more command. The caller owns the rows, loading state and Promise-returning request. The command disappears when all products are loaded.',
isReady: true,
aspectRatio: 16 / 9,
componentsUsed: ['Table'],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.

'use client';

import {useState} from 'react';
import {Table, useTableInfiniteScroll} from '@astryxdesign/core/Table';

const products = Array.from({length: 20}, (_, index) => ({
id: `product-${index}`,
name: `Product ${index + 1}`,
}));
const columns = [{key: 'name', header: 'Product'}];

export default function InfiniteScrollHookUsage() {
const [data, setData] = useState(products.slice(0, 4));
const [isLoading, setIsLoading] = useState(false);
const loading = useTableInfiniteScroll({
hasMore: data.length < products.length,
isLoading,
onLoadMore: async () => {
setIsLoading(true);
try {
const nextBatch = await Promise.resolve(
products.slice(data.length, data.length + 4),
);
setData(previous => [...previous, ...nextBatch]);
} finally {
setIsLoading(false);
}
},
});
return <Table data={data} columns={columns} idKey="id" plugins={{loading}} />;
}
4 changes: 4 additions & 0 deletions packages/core/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,10 @@
"defaultMessage": "Table",
"description": "Fallback screen-reader-only accessible name for a data-table region when the consumer provides none. Noun (\"a table\"), not the verb \"to table\"."
},
"@astryx.table.loadMore": {
"defaultMessage": "Load more",
"description": "Button that requests another batch of table rows. Verb phrase; shown while additional rows are available."
},
"@astryx.table.noData": {
"defaultMessage": "No data",
"description": "Fallback empty-state text in the table body when there are zero rows. Neutral tone (not error-y); consumers commonly override with something specific like \"No results\"."
Expand Down
Loading
Loading