Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • show presence for the same user in another tab
  • fix z-index of multiplayer cursor to fall behind panel,terminal,sidebar but above blocks
  • improved connection detection

Type of Change

  • Bug fix
  • New feature

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

…, fix z-index of multiplayer cursor to fall behind panel,terminal,sidebar but above blocks, improved connection detection
@vercel
Copy link

vercel bot commented Jan 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Jan 16, 2026 2:42am

Review with Vercel Agent

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 16, 2026

Greptile Summary

This PR enables multi-tab presence for the same user and fixes cursor layering. Changed from filtering by userId to currentSocketId, allowing users to see their own presence in other tabs. The cursor z-index was reduced from z-30 to z-[5] to properly layer behind panels/sidebars but above workflow blocks.

Key changes:

  • Added currentSocketId state tracking in socket provider with proper lifecycle management (set on connect/reconnect, cleared on disconnect)
  • Improved presence state management by upserting users in cursor-update and selection-update handlers, preventing data loss when these events arrive before presence-update
  • Enhanced presence-update handler to preserve existing cursor/selection state when merging with new user data
  • Replaced useSession calls with currentSocketId from socket context in cursor and avatar components
  • Added overflow-hidden to cursor container to prevent visual overflow

The upsert logic in cursor/selection handlers (lines 406-448) addresses the race condition where cursor/selection events could arrive before the authoritative presence broadcast, ensuring users are always visible even if events arrive out of order.

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk of breaking existing functionality
  • The changes are focused and well-tested. The upsert logic addresses the race condition concerns from previous comments. The z-index change is a straightforward styling fix. The only consideration is the added complexity in presence state management, which could have edge cases in high-concurrency scenarios
  • Pay close attention to socket-provider.tsx - the upsert logic adds complexity to state management that should be monitored in production

Important Files Changed

Filename Overview
apps/sim/app/workspace/providers/socket-provider.tsx Added currentSocketId state tracking and improved presence management with cursor/selection event upsert logic; preserves cursor/selection state during presence updates
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/cursors/cursors.tsx Changed filtering from userId to currentSocketId to show same user's other tabs; updated z-index from z-30 to z-[5] and added overflow-hidden
apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workflow-list/components/workflow-item/avatars/avatars.tsx Changed filtering from userId to currentSocketId to allow same user's multiple tabs to appear in presence list

Sequence Diagram

sequenceDiagram
    participant Client as Client (Tab)
    participant Socket as Socket Provider
    participant Server as Socket.IO Server
    participant Other as Other Clients
    
    Note over Client,Server: Connection & Presence Setup
    Client->>Socket: Initialize connection
    Socket->>Server: connect (with auth token)
    Server->>Socket: connect event
    Socket->>Socket: setCurrentSocketId(socketInstance.id)
    Socket->>Server: join-workflow(workflowId)
    Server->>Socket: presence-update(all users)
    Socket->>Socket: setPresenceUsers (merge with existing cursor/selection)
    Server->>Other: presence-update(including new user)
    
    Note over Client,Server: Cursor Updates (Race Condition Handling)
    Client->>Socket: emitCursorUpdate({x, y})
    Socket->>Server: cursor-update event
    Server->>Other: broadcast cursor-update
    Other->>Socket: receive cursor-update
    Socket->>Socket: Check if user exists in presenceUsers
    alt User exists
        Socket->>Socket: Update cursor for existing user
    else User doesn't exist (race condition)
        Socket->>Socket: Upsert new user with cursor data
    end
    Server->>Other: presence-update (periodic/on join)
    Socket->>Socket: Merge presence with existing cursor/selection state
    
    Note over Client,Server: Filtering & Display
    Socket->>Client: presenceUsers + currentSocketId
    Client->>Client: Filter by socketId !== currentSocketId
    Client->>Client: Render cursors/avatars (same user, different tabs visible)
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

@greptile

@waleedlatif1 waleedlatif1 merged commit feb994c into staging Jan 16, 2026
11 checks passed
@waleedlatif1 waleedlatif1 deleted the improvement/presence branch January 16, 2026 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants