LearnNewsExamplesServices
Frontmatter
id8860
titleFix Service Worker clone error and Manager initialization race conditions
stateClosed
labels
bugaicore
assigneestobiu
createdAtJan 22, 2026, 12:57 AM
updatedAtJan 22, 2026, 1:08 AM
githubUrlhttps://github.com/neomjs/neo/issues/8860
authortobiu
commentsCount1
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJan 22, 2026, 1:08 AM

Fix Service Worker clone error and Manager initialization race conditions

Closed v11.23.1 bugaicore
tobiu
tobiu commented on Jan 22, 2026, 12:57 AM

This task addresses three runtime errors discovered in dist/production builds:

  1. Service Worker Error: TypeError: Failed to execute 'clone' on 'Response': Response body is already used.

    • Cause: The response.clone() method is called inside an asynchronous caches.open().then() block. By the time this block executes, the browser has likely already consumed the original response body (which was returned immediately to respondWith).
    • Fix: Clone the response synchronous-immediately upon receipt, before any async cache operations.
  2. Manager Initialization Error: TypeError: Cannot set properties of undefined (setting 'neo-5') inside promiseMessage.

    • Cause: me.promises is initialized at the end of the construct method, but checkServiceWorkerVersion() (which uses promiseMessage) is called earlier in the constructor.
    • Fix: Move me.promises = {} initialization to the beginning of the construct method.
  3. Manager getWorker Error: TypeError: Cannot read properties of undefined (reading 'worker').

    • Cause: getWorker(name) attempts to access this.workers[name].worker without checking if this.workers[name] exists.
    • Fix: Add a safety check for the existence of the worker entry in this.workers.
tobiu added the bug label on Jan 22, 2026, 12:57 AM
tobiu added the ai label on Jan 22, 2026, 12:57 AM
tobiu added the core label on Jan 22, 2026, 12:57 AM
tobiu referenced in commit 2776bdb - "fix: ServiceWorker clone error and Manager init race conditions (#8860)" on Jan 22, 2026, 1:02 AM
tobiu assigned to @tobiu on Jan 22, 2026, 1:03 AM
tobiu
tobiu Jan 22, 2026, 1:03 AM

Input from Gemini 3 Pro:

✦ I have applied the following fixes to address the runtime errors in dist/production:

  1. Service Worker Clone Error: Updated src/worker/ServiceBase.mjs to synchronously clone the response in onFetch before any async cache operations. This prevents the "Response body is already used" error.
  2. Manager Initialization Race Condition: Updated src/worker/Manager.mjs to initialize me.promises = {} at the very beginning of the construct method. This ensures it's available when checkServiceWorkerVersion (and subsequently promiseMessage) is called.
  3. Manager getWorker Safety Check: Updated getWorker in src/worker/Manager.mjs to check for the existence of this.workers[name] before accessing its .worker property, preventing the "Cannot read properties of undefined" error.

The changes have been committed and pushed to dev.

tobiu closed this issue on Jan 22, 2026, 1:08 AM