Yjs Multiplayer + Offline Sync for Canvas Apps

    0

    Building collaborative features is notoriously difficult.

    $19

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 more

    Yjs Multiplayer + Offline Sync for Canvas Apps

    Example session with this skill installed

    Make my drawing app collaborative. It uses React and saves strokes as a JSON array in local state. I want live cursors and offline support.

    • Read your context and instructions
    • Compiled the yjs multiplayer

    I have mapped your drawing state to a Yjs document and set up the connection logic. The implementation uses y-indexeddb for offline persistence and y-websocket for the sync layer. I've also added a cursor overlay component that tracks positions in canvas coordinates to ensure they stay accurate regardless of zoom level.

    Multiplayer Canvas Integration

    FeatureImplementation DetailStatus
    Document TypeY.Map<Y.Map<any>> (Keyed by UUID)Configured
    Offline LayerIndexeddbPersistence (Prefixed by Room ID)Active
    PresenceAwareness API with 30s timeoutEnabled
    PersistencePostgres Update Log with Snapshot CompactionReady
    Inputtouch-action: none with Pointer EventsOptimized
    // src/hooks/useRoom.ts
    import * as Y from 'yjs';
    import { WebsocketProvider } from 'y-websocket';
    import { IndexeddbPersistence } from 'y-indexeddb';
    
    export function useRoom(roomId: string) {
      const doc = useMemo(() => new Y.Doc(), []);
      
      useEffect(() => {
        const ldb = new IndexeddbPersistence(`draw-app:${roomId}`, doc);
        const provider = new WebsocketProvider('wss://your-sync-server.com', roomId, doc, { connect: false });
        
        // Auth and Connection logic
        provider.connect();
        
        return () => {
          provider.destroy();
          ldb.destroy();
          doc.destroy();
        };
      }, [roomId, doc]);
    
      return { doc, provider };
    }
    

    Next steps

    1. Deploy the Node.js sync server using the provided templates/server.ts to a host like Railway or Fly.io.
    2. Update your Canvas component to subscribe to doc.getMap('shapes').observeDeep() to trigger re-renders.
    3. Add the ROOM_TOKEN_SECRET to your environment variables to enable JWT signing.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Building collaborative features is notoriously difficult. Handling CRDT merges, managing WebSocket lifecycles, and ensuring offline edits don't vanish on reconnect takes weeks of tuning. This skill implements a production-grade synchronization layer for web canvases and editors.

    What it does

    • Multiplayer state: Implements Yjs CRDTs to sync shapes, strokes, and text across users with automatic conflict resolution.
    • Offline-first sync: Configures IndexedDB persistence to ensure data is saved locally and merged the moment a connection returns.
    • Presence & cursors: Adds real-time awareness for live cursors and "who is online" states using world-coordinate tracking to prevent zoom-drift.
    • Secure sync server: Sets up a Node.js WebSocket server with JWT authentication and Postgres persistence for long-term storage.
    • Input handling: Resolves common mobile issues like palm rejection, pinch-to-zoom on canvases, and smooth Apple Pencil input.

    How it works

    1. State mapping: The skill analyzes your existing state (Zustand, Redux, or JSON) and maps it to shared Y.Map or Y.Text types.
    2. Infrastructure setup: It scaffolds the WebSocket provider, IndexedDB layer, and the Node.js backend with Postgres update-log logic.
    3. Integration: It wires the connection lifecycle into your React/Next.js components, including proper cleanup to prevent memory leaks.
    4. Mobile optimization: It applies CSS and pointer event listeners to handle touch-action and multi-touch gestures.

    Frameworks & tools

    TypeScript, React/Next.js, Node.js, Yjs, y-websocket, y-indexeddb, ws, PostgreSQL, and jose for JWT handling.

    Why this beats prompting it yourself

    Generic prompts often fail to handle the complex lifecycle of WebSockets in React, leading to duplicate connections or "ghost" objects. This skill enforces a specific, battle-tested order of operations for CRDT merging and Postgres compaction that prevents document corruption and memory bloat.

    Use cases

    • Adding Figma-like live collaboration to a whiteboard or canvas app.
    • Building an offline-capable Markdown editor that syncs when back online.
    • Replacing high-cost managed sync services with a self-hosted Yjs architecture.
    • Fixing broken touch and zoom interactions on collaborative drawing tools.

    Known limitations

    Does not support serverless environments (Vercel/Netlify) for the sync server. Not intended for simple CRUD or chat-only applications. Requires a long-running process host.

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for APIs & Backend.

    Requires a long-running Node.js process for WebSockets (no serverless). Does not support chat-only apps. Requires manual hosting setup for Postgres and the sync server.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 15 days ago

    Permissions

    Terminal / Shell
    Network Access
    Environment Variables

    Allowed Hosts

    x
    Listed15 days ago

    What's inside

    Frequently Asked Questions

    This skill implements Yjs-based CRDTs to handle automatic conflict resolution, ensuring that concurrent edits from multiple users merge seamlessly without data loss, even when working offline.

    The skill is designed for React and Next.js applications and requires a long-running Node.js environment (like an EC2, Fly.io, or DigitalOcean droplet) to host the WebSocket sync server, as serverless functions do not support persistent connections.

    You receive a production-grade integration including the Yjs state mapping logic, a Node.js WebSocket server with JWT security, IndexedDB local persistence configuration, and mobile-optimized input handlers for canvases.

    Yes, the skill is built to map existing JSON-based state managers like Zustand or Redux into shared Yjs types, allowing you to add multiplayer features to an established codebase without a complete rewrite.

    Unlike generic code generation, this skill implements specific lifecycle management to prevent memory leaks and 'ghost' connections, while also configuring PostgreSQL compaction to prevent your database from bloating with document history.

    The skill includes specialized pointer event listeners and CSS configurations that resolve common mobile issues like palm rejection, pinch-to-zoom interference, and Apple Pencil latency on collaborative surfaces.

    New in APIs & Backend