fix(tui): prevent multi-picker crash when options change under a held selection#979
Draft
posthog[bot] wants to merge 1 commit into
Draft
fix(tui): prevent multi-picker crash when options change under a held selection#979posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
… selection MultiPickerMenu keyed selections by numeric option index. When the options list shrank or reordered while mounted, a held index could point at nothing, so confirm()'s `options[i].value` threw `TypeError: Cannot read properties of undefined (reading 'value')` — a hard crash in a core onboarding primitive. Prune the `selected` set in the same effect that already re-validates `focused`, so both stay consistent, and make value resolution defensive as a backstop. Extract the two operations into pure, unit-tested helpers. Generated-By: PostHog Code Task-Id: d4bafc2f-5521-4181-9747-aab310d6f582
🧙 Wizard CIRun the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands: Test all apps:
Test all apps in a directory:
Test an individual app:
Show more apps
Results will be posted here when complete. |
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
MultiPickerMenuinsrc/ui/tui/primitives/PickerMenu.tsxtracks picked items as aSet<number>of option indices. When the options list shrinks or reorders while the picker is mounted, a held index can point at nothing. On Confirm,confirm()did[...selected].map((i) => options[i].value), so a stale index madeoptions[i]undefinedand reading.valuethrewTypeError: Cannot read properties of undefined (reading 'value').This is a hard crash in a core onboarding primitive — it takes down the wizard mid-flow with no user workaround. The re-validation
useEffectonly repairedfocused; it never pruned theselectedset, which is the root of the asymmetry.Changes
selectedset in the sameuseEffectthat re-validatesfocused, so focus and selection stay consistent whenoptionschanges.confirm().pruneSelected,selectedValues) and unit-test them.GroupedPickerMenukeys selections by stringvalue, not index, so it never hits this crash and is left unchanged.Test plan
src/ui/tui/__tests__/picker-menu.test.tscover the stale-index and disabled-option cases plus referential stability.pnpm build && pnpm test— 1547 tests pass.pnpm fixclean.LLM context
Authored by an LLM agent (PostHog Code). The full-interactive keyboard path can't be exercised in unit tests here because the repo globally mocks
ink(useInputis a no-op), so the fix's logic was extracted into pure helpers and tested directly.Created with PostHog Desktop from this inbox report.