Skip to content

fix(tui): prevent multi-picker crash when options change under a held selection#979

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/fix-multipicker-stale-index-crash
Draft

fix(tui): prevent multi-picker crash when options change under a held selection#979
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/fix-multipicker-stale-index-crash

Conversation

@posthog

@posthog posthog Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Problem

MultiPickerMenu in src/ui/tui/primitives/PickerMenu.tsx tracks picked items as a Set<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 made options[i] undefined and reading .value threw TypeError: 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 useEffect only repaired focused; it never pruned the selected set, which is the root of the asymmetry.

Changes

  • Prune the selected set in the same useEffect that re-validates focused, so focus and selection stay consistent when options changes.
  • Make value resolution defensive (drop indices that no longer resolve) as a backstop for any stale index that survives to confirm().
  • Extract both operations into pure helpers (pruneSelected, selectedValues) and unit-test them.

GroupedPickerMenu keys selections by string value, not index, so it never hits this crash and is left unchanged.

Test plan

  • New unit tests in src/ui/tui/__tests__/picker-menu.test.ts cover the stale-index and disabled-option cases plus referential stability.
  • pnpm build && pnpm test — 1547 tests pass. pnpm fix clean.

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 (useInput is a no-op), so the fix's logic was extracted into pure helpers and tested directly.


Created with PostHog Desktop from this inbox report.

… 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
@github-actions

Copy link
Copy Markdown

🧙 Wizard CI

Run 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:

  • /wizard-ci all

Test all apps in a directory:

  • /wizard-ci basic-integration
  • /wizard-ci mcp-analytics
  • /wizard-ci revenue

Test an individual app:

  • /wizard-ci basic-integration/android
  • /wizard-ci basic-integration/angular
  • /wizard-ci basic-integration/astro
Show more apps
  • /wizard-ci basic-integration/django
  • /wizard-ci basic-integration/fastapi
  • /wizard-ci basic-integration/flask
  • /wizard-ci basic-integration/javascript-node
  • /wizard-ci basic-integration/javascript-web
  • /wizard-ci basic-integration/laravel
  • /wizard-ci basic-integration/next-js
  • /wizard-ci basic-integration/nuxt
  • /wizard-ci basic-integration/python
  • /wizard-ci basic-integration/rails
  • /wizard-ci basic-integration/react-native
  • /wizard-ci basic-integration/react-router
  • /wizard-ci basic-integration/sveltekit
  • /wizard-ci basic-integration/swift
  • /wizard-ci basic-integration/tanstack-router
  • /wizard-ci basic-integration/tanstack-start
  • /wizard-ci basic-integration/vue
  • /wizard-ci mcp-analytics/custom-dispatcher
  • /wizard-ci mcp-analytics/typescript-sdk
  • /wizard-ci revenue/stripe

Results will be posted here when complete.

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