Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix(tanstack-table): reset page to 1 when change page size (#11344)

Vinicius Lourenço96ad37fea950
diff --git a/frontend/src/components/TanStackTableView/TanStackTable.tsx b/frontend/src/components/TanStackTableView/TanStackTable.tsx
index 275a5dd8e9..ec8372ad9a 100644
--- a/frontend/src/components/TanStackTableView/TanStackTable.tsx
+++ b/frontend/src/components/TanStackTableView/TanStackTable.tsx
@@ -626,6 +626,10 @@ function TanStackTableInner<TData>(
onChange={(value): void => {
setLimit(+value);
pagination.onLimitChange?.(+value);
+ if (page !== 1) {
+ setPage(1);
+ pagination.onPageChange?.(1);
+ }
}}
items={paginationPageSizeItems}
/>
diff --git a/frontend/src/components/TanStackTableView/__tests__/TanStackTableView.test.tsx b/frontend/src/components/TanStackTableView/__tests__/TanStackTableView.test.tsx
index 023d91bb93..dd500b6525 100644
--- a/frontend/src/components/TanStackTableView/__tests__/TanStackTableView.test.tsx
+++ b/frontend/src/components/TanStackTableView/__tests__/TanStackTableView.test.tsx
@@ -401,6 +401,62 @@ describe('TanStackTableView Integration', () => {
expect(onLimitChange).toHaveBeenCalledWith(20);
});
});
+
+ it('resets page to 1 when limit changes', async () => {
+ const user = userEvent.setup();
+ const onUrlUpdate = jest.fn<void, [UrlUpdateEvent]>();
+ const onPageChange = jest.fn();
+
+ renderTanStackTable({
+ props: {
+ pagination: { total: 100, defaultPage: 1, defaultLimit: 10, onPageChange },
+ enableQueryParams: true,
+ },
+ onUrlUpdate,
+ });
+
+ await waitFor(() => {
+ expect(screen.getByRole('navigation')).toBeInTheDocument();
+ });
+
+ // Navigate to page 2
+ const nav = screen.getByRole('navigation');
+ const page2 = Array.from(nav.querySelectorAll('button')).find(
+ (btn) => btn.textContent?.trim() === '2',
+ );
+ if (!page2) {
+ throw new Error('Page 2 button not found in pagination');
+ }
+ await user.click(page2);
+
+ await waitFor(() => {
+ const lastPage = onUrlUpdate.mock.calls
+ .map((call) => call[0].searchParams.get('page'))
+ .filter(Boolean)
+ .pop();
+ expect(lastPage).toBe('2');
+ });
+
+ // Change page size
+ const comboboxTrigger = document.querySelector(
+ 'button[aria-haspopup="dialog"]',
+ ) as HTMLElement;
+ await user.click(comboboxTrigger);
+
+ const option20 = await screen.findByRole('option', { name: '20' });
+ await user.click(option20);
+
+ // Verify page reset to 1 (nuqs removes default values from URL)
+ await waitFor(() => {
+ const lastCall = onUrlUpdate.mock.calls[onUrlUpdate.mock.calls.length - 1];
+ const lastPage = lastCall[0].searchParams.get('page');
+ expect(lastPage === '1' || lastPage === null).toBe(true);
+ expect(lastCall[0].searchParams.get('limit')).toBe('20');
+ });
+
+ // Verify onPageChange callback was called with 1
+ expect(onPageChange).toHaveBeenCalledWith(1);
+ });
});
describe('sorting', () => {