: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(dashboards): resize drifting away from cursor on large dashboards (#68679)
Matt Puabffedb7562b8
diff --git a/frontend/src/scenes/dashboard/DashboardItems.tsx b/frontend/src/scenes/dashboard/DashboardItems.tsxindex 54e7290138b9..3de9a51e689c 100644--- a/frontend/src/scenes/dashboard/DashboardItems.tsx+++ b/frontend/src/scenes/dashboard/DashboardItems.tsx@@ -3,7 +3,7 @@ import './DashboardItems.scss'import clsx from 'clsx'import { useActions, useAsyncActions, useValues } from 'kea'import { router } from 'kea-router'-import { RefObject, useCallback, useEffect, useMemo, useRef, useState } from 'react'+import { RefObject, memo, useCallback, useEffect, useMemo, useRef, useState } from 'react'import { Layout, Responsive as ReactGridLayout, useContainerWidth } from 'react-grid-layout'import { GridBackground } from 'react-grid-layout/extras'@@ -15,6 +15,7 @@ import { EditModeEdge } from 'lib/components/Cards/InsightCard/EditModeEdgeOverlimport { LemonBanner } from 'lib/lemon-ui/LemonBanner'import { LemonMenuItem } from 'lib/lemon-ui/LemonMenu'import { DashboardEventSource, eventUsageLogic } from 'lib/utils/eventUsageLogic'+import { objectsEqual } from 'lib/utils/objects'import { addInsightToDashboardLogic } from 'scenes/dashboard/addInsightToDashboardModalLogic'import { getAddTileMenuItems } from 'scenes/dashboard/DashboardHeaderActions'import { dashboardLogic } from 'scenes/dashboard/dashboardLogic'@@ -39,6 +40,29 @@ const BASE_ROW_HEIGHT = 80const BASE_MARGIN: [number, number] = [16, 16]const CONTAINER_PADDING: [number, number] = [0, 0]+/**+ * Shallow prop compare, except: `style` by value (react-grid-layout rebuilds it every drag/resize mousemove even+ * for tiles that haven't moved) and `children` ignored (the RGL-injected resize handles, recreated each render+ * with identical content). Lets untouched tiles skip re-rendering during gestures.+ */+function gridTilePropsEqual(prevProps: Record<string, any>, nextProps: Record<string, any>): boolean {+ return [...new Set([...Object.keys(prevProps), ...Object.keys(nextProps)])].every(+ (key) =>+ key === 'children' ||+ (key === 'style'+ ? objectsEqual(prevProps.style, nextProps.style)+ : Object.is(prevProps[key], nextProps[key]))+ )+}++const MemoizedInsightCard = memo(InsightCard, gridTilePropsEqual) as typeof InsightCard+const MemoizedDashboardTextItem = memo(DashboardTextItem, gridTilePropsEqual) as typeof DashboardTextItem+const MemoizedDashboardButtonTileItem = memo(+ DashboardButtonTileItem,+ gridTilePropsEqual+) as typeof DashboardButtonTileItem+const MemoizedDashboardWidgetItem = memo(DashboardWidgetItem, gridTilePropsEqual) as typeof DashboardWidgetItem+export function DashboardItems(): JSX.Element {const {dashboard,@@ -507,7 +531,7 @@ export function DashboardItems(): JSX.Element {const loading = isErrorTile ? false : isRefreshing(insight.short_id)return (- <InsightCard+ <MemoizedInsightCardkey={tile.id}tile={tile}insight={insight}@@ -540,7 +564,7 @@ export function DashboardItems(): JSX.Element {if (text) {return (- <DashboardTextItem+ <MemoizedDashboardTextItemkey={tile.id}tile={tile}placement={placement}@@ -565,7 +589,7 @@ export function DashboardItems(): JSX.Element {if (button_tile) {return (- <DashboardButtonTileItem+ <MemoizedDashboardButtonTileItemkey={tile.id}tile={tile}placement={placement}@@ -593,7 +617,7 @@ export function DashboardItems(): JSX.Element {const refreshState = widgetRefreshStatus[tile.id]return (- <DashboardWidgetItem+ <MemoizedDashboardWidgetItemkey={tile.id}tile={tile}placement={placement}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex f3681715cc63..4118d17fed44 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -20112,8 +20112,8 @@ packages:react: 18.3.1react-dom: 18.3.1- resolution: {integrity: sha512-liJBNayhX7qA4tBJiBD321FDhJxgGTJ07uzH5zSORXoE8h7PyEZ8mLqmosST7ppf6C4zUsbd2gzDMmBCfFp9Lw==}+ resolution: {integrity: sha512-3NKQ0SLZV7rs3LQHeXlOzDSRQfFrkX6TVet77/Qk03zqiZyee37b7N8/gwDJAA8UUjRz7PdWCCy49hcso45SMQ==}peerDependencies:react: 18.3.1react-dom: 18.3.1@@ -42840,7 +42840,7 @@ snapshots:react: 18.3.1react-dom: 18.3.1([email protected])resize-observer-polyfill: 1.5.1@@ -42918,7 +42918,7 @@ snapshots:react: 18.3.1react-dom: 18.3.1([email protected])dependencies:prop-types: 15.8.1react: 18.3.1