Collaboration Features
SPEAR provides real-time collaborative editing for report sections, allowing multiple team members to work simultaneously on the same content. This guide covers the technology stack, implementation details, and user experience of collaborative editing.
Overview
Section titled “Overview”Real-time collaboration in SPEAR enables:
- Multiple users editing the same section simultaneously
- Live cursor positions showing where collaborators are working
- Instant synchronization of changes across all clients
- Conflict-free merging of concurrent edits
- Connection status visibility
Technology Stack
Section titled “Technology Stack”Y.js (CRDT Library)
Section titled “Y.js (CRDT Library)”Y.js is a Conflict-free Replicated Data Type (CRDT) implementation that enables real-time collaboration without conflicts. Key benefits:
- Conflict-free - Concurrent edits automatically merge correctly
- Offline support - Changes sync when connection restores
- Efficient - Only diffs are transmitted, not full documents
WebSocket Provider
Section titled “WebSocket Provider”WebSocket connections maintain real-time sync between clients:
- Persistent connection for instant updates
- Automatic reconnection on network issues
- Session persistence for seamless reconnection
Awareness Protocol
Section titled “Awareness Protocol”Tracks user presence and cursor positions:
- User identification (name, color)
- Cursor position in document
- Selection state
- Online/offline status
How It Works
Section titled “How It Works”Document Synchronization
Section titled “Document Synchronization”Each report section has a unique documentId that identifies it for collaboration:
documentId = `section-${sectionId}`When multiple users open the same section:
- Each client creates a Y.js document with the same
documentId - WebSocket connection established to sync server
- Document state syncs between all connected clients
- Changes propagate instantly to all participants
Awareness State
Section titled “Awareness State”The awareness protocol shares user information:
{ user: { name: "John Doe", color: "#3498db", sessionId: "abc123" }, cursor: { anchor: 150, // Cursor position head: 150 }}Connection Status
Section titled “Connection Status”Three connection states are tracked:
| Status | Description | Indicator |
|---|---|---|
| Connected | Active sync connection | Green |
| Connecting | Establishing connection | Yellow |
| Disconnected | No connection | Red |
User Experience
Section titled “User Experience”Live Cursors
Section titled “Live Cursors”When collaborators are editing:
- Colored cursor appears at their position
- Name label shows who is editing
- Cursor moves in real-time as they type
- Selection highlights show selected text
Collaborator Avatars
Section titled “Collaborator Avatars”The editor toolbar displays:
- Avatar icons for each connected user
- Tooltips with user names
- Visual indicator of active collaborators
Real-Time Updates
Section titled “Real-Time Updates”Content changes are visible instantly:
- Text appears as collaborators type
- Formatting changes reflect immediately
- Images and media sync automatically
- No manual refresh required
Enabling Collaboration
Section titled “Enabling Collaboration”BaseEdraEditor Configuration
Section titled “BaseEdraEditor Configuration”Enable collaboration by setting props on BaseEdraEditor:
<script lang="ts"> import BaseEdraEditor from '$lib/components/edra/BaseEdraEditor.svelte';
const sectionId = 'unique-section-id';</script>
<BaseEdraEditor collaboration={true} documentId={`section-${sectionId}`} content={initialContent} onUpdate={(html) => handleUpdate(html)}/>Required Props
Section titled “Required Props”| Prop | Type | Description |
|---|---|---|
collaboration | boolean | Must be true to enable |
documentId | string | Unique identifier for the document |
WebSocket Server
Section titled “WebSocket Server”The backend must provide a WebSocket endpoint for Y.js sync. Configuration is handled by SPEAR’s backend infrastructure.
Collaboration UI Components
Section titled “Collaboration UI Components”Connection Status Badge
Section titled “Connection Status Badge”Displays current connection state in the editor toolbar:
{#if connectionStatus === 'connected'} <Badge variant="success">Connected</Badge>{:else if connectionStatus === 'connecting'} <Badge variant="warning">Connecting...</Badge>{:else} <Badge variant="destructive">Disconnected</Badge>{/if}Collaborator List
Section titled “Collaborator List”Shows active users with visual indicators:
<div class="collaborator-avatars"> {#each collaborators as user} <Avatar style="border-color: {user.color}" title={user.name} > {user.initials} </Avatar> {/each}</div>Session Persistence
Section titled “Session Persistence”Reconnection Handling
Section titled “Reconnection Handling”When connection drops and restores:
- WebSocket provider automatically reconnects
- Y.js syncs local changes with server
- Remote changes sync to local document
- Awareness state re-establishes
Session Storage
Section titled “Session Storage”Connection state persisted to sessionStorage for seamless page refresh:
// Store connection statesessionStorage.setItem(`collab-${documentId}`, JSON.stringify({ timestamp: Date.now(), userId: currentUser.id}));Limitations
Section titled “Limitations”Editor Support
Section titled “Editor Support”Collaboration is only available in BaseEdraEditor. The following editors do not support collaboration:
- FindingsRichTextEditor
- ValidationNotesEditor
- SOWRichTextEditor
Authentication Required
Section titled “Authentication Required”- All collaborators must be authenticated users
- Anonymous collaboration is not supported
- User information displayed to other collaborators
Network Requirements
Section titled “Network Requirements”- WebSocket connection required for real-time sync
- Offline edits will sync when connection restores
- High latency may cause visible sync delays
Concurrent Edit Limits
Section titled “Concurrent Edit Limits”- No hard limit on concurrent users
- Performance may degrade with 10+ simultaneous editors
- Recommended: 5 or fewer concurrent editors per section
Troubleshooting
Section titled “Troubleshooting”Connection Issues
Section titled “Connection Issues”Symptom: Status shows “Disconnected” persistently
Solutions:
- Check network connectivity
- Verify WebSocket server is running
- Check browser console for connection errors
- Try refreshing the page
Cursors Not Visible
Section titled “Cursors Not Visible”Symptom: Can’t see other users’ cursors
Solutions:
- Verify both users have collaboration enabled
- Check that documentId matches exactly
- Ensure awareness state is being shared
- Verify user information is set
Content Not Syncing
Section titled “Content Not Syncing”Symptom: Changes don’t appear for other users
Solutions:
- Check connection status
- Verify Y.js document is initialized
- Check for JavaScript errors in console
- Try refreshing both clients
Duplicate Cursors
Section titled “Duplicate Cursors”Symptom: Multiple cursors appear for same user
Solutions:
- Close duplicate browser tabs
- Clear session storage
- Refresh the page