Skip to content

Duplicate block.id after Ctrl + Drag copy #1804

Open
@vitallygolovanov

Description

@vitallygolovanov

Hey BlockNote team!

Firstly, thank you for the awesome tool that BlockNote is. Secondly...

Describe the bug

At least I'm pretty sure it's a bug. When I copy a block using Ctrl + drag, the fresh copy keeps the exact same block.id as the original (and therefore my custom permanentId prop ends up colliding too). Until the page is refreshed, the two blocks are indistinguishable to the editor-level APIs like editor.updateBlock().

To Reproduce

  1. Create a block.
  2. Hold Ctrl and drag it somewhere else (classic “duplicate” gesture).
  3. Both the old block and the new one share the same block.id.
    • Any call to editor.updateBlock() that targets one of them updates both.
    • Inside onChange(), there’s no safe way to tell copy from source other than brittle reference checks.

Expected behavior: The duplicate should receive a brand-new block.id (just like what happens when you copy-paste).

For convenience of demonstration, I created a custom block that displays the id right in the editor (but I did confirm that it's not just a rendering bug, the block.id is the same everywhere).

My `useUniqueCustomBlockCopies()` hook does not write block.id. Open the spoiler for an example of a problem stemming from this issue.

I also added a permanentId property to the CustomBlock to simulate some other props that might need updating on copy and how updating the block with an unchanged block.id leads to issues. You can find my attempts at the latter in src/components/editor/unique-custom-block-on-copy.ts.

permanentId is meant to persist across saves, collaboration and other scenarios where block.id is expected to change, but when a block is explicitly copied, the copy needs to be assigned a new permanentId._

Expected behavior: after ctrl+drag below the original block, the original retains it's permanentId, while the copy is assigned the new permanentId.

Actual behavior: both original and the copy get assigned the new permanentId.

However, my code might be bugged because of all iterations of trying to get it to work before realizing that same id's after copy might be a bug. Or because I'm doing this in the entirely wrong place. I asked this question in #1797

Repo: https://github.com/vitallygolovanov/block-note-duplicate-id-on-copy-minimal-repro

StackBlitz (to run in browser): https://stackblitz.com/~/github.com/vitallygolovanov/block-note-duplicate-id-on-copy-minimal-repro

Misc

  • @blocknote/core: 0.32.0
  • @blocknote/react: 0.32.0
  • @blocknote/mantine: 0.32.0
  • React: 19.0.0
  • Next.js: 15.3.4
  • Browser: Chrome 137.0.7151.104 (64-bit)
  • OS: Windows 10 (also reproducible in StackBlitz Linux container)

Possible fix?

Looks like the drop-copy path skips the internal ID-regeneration step that paste already does. If I’m not missing something obvious, simply re-running whatever generates new block.ids after a move-&-clone (but preferably before onChange() is fired) should solve it.

Happy to test a patch or dig deeper if someone points me in the right direction. Not sure, if I'm familiar enough with BlockNote's codebase to produce a PR though yet. Thanks for the awesome editor!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions