Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(data-warehouse): stop sources pagination refetch and scroll jump (#74999)

Thiago Salvatore256a38da02a0
diff --git a/frontend/src/lib/lemon-ui/LemonTable/LemonTable.tsx b/frontend/src/lib/lemon-ui/LemonTable/LemonTable.tsx
index a4c18e3a189f..94da99b4ed79 100644
--- a/frontend/src/lib/lemon-ui/LemonTable/LemonTable.tsx
+++ b/frontend/src/lib/lemon-ui/LemonTable/LemonTable.tsx
@@ -59,6 +59,11 @@ export interface LemonTableProps<T extends Record<string, any>, K extends BulkSe
/** Whether the table is still interactable while `loading` is `true`. Defaults to `true`. **/
disableTableWhileLoading?: boolean
pagination?: PaginationAuto | PaginationManual
+ /**
+ * Whether changing the page scrolls the table back into view. Defaults to `true`.
+ * Set to `false` for tables high up on a page where paging shouldn't move the viewport.
+ */
+ scrollToTopOnPageChange?: boolean
expandable?: ExpandableConfig<T>
/** Whether the header should be shown. The default value is `true`. */
showHeader?: boolean
@@ -129,6 +134,7 @@ export function LemonTable<T extends Record<string, any>, K extends BulkSelectio
loading,
disableTableWhileLoading = true,
pagination,
+ scrollToTopOnPageChange = true,
expandable,
showHeader = true,
uppercaseHeader = true,
@@ -336,6 +342,10 @@ export function LemonTable<T extends Record<string, any>, K extends BulkSelectio
}
previousPageRef.current = paginationState.currentPage
+ if (!scrollToTopOnPageChange) {
+ return
+ }
+
// When the current page changes, scroll back to the top of the table
if (scrollRef.current) {
const realTableOffsetTop = scrollRef.current.getBoundingClientRect().top - 320 // Extra breathing room
@@ -349,7 +359,7 @@ export function LemonTable<T extends Record<string, any>, K extends BulkSelectio
}
}
}
- }, [paginationState.currentPage])
+ }, [paginationState.currentPage, scrollToTopOnPageChange])
if (firstColumnSticky && expandable) {
// Due to CSS, for firstColumnSticky to work the first column needs to be a content column
diff --git a/products/data_warehouse/frontend/shared/components/DirectConnectSourcesTable.tsx b/products/data_warehouse/frontend/shared/components/DirectConnectSourcesTable.tsx
index 90871562120f..21eef74ae00b 100644
--- a/products/data_warehouse/frontend/shared/components/DirectConnectSourcesTable.tsx
+++ b/products/data_warehouse/frontend/shared/components/DirectConnectSourcesTable.tsx
@@ -28,6 +28,7 @@ export function DirectConnectSourcesTable(): JSX.Element {
dataSource={filteredDirectSources}
loading={dataWarehouseSourcesLoading}
pagination={{ pageSize: 10 }}
+ scrollToTopOnPageChange={false}
columns={[
{
width: 0,
diff --git a/products/data_warehouse/frontend/shared/components/ManagedSourcesTable.tsx b/products/data_warehouse/frontend/shared/components/ManagedSourcesTable.tsx
index aeb54d2e5222..ae1c33c3c421 100644
--- a/products/data_warehouse/frontend/shared/components/ManagedSourcesTable.tsx
+++ b/products/data_warehouse/frontend/shared/components/ManagedSourcesTable.tsx
@@ -69,6 +69,7 @@ export function ManagedSourcesTable(): JSX.Element {
loading={dataWarehouseSourcesLoading}
disableTableWhileLoading={false}
pagination={{ pageSize: 10 }}
+ scrollToTopOnPageChange={false}
emptyState={
<div className="flex flex-col items-center gap-2 py-2">
<span>{managedSearchTerm ? 'No sources matching your search' : 'No managed sources'}</span>
diff --git a/products/data_warehouse/frontend/shared/components/SelfManagedSourcesTable.tsx b/products/data_warehouse/frontend/shared/components/SelfManagedSourcesTable.tsx
index 96b8e01c368f..fb146879ae69 100644
--- a/products/data_warehouse/frontend/shared/components/SelfManagedSourcesTable.tsx
+++ b/products/data_warehouse/frontend/shared/components/SelfManagedSourcesTable.tsx
@@ -22,6 +22,7 @@ export function SelfManagedSourcesTable(): JSX.Element {
dataSource={filteredSelfManagedTables}
loading={databaseLoading}
pagination={{ pageSize: 10 }}
+ scrollToTopOnPageChange={false}
columns={[
{
width: 0,
diff --git a/products/data_warehouse/frontend/shared/logics/sourceManagementLogic.ts b/products/data_warehouse/frontend/shared/logics/sourceManagementLogic.ts
index 50aa887a0794..a7f927a16ad0 100644
--- a/products/data_warehouse/frontend/shared/logics/sourceManagementLogic.ts
+++ b/products/data_warehouse/frontend/shared/logics/sourceManagementLogic.ts
@@ -427,9 +427,23 @@ export const sourceManagementLogic = kea<sourceManagementLogicType>([
],
}),
urlToAction(({ actions }) => {
- const reload = (): void => actions.loadSources()
// Reload (and restart polling) when landing on a page that renders the sources list, in
// case this shared logic was already mounted by another scene and afterMount won't re-run.
+ // Skip same-path URL changes — the sources tables sync their pagination to the URL (e.g.
+ // ?managed-sources_page=2), and a full refetch on every page click would blink the table
+ // and shift the page.
+ const reload = (
+ _params: Record<string, string | undefined>,
+ _searchParams: Record<string, any>,
+ _hashParams: Record<string, any>,
+ currentLocation: { pathname: string; initial?: boolean },
+ previousLocation?: { pathname: string }
+ ): void => {
+ if (!currentLocation.initial && currentLocation.pathname === previousLocation?.pathname) {
+ return
+ }
+ actions.loadSources()
+ }
return Object.fromEntries(SOURCE_LIST_PATHS.map((sourcePath) => [sourcePath, reload]))
}),
listeners(({ actions, values, cache }) => ({