Skip to content

fix: resolve RadioButtonSelect array bounds crash and auth dialog navigation#46

Merged
koalazf99 merged 1 commit into
QwenLM:mainfrom
loheagn:main
Jul 23, 2025
Merged

fix: resolve RadioButtonSelect array bounds crash and auth dialog navigation#46
koalazf99 merged 1 commit into
QwenLM:mainfrom
loheagn:main

Conversation

@loheagn

@loheagn loheagn commented Jul 23, 2025

Copy link
Copy Markdown
Contributor

Summary

  • Fixes critical crash in RadioButtonSelect component: TypeError: Cannot read properties of undefined (reading 'value')
  • Resolves Enter key not working on authentication screen
  • Adds comprehensive bounds checking to prevent array access errors

Root Cause Analysis

The bug occurred when:

  1. RadioButtonSelect received an invalid initialIndex (could be -1 from findIndex())
  2. Dynamic changes to the items array could make activeIndex out of bounds
  3. No validation existed before accessing items[activeIndex].value

Changes Made

RadioButtonSelect Component

  • Added useEffect to ensure activeIndex stays within valid bounds when items array changes
  • Added bounds checking in key handlers (up/down arrows, Enter key)
  • Added validation in useInput activation condition
  • Removed unsafe non-null assertions (\!) and replaced with proper checks

AuthDialog Component

  • Fixed initialAuthIndex calculation using Math.max(0, findIndex(...)) to prevent negative values

Test Plan

  • Build completes without errors (npm run build)
  • Linting passes (npm run lint)
  • TypeScript compilation succeeds (npm run typecheck)
  • CLI starts without crashing (npm start)
  • Authentication screen displays properly
  • Enter key works on authentication selection
  • No console errors during navigation

Impact

This fix resolves a crash that prevented users from completing authentication setup, making the CLI unusable in certain scenarios. The fix is backward compatible and doesn't change the public API.

…igation

- Add bounds checking in RadioButtonSelect to prevent accessing undefined array elements
- Add useEffect to ensure activeIndex stays within valid bounds when items array changes
- Add validation guards around navigation handlers (up/down arrow keys)
- Fix AuthDialog initialAuthIndex calculation to prevent negative values from findIndex
- Ensure Enter key works properly on authentication screen

Fixes TypeError: Cannot read properties of undefined (reading 'value') that occurred
when activeIndex was out of bounds due to dynamic array changes or invalid initialization.

Signed-off-by: loheagn <loheagn@icloud.com>
@loheagn

loheagn commented Jul 23, 2025

Copy link
Copy Markdown
Contributor Author

I try to use Claude Code to fix a bug which I found in my first usage of Qwen Code. I'm not familiar with typescript but this patch seems to fix the bug correctly.

Hope this pr helps.

@koalazf99 koalazf99 merged commit 1732467 into QwenLM:main Jul 23, 2025
ranpox pushed a commit that referenced this pull request Aug 1, 2025
npm run start -- -m model-id -d data/dir
halfaipg pushed a commit to AIPowerGrid/grid-code that referenced this pull request Aug 16, 2025
halfaipg pushed a commit to AIPowerGrid/grid-code that referenced this pull request Aug 16, 2025
…igation (QwenLM#46)

- Add bounds checking in RadioButtonSelect to prevent accessing undefined array elements
- Add useEffect to ensure activeIndex stays within valid bounds when items array changes
- Add validation guards around navigation handlers (up/down arrow keys)
- Fix AuthDialog initialAuthIndex calculation to prevent negative values from findIndex
- Ensure Enter key works properly on authentication screen

Fixes TypeError: Cannot read properties of undefined (reading 'value') that occurred
when activeIndex was out of bounds due to dynamic array changes or invalid initialization.

Signed-off-by: loheagn <loheagn@icloud.com>
Co-authored-by: linan.loheagn3 <linan.loheagn3@bytedance.com>
xaelistic pushed a commit to xaelistic/qwen-code that referenced this pull request Jun 7, 2026
…igation (QwenLM#46)

- Add bounds checking in RadioButtonSelect to prevent accessing undefined array elements
- Add useEffect to ensure activeIndex stays within valid bounds when items array changes
- Add validation guards around navigation handlers (up/down arrow keys)
- Fix AuthDialog initialAuthIndex calculation to prevent negative values from findIndex
- Ensure Enter key works properly on authentication screen

Fixes TypeError: Cannot read properties of undefined (reading 'value') that occurred
when activeIndex was out of bounds due to dynamic array changes or invalid initialization.

Signed-off-by: loheagn <loheagn@icloud.com>
Co-authored-by: linan.loheagn3 <linan.loheagn3@bytedance.com>
xaelistic pushed a commit to xaelistic/qwen-code that referenced this pull request Jun 7, 2026
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