fix(web): fail soft when grid element is absent on event mousedown#2196
Draft
posthog[bot] wants to merge 1 commit into
Draft
fix(web): fail soft when grid element is absent on event mousedown#2196posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
getElemByIdingrid.util.tsunconditionally throws whendocument.getElementById(...)returns null or a non-div element. It's called on every timed/all-day event mousedown viauseGridEventMouseDown.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:
maybeGetElemByIdvariant that returnsnullwhen the element is absent or not anHTMLDivElement.onMouseDownto 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
getElemByIdis 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 failCreated with PostHog Code from this inbox report.