fix(store): improve WebSocket client ID on tab reload and duplication - #26370
fix(store): improve WebSocket client ID on tab reload and duplication#26370luka-mimi wants to merge 2 commits into
Conversation
… tab reload and duplication
There was a problem hiding this comment.
No issues found across 1 file
Architecture diagram
sequenceDiagram
participant Tab as Browser Tab
participant Store as useRootStore
participant Perf as Performance API
participant Storage as sessionStorage
participant WS as WebSocket Client
participant Backend as n8n Server
Note over Tab, Store: Store Initialization (on load/reload)
Tab->>Store: Initialize Store
Store->>Store: getClientId()
Store->>Perf: NEW: Check navigation type
Perf-->>Store: PerformanceNavigationTiming (type)
alt NEW: navEntry.type is 'reload'
Store->>Storage: CHANGED: Attempt to retrieve 'n8n-client-id'
Storage-->>Store: existingId (if present)
else NEW: navEntry.type is not 'reload' (e.g. duplication/new tab)
Store->>Store: Generate new random ID
Store->>Storage: setItem('n8n-client-id', newId)
end
Store-->>WS: Return clientId
WS->>Backend: Connect via WebSocket (query: pushRef=clientId)
Note over WS, Backend: Backend maps execution updates to specific clientId
|
Hey @luka-mimi, Thank you for your contribution. We appreciate the time and effort you’ve taken to submit this pull request. Before we can proceed, please ensure the following: Regarding new nodes: If your node integrates with an AI service that you own or represent, please email nodes@n8n.io and we will be happy to discuss the best approach. About review timelines: Thank you again for contributing to n8n. |
|
Hey @luka-mimi Don't forget to add tests so we can pass it on for review. |
I have added the test cases. However, I don’t think these test cases can fully simulate browser behavior. This bug only occurs when duplicating a tab in the browser. |
Summary
Problem
clientIdto maintain its own WebSocketconnection with the n8n backend, so execution push messages are routed to
the correct tab.
sessionStorage, meaning the duplicated tab inheritsthe same
n8n-client-idas the original. Both tabs then share oneclientId, causing push messages to be misrouted between them.clientId, otherwise in-flightexecution messages from the backend — already addressed to the old ID —
are lost.
tell a reload (reuse needed) from a duplication (new ID needed).
Fix
Detect navigation type using
performance.getEntriesByType('navigation')[0].type:"reload"→ reuse the stored ID (keeps push messages alive)duplication)
Result
Related Linear tickets, Github issues, and Community forum posts
#26369
fixes #<26369>
Review / Merge checklist
release/backport(if the PR is an urgent fix that needs to be backported)