ueberdosis / tiptap

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

[Bug]: Dragging Only A Part Creates Duplicate Unique-ID #5578

Open rosenbauerwillbacker opened 2 weeks ago

rosenbauerwillbacker commented 2 weeks ago

Affected Packages

@tiptap-pro/extension-unique-id, @tiptap-react

Version(s)

2.10.11

Bug Description

Simple steps to reproduce:

  1. Visit the official Tiptap demo: https://tiptap.dev/docs/editor/extensions/functionality/uniqueid
  2. Select a small text part of the heading. (e.g. "very") image
  3. Drag it to an empty space, so that it creates a new node. image

As you can see we have now created two nodes with a duplicate id. I have also reproduced that locally with the latest packages.

Quick-Fix We have fixed it by automatically forcing the user to select the whole heading.

addProseMirrorPlugins() {
    return [
      new Plugin({
        props: {
          // Select the entire heading nodes when they are dragged
          handleDOMEvents: {
            dragstart(view, event) {
              const { state, dispatch } = view;
              const { doc, selection } = view.state;
              const { from, to} = selection;

              let minFrom = from;
              let maxTo = to;
              doc.nodesBetween(from, to, (node, pos) => {
                if (node.type.name === 'heading') {
                  minFrom = Math.min(minFrom, pos);
                  maxTo = Math.max(maxTo, pos + node.nodeSize);
                }
              });
              if (minFrom !== from || maxTo !== to) {
                const tr = state.tr.setSelection(
                  TextSelection.create(state.doc, minFrom, maxTo)
                );
                dispatch(tr);
              }
            }
          }
        }
      })  
    ];
  },

Info Our team would really like to use this pro extension in production. However, this is the third bug we have encountered after testing it for two days. Is this extension considered stable or is it experimental?

It would be great if some additional logic or automated tests would be added that ensures the stability of this great plugin. We have a business-critical application and having suddenly two nodes with duplicate ids poses a big threat to us.

Thank you very much in advance for your help.

Browser Used

Chrome

Code Example URL

No response

Expected Behavior

Unique-ids should be unique as the name suggests.

Additional Context (Optional)

No response

Dependency Updates

nperez0111 commented 2 weeks ago

Hm that is strange because it should be rewriting if there is every a duplicate ID valid bug on our side that @bdbch could help with