Skip to content

Crash: sync.data.lsp is undefined when sidebar renders LSP panel #20443

@Echoziness

Description

@Echoziness

Bug Description

Opening the sidebar with the LSP panel crashes the TUI with:

TypeError: undefined is not an object (evaluating 'sync8.data.lsp.map')

Root Cause

In packages/opencode/src/cli/cmd/tui/plugin/api.tsx:186:

lsp() {
  return sync.data.lsp.map((item) => ({ id: item.id, root: item.root, status: item.status }))
}

Unlike other methods in the same file that use ?? [] for fallback:

message(sessionID) { return sync.data.message[sessionID] ?? [] }
permission(sessionID) { return sync.data.permission[sessionID] ?? [] }
question(sessionID) { return sync.data.question[sessionID] ?? [] }

The lsp() method has no null guard. When the sidebar renders the LSP panel before the LSP service is initialized, sync.data.lsp is undefined, causing the crash.

Reproduction

  1. Open a project in opencode TUI
  2. Trigger LSP diagnostics on a file (e.g., open a C/C++ file with clangd)
  3. Open the sidebar before LSP service finishes initializing
  4. Crash occurs

Environment

  • opencode version: 1.3.9
  • OS: Windows 11
  • LSP: clangd

Suggested Fix

Add null guard in api.tsx:186:

lsp() {
  return (sync.data.lsp ?? []).map((item) => ({ id: item.id, root: item.root, status: item.status }))
}

Same pattern should be applied to mcp() at line 189 if sync.data.mcp can also be undefined.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions