Skip to content

fix(dashboards): Clamp invalid widget layouts to prevent browser crash#109825

Merged
gggritso merged 1 commit intomasterfrom
georgegritsouk/dain-1265-add-frontend-clamping-and-sentry-logging-for-invalid-widget
Mar 4, 2026
Merged

fix(dashboards): Clamp invalid widget layouts to prevent browser crash#109825
gggritso merged 1 commit intomasterfrom
georgegritsouk/dain-1265-add-frontend-clamping-and-sentry-logging-for-invalid-widget

Conversation

@gggritso
Copy link
Member

@gggritso gggritso commented Mar 3, 2026

Add frontend clamping for widget layout dimensions that exceed the 6-column grid bounds.

Widgets created via external tools (e.g. LLMs) can have dimensions like w: 12 where the maximum is 6. This causes an infinite re-render loop in react-grid-layout when entering edit mode, crashing the browser. The new clampWidgetLayout() function normalizes dimensions before they reach the grid library, and logs invalid layouts to Sentry for observability.

Backend validation counterpart: #109826

Refs DAIN-1265

@linear
Copy link

linear bot commented Mar 3, 2026

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Mar 3, 2026
@gggritso gggritso marked this pull request as ready for review March 3, 2026 21:06
@gggritso gggritso requested a review from a team as a code owner March 3, 2026 21:06
Copy link
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Sentry side effect in pure function fires every render
    • Removed the Sentry.captureMessage call from clampWidgetLayout so render-path layout clamping is now pure and no longer emits repeated events on re-renders.

Create PR

Or push these changes by commenting:

@cursor push f0f519073e
Preview (f0f519073e)
diff --git a/static/app/views/dashboards/clampWidgetLayout.tsx b/static/app/views/dashboards/clampWidgetLayout.tsx
--- a/static/app/views/dashboards/clampWidgetLayout.tsx
+++ b/static/app/views/dashboards/clampWidgetLayout.tsx
@@ -1,5 +1,3 @@
-import * as Sentry from '@sentry/react';
-
 import {NUM_DESKTOP_COLS} from 'sentry/views/dashboards/constants';
 
 import type {WidgetLayout} from './types';
@@ -14,14 +12,5 @@
   const x = Math.max(0, Math.min(layout.x, NUM_DESKTOP_COLS - 1));
   const clampedW = Math.min(w, NUM_DESKTOP_COLS - x);
 
-  if (layout.w !== clampedW || layout.x !== x) {
-    Sentry.captureMessage('Invalid widget layout dimensions detected', {
-      extra: {
-        original: {x: layout.x, y: layout.y, w: layout.w, h: layout.h},
-        clamped: {x, w: clampedW},
-      },
-    });
-  }
-
   return {...layout, w: clampedW, x};
 }
This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

@gggritso gggritso force-pushed the georgegritsouk/dain-1265-add-frontend-clamping-and-sentry-logging-for-invalid-widget branch from cbd75d9 to af579ea Compare March 3, 2026 22:32
Copy link
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

…owser crash

Widgets created via external tools (e.g. LLMs) can have dimensions
exceeding the 6-column grid maximum (e.g. w:12). This causes an
infinite re-render loop in react-grid-layout when entering edit mode,
leading to 100% CPU usage and browser crash.

Add clampWidgetLayout() that normalizes oversized layouts before they
reach react-grid-layout, applied in getDashboardLayout() and
assignDefaultLayout(). Invalid layouts are logged to Sentry via
captureMessage for observability.

Refs DAIN-1265
Co-Authored-By: Claude <noreply@anthropic.com>
@gggritso gggritso force-pushed the georgegritsouk/dain-1265-add-frontend-clamping-and-sentry-logging-for-invalid-widget branch from af579ea to e628a57 Compare March 3, 2026 22:45
gggritso added a commit that referenced this pull request Mar 4, 2026
…109826)

Replace the custom `LayoutField` with a `LayoutSerializer` using DRF's
built-in `IntegerField` validators to reject invalid widget dimensions
at the API level.

Widgets created via external tools (e.g. LLMs) can have invalid
dimensions like `w: 12` where the grid maximum is `6`. This change
prevents such layouts from being persisted. The `LayoutSerializer` also
lets drf-spectacular auto-generate accurate OpenAPI documentation with
field types and constraints, removing the need for manual
`@extend_schema_field` annotations.

Frontend clamping counterpart:
#109825

Refs DAIN-1266

Co-authored-by: Claude <noreply@anthropic.com>
Copy link
Member

@nikkikapadia nikkikapadia left a comment

Choose a reason for hiding this comment

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

lgtm just have a clarifying question

@gggritso gggritso merged commit 14fab61 into master Mar 4, 2026
60 checks passed
@gggritso gggritso deleted the georgegritsouk/dain-1265-add-frontend-clamping-and-sentry-logging-for-invalid-widget branch March 4, 2026 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants