Skip to content

fix(web): stop throwing when right-clicking an uncached event - #2549

Merged
tyler-dane merged 1 commit into
mainfrom
posthog-self-driving/fixweb-stop-throwing-when-right-clicked-85631e
Aug 2, 2026
Merged

fix(web): stop throwing when right-clicking an uncached event#2549
tyler-dane merged 1 commit into
mainfrom
posthog-self-driving/fixweb-stop-throwing-when-right-clicked-85631e

Conversation

@posthog

@posthog posthog Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Right-clicking a grid event whose id isn't in the react-query cache threw an uncaught Error("Selected event not found") and took down the grid — an uncaught throw in a core interaction (right-click to open the event menu), not a degraded state.
  • The DOM id (data-event-id) can legitimately disagree with the cache: unsaved drafts render with draft.clientId (never cached), week transitions render from non-cache-backed placeholderData, and optimistically removed events can still be on screen for a frame.
  • This was the only one of ~14 findEventInCache call sites that threw; every other caller treats a null result as normal.
  • Fix: getDraftForEvent returns null on a miss and handleContextMenu bails out — same shape as the existing if (!draft) return guard. It also falls back to the current grid draft when the clicked id matches getGridDraftId(draft), so right-clicking an in-progress draft opens the menu instead of quietly doing nothing.

Simplicity

  • Replaces the throwing getSelectedEvent with a single getDraftForEvent helper; the call site loses its separate editGridEventDraft(...) wrapping (now folded into the helper), so handleContextMenu gets simpler, not larger.

Automated validation

  • Did not run the browser app. The symptom is an uncaught exception (not a visual/layout state); it's reproduced and pinned by a unit test that right-clicks a card whose id is absent from the cache and asserts no throw and no menu.

Independent review

  • Self-reviewed the diff. The fallback returns the store's live GridEventDraft directly (the same object startGridDraft/gridEventDraftToGridEvent already consume elsewhere), so no new shape is introduced.

Test plan

  • bun test src/components/ContextMenu/contextMenuLayering.test.tsx (3 pass, incl. the new "ignores a right-click on an event that isn't in the cache")
  • bun run type-check
  • biome check on the changed files

Created with PostHog Desktop from this inbox report.

Right-clicking a grid event whose id isn't in the react-query cache threw an
uncaught "Selected event not found" from getSelectedEvent and took down the
grid. The DOM id (data-event-id) can legitimately disagree with the cache:
unsaved drafts render with draft.clientId, week transitions render from
non-cache-backed placeholderData, and optimistically removed events can still
be on screen for a frame.

Make the miss a no-op — getDraftForEvent returns null and handleContextMenu
bails, matching every other findEventInCache caller. Also fall back to the
current grid draft when the clicked id matches getGridDraftId(draft), so
right-clicking an in-progress draft opens the menu instead of doing nothing.

Generated-By: PostHog Code
Task-Id: 9ba7ed8a-80a1-49ac-b763-82a2090da9d7
@tyler-dane
tyler-dane marked this pull request as ready for review August 2, 2026 00:51
@tyler-dane
tyler-dane merged commit 5271211 into main Aug 2, 2026
20 checks passed
@tyler-dane
tyler-dane deleted the posthog-self-driving/fixweb-stop-throwing-when-right-clicked-85631e branch August 2, 2026 00:51
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.

1 participant