From 916748c2940d28df705dfdcae8ef5f9aef2b8bff Mon Sep 17 00:00:00 2001 From: rickcedwhat-ai Date: Thu, 6 Aug 2026 00:34:50 -0400 Subject: [PATCH 1/3] fix: move onReset to run after goToFirst and autoInit (#404) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit onReset previously ran before pagination reset, so DOM settle logic inside the hook fired before the table navigated back to page 1. Move it to the end of reset() so it runs after goToFirst, cache clear, and autoInit — matching user expectations. Co-Authored-By: Claude Opus 4.6 --- src/typeContext.ts | 4 ++-- src/types.ts | 4 ++-- src/useTable.ts | 3 +-- tests/edge-cases.spec.ts | 44 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/typeContext.ts b/src/typeContext.ts index 2c48185a..723e5862 100644 --- a/src/typeContext.ts +++ b/src/typeContext.ts @@ -685,7 +685,7 @@ export interface TableConfig { autoScroll?: boolean; /** Debug options for development and troubleshooting */ debug?: DebugConfig; - /** Reset hook */ + /** Hook called after reset completes (after goToFirst, cache clear, and autoInit). */ onReset?: (context: TableContext) => Promise; /** All interaction strategies */ strategies?: TableStrategies; @@ -915,7 +915,7 @@ export interface TableResult extends AsyncIterable<{ row: SmartRow; /** - * Resets the table state (clears cache, flags) and invokes the onReset strategy. + * Resets the table: navigates to page 1, clears cache, re-inits headers, then calls onReset. */ reset: () => Promise; diff --git a/src/types.ts b/src/types.ts index a158d8b8..287a52d9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -685,7 +685,7 @@ export interface TableConfig { autoScroll?: boolean; /** Debug options for development and troubleshooting */ debug?: DebugConfig; - /** Reset hook */ + /** Hook called after reset completes (after goToFirst, cache clear, and autoInit). */ onReset?: (context: TableContext) => Promise; /** All interaction strategies */ strategies?: TableStrategies; @@ -915,7 +915,7 @@ export interface TableResult extends AsyncIterable<{ row: SmartRow; /** - * Resets the table state (clears cache, flags) and invokes the onReset strategy. + * Resets the table: navigates to page 1, clears cache, re-inits headers, then calls onReset. */ reset: () => Promise; diff --git a/src/useTable.ts b/src/useTable.ts index bf619d1d..75a0c082 100644 --- a/src/useTable.ts +++ b/src/useTable.ts @@ -444,8 +444,6 @@ export const useTable = (rootLocator: Locator, configOptions: TableConf reset: async () => { log("Resetting table..."); - await config.onReset(createStrategyContext()); - if (config.strategies.pagination?.goToFirst) { log("Auto-navigating to first page..."); await config.strategies.pagination.goToFirst(createStrategyContext()); @@ -458,6 +456,7 @@ export const useTable = (rootLocator: Locator, configOptions: TableConf tableMapper.clear(); log("Table reset complete. Calling autoInit to restore state."); await _autoInit(); + await config.onReset(createStrategyContext()); }, revalidate: async () => { diff --git a/tests/edge-cases.spec.ts b/tests/edge-cases.spec.ts index 900fb989..22e4d7f8 100644 --- a/tests/edge-cases.spec.ts +++ b/tests/edge-cases.spec.ts @@ -251,6 +251,50 @@ test.describe('Edge cases and missing coverage', () => { await expect(page.locator('#page')).toHaveText('1'); }); + test('onReset runs after goToFirst and autoInit (#404)', async ({ page }) => { + await page.setContent(` + + + + + + + +
ID
1
2
+
1
+ + `); + + let pageTextDuringOnReset = ''; + const table = useTable(page.locator('#t'), { + strategies: { pagination: Strategies.Pagination.click({ next: '#next', first: '#first' }) }, + maxPages: 2, + onReset: async () => { + pageTextDuringOnReset = await page.locator('#page').textContent() ?? ''; + }, + }); + await table.init(); + await table.findRows({}); + expect(table.currentPageIndex).toBe(1); + await expect(page.locator('#page')).toHaveText('2'); + + await table.reset(); + expect(pageTextDuringOnReset).toBe('1'); + }); + test('sorting.getState throws when no sorting strategy configured', async ({ page }) => { await page.setContent(`
Name
Alice
From 535007c0c72eff05976859412ff07de7c20ed3fb Mon Sep 17 00:00:00 2001 From: rickcedwhat-ai Date: Thu, 6 Aug 2026 00:37:57 -0400 Subject: [PATCH 2/3] docs: update auto-generated API signatures for onReset Co-Authored-By: Claude Opus 4.6 --- docs/.vitepress/tableconfig-signatures.json | 2 +- docs/.vitepress/tableresult-signatures.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/.vitepress/tableconfig-signatures.json b/docs/.vitepress/tableconfig-signatures.json index 7a572dcc..7ed2ddc9 100644 --- a/docs/.vitepress/tableconfig-signatures.json +++ b/docs/.vitepress/tableconfig-signatures.json @@ -42,7 +42,7 @@ { "name": "onReset", "signature": "onReset?: (context: TableContext) => Promise", - "comment": "/** Reset hook */" + "comment": "/** Hook called after reset completes (after goToFirst, cache clear, and autoInit). */" }, { "name": "strategies", diff --git a/docs/.vitepress/tableresult-signatures.json b/docs/.vitepress/tableresult-signatures.json index 811ff814..281d7963 100644 --- a/docs/.vitepress/tableresult-signatures.json +++ b/docs/.vitepress/tableresult-signatures.json @@ -77,7 +77,7 @@ { "name": "reset", "signature": "reset: () => Promise", - "comment": "/**\n* Resets the table state (clears cache, flags) and invokes the onReset strategy.\n*/" + "comment": "/**\n* Resets the table: navigates to page 1, clears cache, re-inits headers, then calls onReset.\n*/" }, { "name": "revalidate", From cb63b9f1bed10d5c8672a4a03746a07f7567fbba Mon Sep 17 00:00:00 2001 From: rickcedwhat-ai Date: Tue, 11 Aug 2026 01:01:54 -0400 Subject: [PATCH 3/3] =?UTF-8?q?docs:=20soften=20reset()=20JSDoc=20?= =?UTF-8?q?=E2=80=94=20goToFirst=20is=20best-effort,=20not=20guaranteed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 --- docs/.vitepress/tableresult-signatures.json | 2 +- src/typeContext.ts | 2 +- src/types.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/.vitepress/tableresult-signatures.json b/docs/.vitepress/tableresult-signatures.json index 281d7963..4c6bc541 100644 --- a/docs/.vitepress/tableresult-signatures.json +++ b/docs/.vitepress/tableresult-signatures.json @@ -77,7 +77,7 @@ { "name": "reset", "signature": "reset: () => Promise", - "comment": "/**\n* Resets the table: navigates to page 1, clears cache, re-inits headers, then calls onReset.\n*/" + "comment": "/**\n* Resets the table: calls goToFirst (if configured), clears cache, re-inits headers, then calls onReset.\n*/" }, { "name": "revalidate", diff --git a/src/typeContext.ts b/src/typeContext.ts index 723e5862..3a21f32f 100644 --- a/src/typeContext.ts +++ b/src/typeContext.ts @@ -915,7 +915,7 @@ export interface TableResult extends AsyncIterable<{ row: SmartRow; /** - * Resets the table: navigates to page 1, clears cache, re-inits headers, then calls onReset. + * Resets the table: calls goToFirst (if configured), clears cache, re-inits headers, then calls onReset. */ reset: () => Promise; diff --git a/src/types.ts b/src/types.ts index 287a52d9..02627462 100644 --- a/src/types.ts +++ b/src/types.ts @@ -915,7 +915,7 @@ export interface TableResult extends AsyncIterable<{ row: SmartRow; /** - * Resets the table: navigates to page 1, clears cache, re-inits headers, then calls onReset. + * Resets the table: calls goToFirst (if configured), clears cache, re-inits headers, then calls onReset. */ reset: () => Promise;