Skip to content

Content Duplication in Collaborative Editor Upon Page Refresh #950

Open
@DineshCodeFlow

Description

@DineshCodeFlow

I'm experiencing a content duplication issue in my collaborative editor built with Yjs and PartyKit. Every time I refresh the page, the initial content is duplicated.​

Steps to Reproduce:

Set up a collaborative editor using Yjs and PartyKit.​

  • Insert initial content into the Yjs document if it's empty.​

  • Open the editor in a browser.​

  • Refresh the page.​

  • Observe that the initial content is duplicated.​

Expected Behavior:

The initial content should appear only once, regardless of page refreshes.​

Actual Behavior:

Each page refresh results in the initial content being duplicated.​

Code Snippet:

import type { PartyKitServer } from "partykit/server";
import { onConnect } from "y-partykit";
import * as Y from "yjs";

export default {
  onConnect(ws, room) {
    return onConnect(ws, room, {
      persist: { mode: "snapshot" },

      async load() {
        const yDoc = new Y.Doc();
        return yDoc;
      },
    });
  },
} satisfies PartyKitServer;

This happens as soon I goes away from blocknote editor to some other page when I comes back the initial lines repeats.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions