Description
Summary
Code blocks fail to render when the worker-based syntax highlighting pipeline fails to initialize. The worker pool remains uninitialized (initialized: false, empty language registry) and may not emit a reliable error event. As a result, no highlighted HTML is generated and code blocks do not render, causing dependent UI elements such as expand/collapse to break due to missing content.
This has been observed in Android production builds when the OpenCode web UI is loaded inside an Expo React Native WebView. It does not reproduce in desktop browsers or Android debug/emulator builds.
Observed Behavior
- Worker pool remains uninitialized (
initialized: false)
- Empty language registry
- No reliable error event emitted
- Syntax highlighting does not render
- Code blocks do not render
- Expand/collapse UI appears broken due to missing content
Expected Behavior
Worker initialization failure should trigger a fallback to main-thread highlighting instead of leaving the system in an uninitialized state.
Proposed Fix
Wrap worker initialization in a Promise.race between:
- successful initialization
- worker error event
- timeout
If worker initialization does not successfully complete before error/timeout, fallback to main thread
Scope
No behavior change in environments where workers function correctly. This only adds a fallback path for initialization failure cases.
Plugins
None
OpenCode version
1.14.48
Steps to reproduce
Actual Environment
- Start the opencode server: opencode serve --port 4096
- Build an Expo app with react-native-webview pointing to the opencode web UI
- Build for Android production (eas build --platform android)
- Install the production APK on a physical Android device
- Send a prompt that triggers a code block response
- Observe that the code blocks don't render, expand/collapse appears broken
- Observe that in console, it raises this Error:
[ERR] 17:07:18 Worker error: {
"isTrusted": true
} {
"worker": {},
"request_id": "req_5",
"initialized": false,
"langs": {}
}
Reproduce in Browser
- Start the opencode server: opencode serve --port 4096
- Open the opencode web UI in Chrome
- Open DevTools → Console, paste and run:
window.Worker = class {
constructor() {
setTimeout(() => {
if (this.onerror) this.onerror(new ErrorEvent("error", { message: "Initialization failed" }));
}, 0);
}
postMessage() {}
addEventListener(type, handler) {
if (type === "error") this.onerror = handler;
}
terminate() {}
};
- Send a prompt that triggers a code block response
- Observe that the code blocks don't render, expand/collapse appears broken
Screenshot and/or share link
Operating System
Ubuntu 24.04 noble
Terminal
No response
Description
Summary
Code blocks fail to render when the worker-based syntax highlighting pipeline fails to initialize. The worker pool remains uninitialized (
initialized: false, empty language registry) and may not emit a reliable error event. As a result, no highlighted HTML is generated and code blocks do not render, causing dependent UI elements such as expand/collapse to break due to missing content.This has been observed in Android production builds when the OpenCode web UI is loaded inside an Expo React Native WebView. It does not reproduce in desktop browsers or Android debug/emulator builds.
Observed Behavior
initialized: false)Expected Behavior
Worker initialization failure should trigger a fallback to main-thread highlighting instead of leaving the system in an uninitialized state.
Proposed Fix
Wrap worker initialization in a
Promise.racebetween:If worker initialization does not successfully complete before error/timeout, fallback to main thread
Scope
No behavior change in environments where workers function correctly. This only adds a fallback path for initialization failure cases.
Plugins
None
OpenCode version
1.14.48
Steps to reproduce
Actual Environment
[ERR] 17:07:18 Worker error: {
"isTrusted": true
} {
"worker": {},
"request_id": "req_5",
"initialized": false,
"langs": {}
}
Reproduce in Browser
window.Worker = class {
constructor() {
setTimeout(() => {
if (this.onerror) this.onerror(new ErrorEvent("error", { message: "Initialization failed" }));
}, 0);
}
postMessage() {}
addEventListener(type, handler) {
if (type === "error") this.onerror = handler;
}
terminate() {}
};
Screenshot and/or share link
Operating System
Ubuntu 24.04 noble
Terminal
No response