fix(tui): add null guards for lsp and mcp state data#20444
fix(tui): add null guards for lsp and mcp state data#20444Echoziness wants to merge 1 commit intoanomalyco:devfrom
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
3508458 to
3d53271
Compare
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Note on the initial typecheck failureThe first typecheck run failed with The |
d6555ac to
fb4cc9a
Compare
Final Local Verification & A/B Test ResultsI have conducted a series of controlled tests on Windows 11 with
Key Findings:
All CI checks are green. Ready for review/merge. |
|
Hi @kommander and @Hona, hope you're doing well! I noticed you've both been actively reviewing TUI-related changes recently. This PR adds a few null guards to \sync.data.lsp\ and \sync.data.mcp\ in the TUI status dialog and footer to prevent a crash during service initialization. It's a small, low-risk fix (+11/-11 lines) and all CI checks are green. I know the PR queue is quite busy right now, so no rush at all—just wanted to gently bump it in case it slipped through the cracks. Thanks for all your hard work on the project! |
Prevents crash when sidebar renders LSP/MCP panels before services are initialized. sync.data.lsp and sync.data.mcp can be undefined during initial load, causing TypeError on .map() and Object.entries(). Fixes crash: 'undefined is not an object (evaluating sync8.data.lsp.map)'
fb4cc9a to
e597025
Compare
Issue for this PR
Closes #20443
Type of change
What does this PR do?
Problem: The TUI crashes when the sidebar renders the LSP/MCP status panel before the corresponding services finish initialization. During this brief window,
sync.data.lspisundefined(not yet an array) andsync.data.mcpisundefined(not yet an object), causing:Root cause: Three files access
sync.data.lspandsync.data.mcpwithout null checks, unlike other methods in the same codebase (message,permission,question,part) which already use?? []fallbacks.Files changed:
packages/opencode/src/cli/cmd/tui/plugin/api.tsx?? []tolsp()and?? {}tomcp()packages/opencode/src/cli/cmd/tui/component/dialog-status.tsxpackages/opencode/src/cli/cmd/tui/routes/session/footer.tsxWhy this fix works: The
??operator returns the right-hand side only when the left-hand side isnullorundefined. This matches the existing pattern used throughoutapi.tsxand ensures the code handles the uninitialized state gracefully without changing behavior once services are ready.How did you verify your code works?
api.tsxformessage(),permission(),question(), andpart()methods.unit (linux)andunit (windows)CI checks green).?? []and?? {}operators preserve type inference — TypeScript correctly infers the return types remainArray<{id, root, status}>and[string, MCPStatus][]respectively.sync.data.lspis already an array andsync.data.mcpis already an object, so the??fallback is never triggered. The fix only affects the uninitialized edge case.Screenshots / recordings
N/A — This is a non-visual crash fix. The change prevents a TypeError that occurs before any UI can be rendered.
Checklist