Skip to content

fix(web): fail soft when grid element is absent on event mousedown#2196

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/fix-grid-mousedown-missing-element
Draft

fix(web): fail soft when grid element is absent on event mousedown#2196
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/fix-grid-mousedown-missing-element

Conversation

@posthog

@posthog posthog Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Summary

getElemById in grid.util.ts unconditionally throws when document.getElementById(...) returns null or a non-div element. It's called on every timed/all-day event mousedown via useGridEventMouseDown.onMouseDown, with no guard. When the target grid element (#mainGrid) is briefly missing during a render / view-transition race, a normal click/drag became an uncaught exception that bubbled through React's event dispatch.

This makes that path fail soft:

  • Adds a non-throwing maybeGetElemById variant that returns null when the element is absent or not an HTMLDivElement.
  • Guards onMouseDown to bail out early (skipping listener setup and drag init) when the grid element isn't present, so a missing grid is a harmless no-op instead of a crash.

The throwing getElemById is left in place for the other callers that legitimately expect the element to exist.

Simplicity

Minimal, contained change to the two files on the reported path. No behavior change when the grid is mounted; the only new branch is the early return when it's absent.

Automated validation

Added unit tests for maybeGetElemById (present div → element, absent → null, wrong element type → null). Full grid util suite passes (18/18).

Independent review

n/a — small, self-contained fix.

Test plan

  • bun test src/common/utils/grid/grid.util.test.ts (packages/web) → 18 pass, 0 fail

Created with PostHog Code from this inbox report.

getElemById unconditionally throws when the target element is missing or
not a div. On the event mousedown path (useGridEventMouseDown.onMouseDown),
a brief render/view-transition race where #mainGrid is absent turned a
normal click/drag into an uncaught exception.

Add a non-throwing maybeGetElemById variant that returns null, and guard
onMouseDown to bail out (skipping listener setup and drag init) when the
grid element isn't present, making a missing grid a harmless no-op.

Generated-By: PostHog Code
Task-Id: f8156baa-42bb-4a0b-a545-c03d80798911
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants