Skip to content

Code blocks fail to render when syntax highlighting worker initialization fails #27317

@adnangif

Description

@adnangif

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

  1. Start the opencode server: opencode serve --port 4096
  2. Build an Expo app with react-native-webview pointing to the opencode web UI
  3. Build for Android production (eas build --platform android)
  4. Install the production APK on a physical Android device
  5. Send a prompt that triggers a code block response
  6. Observe that the code blocks don't render, expand/collapse appears broken
  7. 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

  1. Start the opencode server: opencode serve --port 4096
  2. Open the opencode web UI in Chrome
  3. 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() {}
    };
  4. Send a prompt that triggers a code block response
  5. Observe that the code blocks don't render, expand/collapse appears broken

Screenshot and/or share link

Image Image Image

Operating System

Ubuntu 24.04 noble

Terminal

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions