LearnNewsExamplesServices
Frontmatter
id8339
titleRemote Method Registration Missing for Secondary Windows in SharedWorker
stateClosed
labels
bugaicore
assigneestobiu
createdAtJan 5, 2026, 9:03 PM
updatedAtJan 5, 2026, 9:27 PM
githubUrlhttps://github.com/neomjs/neo/issues/8339
authortobiu
commentsCount1
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJan 5, 2026, 9:27 PM

Remote Method Registration Missing for Secondary Windows in SharedWorker

Closed v11.18.0 bugaicore
tobiu
tobiu commented on Jan 5, 2026, 9:03 PM

Context: In a useSharedWorkers: true environment, a single worker instance (e.g., App, Data) serves multiple connected browser windows (Main Threads).

The Problem: Currently, Neo.core.Base#initRemote() sends the registerRemote message only once when the singleton is first initialized.

  • Window 1 Connects: Worker starts -> Singleton created -> initRemote called -> registerRemote sent to Window 1. Correct.
  • Window 2 Connects: Worker is already running -> Singleton already exists -> initRemote is NOT called again.
  • Result: Window 2 never receives the registerRemote handshake. It has no proxies for the singleton's remote methods.

Impact:

  • Any singleton remote method calls from secondary windows will fail.
  • Critical for Multi-Window Apps (Infinite Canvas, Portal, SharedCovid).

Proposed Solution:

  1. State Persistence: In Neo.core.Base#initRemote, if target === 'main' and we are in a SharedWorker, store the registration payload (className, methods) in a registry on Neo.currentWorker (e.g., remoteMethodRegistry).
  2. Replication: In Neo.worker.Base#onConnected (which fires every time a new window connects), iterate through this registry and re-send all stored registerRemote messages to the newly connected port only.

Scope:

  • src/core/Base.mjs: Update initRemote to register payloads.
  • src/worker/Base.mjs: Add registry storage and update onConnected to replay them.
tobiu added the bug label on Jan 5, 2026, 9:03 PM
tobiu added the ai label on Jan 5, 2026, 9:03 PM
tobiu added the core label on Jan 5, 2026, 9:03 PM
tobiu assigned to @tobiu on Jan 5, 2026, 9:03 PM
tobiu referenced in commit c3a4e13 - "Remote Method Registration Missing for Secondary Windows in SharedWorker #8339" on Jan 5, 2026, 9:26 PM
tobiu
tobiu Jan 5, 2026, 9:27 PM

Input from Gemini 3 Pro:

✦ I have implemented the fix for remote method registration in SharedWorker environments.

Key Changes:

  1. State Persistence (src/worker/Base.mjs):

    • Added remotesToRegister array to Neo.worker.Base.
    • In onConnected, the worker now iterates through this array and sends registerRemote messages to the newly connected port. This ensures that every new window receives the necessary proxy definitions.
  2. Registration Logic (src/core/Base.mjs):

    • Updated initRemote to populate Neo.currentWorker.remotesToRegister when running in a SharedWorker environment.
    • Refactored the connection logic to be more robust: it now unconditionally registers the remote (if applicable) and then awaits the connected event if the worker is not yet ready, before proceeding to promiseRemotes.

Verification:

  • Verified that multi-window applications now correctly receive remote method proxies in secondary windows.
  • Confirmed that existing Dedicated Worker workflows and tests remain unaffected.
tobiu closed this issue on Jan 5, 2026, 9:27 PM
tobiu cross-referenced by #8497 on Jan 10, 2026, 12:28 PM