fix(files): make embedded resource file view collaborative - #6095
Conversation
The /chat resource panel rendered saved files through FileViewer without the collaborative opt-in, so a file open on the Files page and the same file open in the embedded panel never joined the same file-doc room — no live carets and no live content sync between the two surfaces. Pass collaborative on the EmbeddedFile FileViewer. Collaboration still self-gates on canEdit + non-streaming + workspace doc, so the agent token-stream preview (the dedicated streaming-file path, canEdit=false) is untouched.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview
Tests cover shared-socket refcounting and independent leave per file id. Reviewed by Cursor Bugbot for commit 60db01b. Configure here. |
Greptile SummaryThe PR enables collaborative editing for settled files in the embedded resource panel and prevents one same-file provider from prematurely removing a shared socket from the collaboration room.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/collaboration/file-doc-provider.ts | Adds socket- and file-scoped provider reference counting so destroying one same-file provider does not terminate collaboration for another. |
| apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/collaboration/file-doc-provider.test.ts | Covers final-provider room departure and verifies that membership counts remain independently scoped by file. |
| apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/resource-content.tsx | Enables collaboration for the embedded saved-file viewer while preserving existing editability and streaming gates. |
Sequence Diagram
sequenceDiagram
participant A as Embedded file viewer
participant B as Files viewer
participant P as FileDocProvider
participant S as Shared socket
participant R as Realtime room
A->>P: Create provider for file
P->>S: Retain file membership (count 1)
S->>R: JOIN file room
B->>P: Create provider for same file
P->>S: Retain file membership (count 2)
A->>P: Destroy first provider
P->>S: Release membership (count 1)
Note over S,R: No LEAVE emitted
B->>P: Destroy final provider
P->>S: Release membership (count 0)
S->>R: LEAVE file room
Reviews (3): Last reviewed commit: "fix(files): refcount file-doc room membe..." | Re-trigger Greptile
Two collaborative surfaces in one tab (the Files editor and the embedded chat resource panel) share one Socket.IO connection, so both providers for the same file JOIN the same room over that socket. The server's LEAVE does socket.leave(name) with no membership refcount, so the first provider's destroy() would strand the second still-mounted one — no more live content or presence. Count live providers per file per socket (keyed by the stable Socket object, so it survives reconnects) and emit LEAVE only when the last provider for a file tears down. The single-provider path is unchanged (0->1->0).
|
@cursor review |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 60db01b. Configure here.
Summary
/chatresource panel rendered saved files throughFileViewerwithout thecollaborativeopt-in, so the same file open on the Files page and in the embedded panel never joined the same file-doc room — no live text caret and no live content sync between the two surfaces.collaborativeon theEmbeddedFileFileViewer. Collaboration self-gates oncanEdit+ non-streaming + workspace doc, so it engages exactly when the user edits a settled file (the reported case) and stays off during streaming.resource.id === 'streaming-file',canEdit={false}) is untouched — no regression to the streaming preview.Type of Change
Testing
Tested manually (typecheck clean; two-surface live caret + content sync). The synthetic streaming-file preview path is unaffected (canEdit=false, collab never engages).
Checklist