ueberdosis / tiptap

The headless rich text editor framework for web artisans.
https://tiptap.dev
MIT License
25.79k stars 2.18k forks source link

[PRO]: TableOfContents w/ Collab keeps adding extra blank nodes to content #4829

Open qctechjunkie opened 6 months ago

qctechjunkie commented 6 months ago

Which packages did you experience the bug in?

react, extension-table-of-contents, extension-collaboration

What Tiptap version are you using?

2.1.16

What’s the bug you are facing?

We are seeing a bug where empty lines are created when running collab and table of contents (ToC) together. Specificlly when asking ToC to index paragraph nodes. Before collab sync is complete, ToC will index the empty editor's default placeholder paragraph.

<p id="8fa..." data-toc-id="8fa66..." data-placeholder="Body Copy" class="is-empty"><br class="ProseMirror-trailingBreak"></p>

The reason collab begins with an empty editor instead of the content from the record is that TipTap has a duplication problem when starting with content provided in the content prop

If the content is passed in client side, Collab sees this as a change/addition to the content it has, and doubles everything on each page load.

What browser are you using?

Chrome

Code example

No response

What did you expect to happen?

We would expect Table of Contents (ToC) to ignore empty paragraph nodes until content is actually in the node. Or have ToC wait for Collab sync, if Collab is enabled, before indexing the content.

Anything to add? (optional)

No response

Did you update your dependencies?

Are you sponsoring us?

mattkindy commented 3 weeks ago

I believe I was experiencing this even without indexing paragraph nodes when the document was initially empty, with this extension setup:

import { TableOfContents as ToC } from "@tiptap-pro/extension-table-of-contents";

export const TableOfContents = ToC.extend({
  anchorTypes: ["heading"],
});