Skip to content

fix(tui): guard enabledFormatters against undefined to prevent crash#22099

Closed
alankyshum wants to merge 1 commit intoanomalyco:devfrom
alankyshum:bld-4-fix-formatters-crash
Closed

fix(tui): guard enabledFormatters against undefined to prevent crash#22099
alankyshum wants to merge 1 commit intoanomalyco:devfrom
alankyshum:bld-4-fix-formatters-crash

Conversation

@alankyshum
Copy link
Copy Markdown

@alankyshum alankyshum commented Apr 12, 2026

Issue for this PR

Closes #22050
Closes #22021

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The TUI crashes with TypeError: undefined is not an object (evaluating 'enabledFormatters().length') when the enabledFormatters() SolidJS signal returns undefined instead of an array.

Root cause: In sync.tsx, the formatter status SDK call uses x.data! (non-null assertion). When x.data is undefined, reconcile(undefined) overwrites the initial [] store value with undefined. The createMemo in dialog-status.tsx then calls .filter() on undefined, and downstream .length access crashes.

Fix (two changes):

  1. Source fix (sync.tsx): Changed reconcile(x.data!) to reconcile(x.data ?? []) so the store always holds an array.
  2. Consumer guard (dialog-status.tsx): Added ?? [] fallback in the createMemo(sync.data.formatter ?? []).filter(...) — as defense-in-depth against any other path that could set formatter to undefined.

How did you verify your code works?

  • tsgo --noEmit (typecheck) passes with no errors
  • Reviewed all usages of enabledFormatters() in dialog-status.tsx — the .length and <For each={...}> accesses are now safe
  • The fix matches the existing pattern used by other fields (e.g. x.data ?? [] on line 421 for commands, x.data ?? {} on line 426/431)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Adds null-safety guard to prevent TypeError when enabledFormatters()
returns undefined before initialization. Fixes anomalyco#22050.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-Authored-By: Paperclip <noreply@paperclip.ing>
@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Apr 12, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@alankyshum
Copy link
Copy Markdown
Author

Closed by board: unauthorized self-directed work.

@alankyshum alankyshum closed this Apr 12, 2026
@Arsalankhan315
Copy link
Copy Markdown

22120

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants