Frontmatter
| id | 8497 |
| title | ServiceWorker: Implement Remote Method Broadcast and Replay for Multi-Client Support |
| state | Closed |
| labels | bugaicore |
| assignees | tobiu |
| createdAt | Jan 10, 2026, 12:28 PM |
| updatedAt | Jan 10, 2026, 12:36 PM |
| githubUrl | https://github.com/neomjs/neo/issues/8497 |
| author | tobiu |
| commentsCount | 1 |
| parentIssue | null |
| subIssues | [] |
| subIssuesCompleted | 0 |
| subIssuesTotal | 0 |
| blockedBy | [] |
| blocking | [] |
| closedAt | Jan 10, 2026, 12:36 PM |
ServiceWorker: Implement Remote Method Broadcast and Replay for Multi-Client Support
tobiu assigned to @tobiu on Jan 10, 2026, 12:28 PM

tobiu
Jan 10, 2026, 12:36 PM
Input from tobiu:
◆ Implemented the "Registry & Replay" pattern for Service Worker remote method registration.
Changes:
src/core/Base.mjs(initRemote):
- Added detection for
Neo.workerId === 'service'.- Now populates
Neo.currentWorker.remotesToRegisterwithremote.appdefinitions instead of relying solely onpromiseRemotesimmediate execution.
src/worker/ServiceBase.mjs:
- Added
remotesToRegisterarray.- Updated
createMessageChannelto iterate throughremotesToRegisterand postregisterRemotemessages to the newly connected port. This ensures every connecting client (tab) receives the remote method proxies.- Refined
hasWorker(name)to strict mode (!!this.getPort(name) || !!this.lastClient), removing the hardcodedname === 'app'check. This preventspromiseRemotesfrom falsely attempting to send messages when no clients are actually connected, preventing initialization errors.This ensures robust remote method availability across all connected windows and tabs.
tobiu closed this issue on Jan 10, 2026, 12:36 PM
The Service Worker does not properly propagate remote method registration to multiple connected clients (App Workers) or handle new connections after initialization.
The Problem:
Neo.core.Base.promiseRemotestargets 'app', but in a Service Worker context, 'app' represents any connected client. The current logic attempts to send to a single port, missing others.initRemoteruns once on startup. Clients connecting after startup (e.g., opening a new tab) never receive theregisterRemotemessage and cannot access Service Worker methods.promiseRemotesfails if called when no clients are connected (becausesendMessagereturns null), rejecting the initialization promise.Proposed Solution: Adopt the "Registry & Replay" pattern used for SharedWorkers (#8339).
src/core/Base.mjs(initRemote):Neo.workerId === 'service'.remote.appdefinitions inNeo.currentWorker.remotesToRegister.src/worker/ServiceBase.mjs:remotesToRegister = [].createMessageChannel(triggered byonConnect) to iterateremotesToRegisterand sendregisterRemoteto the new client's port.hasWorker('app')to returntrueonly if active ports exist, preventingpromiseRemotesfrom failing when no clients are connected.This ensures every client—existing or new—receives the remote method definitions.