Skip to content

Conversation

@pyramation
Copy link
Contributor

fix(inquirerer): handle empty filteredOptions in checkbox and autocomplete

Summary

Fixes a crash when filtering options in checkbox/autocomplete prompts results in zero matches and the user presses arrow keys or space.

The bug: When typing a filter like "ve" that matches no options, pressing UP arrow would set selectedIndex = filteredOptions.length - 1 = -1, causing Cannot read properties of undefined (reading 'name') when accessing filteredOptions[selectedIndex].

The fix:

  • Added guards in UP_ARROW, DOWN_ARROW, and SPACE handlers to no-op when filteredOptions is empty
  • Updated updateFilteredOptions() in checkbox to clamp indices when filtered results change (matching autocomplete's existing behavior)
  • Applied same guards to autocomplete function for consistency

Review & Testing Checklist for Human

  • Test the exact repro case: Run pgpm init, get to the extensions checkbox, type "ve" (or any filter with no matches), then press UP/DOWN arrows - should no longer crash
  • Verify the UX when no options match - should display empty list without crashing
  • Check that normal filtering + navigation still works correctly when there ARE matching options

Notes

…plete

When filtering options results in zero matches, pressing arrow keys or
space would crash with 'Cannot read properties of undefined'. This fix:

- Adds guards in UP_ARROW, DOWN_ARROW, and SPACE handlers to no-op when
  filteredOptions is empty
- Updates updateFilteredOptions() in checkbox to clamp selectedIndex and
  startIndex when filtered results change (matching autocomplete behavior)
- Prevents division by zero in DOWN_ARROW modulo operation
- Prevents accessing undefined array elements
@devin-ai-integration
Copy link

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@pyramation pyramation merged commit 86d569a into main Dec 27, 2025
36 checks passed
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.

2 participants