fix(command-center): guard ActionSelector Enter against empty/stale options#3438
Draft
posthog[bot] wants to merge 1 commit into
Draft
fix(command-center): guard ActionSelector Enter against empty/stale options#3438posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
…ptions Pressing Enter on a permission prompt or mode switch could crash the whole command-center screen. selectCurrent() read allOptions[selectedIndex] and dereferenced selected.id with no bounds check, unlike its siblings selectByIndex and handleClick which already guard. When options change mid-render (a permission resolves/supersedes, a step/mode transition fires, or the clamping effect hasn't run before the keydown) selected is undefined and selected.id throws a TypeError. Because command center mounts one ActionSelector per grid cell with no per-cell error boundary, a single throw unmounts the whole router tree via the app-root boundary and shows "Something went wrong". - Add the missing `if (!selected) return;` guard to selectCurrent. - Wrap each command-center grid cell in its own ErrorBoundary so one cell's failure can no longer take down the entire screen. - Add regression tests for the empty and stale-index cases. Generated-By: PostHog Code Task-Id: 64856792-d5b4-4990-ac32-0c102f9884ec
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
|
React Doctor found no issues in the changed files. 🎉 Reviewed by React Doctor for commit |
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.
Problem
Users in command center hit a full-screen crash when pressing Enter to approve an agent permission or switch mode (accept edits / plan / default), forcing an app restart or navigating away and back.
The root cause:
selectCurrent()inuseActionSelectorState.tsreadallOptions[selectedIndex]and dereferencedselected.idwith no bounds check — unlike its siblingsselectByIndexandhandleClick, which already guard. When the options change mid-render (a permission gets resolved or superseded, a step/mode transition fires, or the clamping effect hasn't run before the keydown),selectedisundefinedandselected.idthrows aTypeError.This took down the entire screen, not just the one prompt: command center mounts one
ActionSelectorper grid cell, and there was no error boundary around individual cells — the only boundary was the app-root one, so a single throw unmounted the whole router tree and showed "Something went wrong."Why: approving agent permissions / switching mode is a core, high-frequency interaction, so a full-screen crash there is disruptive enough that recovery required restarting the app or navigating away.
Changes
if (!selected) return;guard toselectCurrent, matching the guardsselectByIndexandhandleClickalready have.ErrorBoundaryso one cell's failure can no longer take down the whole screen (resets when the cell's task/terminal changes).How did you test this?
useActionSelectorState.test.ts(3 cases) — all pass viavitest run.pnpm --filter @posthog/ui typecheck— clean.biome checkon the changed files — clean.Automatic notifications
Created with PostHog Code from an inbox report.