Skip to content

fix(store): improve WebSocket client ID on tab reload and duplication - #26370

Closed
luka-mimi wants to merge 2 commits into
n8n-io:masterfrom
luka-mimi:fix-websocket-pushRef
Closed

fix(store): improve WebSocket client ID on tab reload and duplication#26370
luka-mimi wants to merge 2 commits into
n8n-io:masterfrom
luka-mimi:fix-websocket-pushRef

Conversation

@luka-mimi

@luka-mimi luka-mimi commented Feb 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Problem

  1. Each browser tab needs a unique clientId to maintain its own WebSocket
    connection with the n8n backend, so execution push messages are routed to
    the correct tab.
  2. Tab duplication copies sessionStorage, meaning the duplicated tab inherits
    the same n8n-client-id as the original. Both tabs then share one
    clientId, causing push messages to be misrouted between them.
  3. Page reload must reuse the existing clientId, otherwise in-flight
    execution messages from the backend — already addressed to the old ID —
    are lost.
  4. The old code unconditionally reused the stored ID, making it impossible to
    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)
  • anything else → generate a new ID (breaks the shared-ID problem on
    duplication)

Result

Scenario Before After
First visit New ID ✅ New ID ✅
Page reload Reuse ID ✅ Reuse ID ✅
Tab duplication Reuse ID (conflict) ❌ New ID ✅

Related Linear tickets, Github issues, and Community forum posts

#26369
fixes #<26369>

Review / Merge checklist

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Loading

@n8n-assistant n8n-assistant Bot added community Authored by a community member in linear DEPRECATED labels Feb 28, 2026
@n8n-assistant

n8n-assistant Bot commented Feb 28, 2026

Copy link
Copy Markdown
Contributor

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:
• Tests are included for any new functionality, logic changes or bug fixes.
• The PR aligns with our contribution guidelines.

Regarding new nodes:
We no longer accept new nodes directly into the core codebase. Instead, we encourage contributors to follow our Community Node Submission Guide to publish nodes independently.

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:
This PR has been added to our internal tracker as "GHC-7053". While we plan to review it, we are currently unable to provide an exact timeframe. Our goal is to begin reviews within a month, but this may change depending on team priorities. We will reach out when the review begins.

Thank you again for contributing to n8n.

@Joffcom

Joffcom commented Feb 28, 2026

Copy link
Copy Markdown
Member

Hey @luka-mimi

Don't forget to add tests so we can pass it on for review.

@luka-mimi

Copy link
Copy Markdown
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Authored by a community member in linear DEPRECATED

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants