Skip to content

"Cursor" placed incorrectly when adding custom block #1844

Closed

Description

@sgehrig

Describe the bug
I am using this very simple custom block:

export const Title = createReactBlockSpec(
    {
        type: 'title',
        propSchema: {
            type: {
                default: 'type-a',
                values: ['type-a', 'type-b'],
            },
        },
        content: 'inline',
        hardBreakShortcut: 'none',
    },
    {
        render: (props) => {
            return (
                <div className="title-block" data-title-type={props.block.props.type}>
                    <div className="inline-content" ref={props.contentRef}/>
                </div>
            );
        },
    },
);

The CSS is something like this:

.title-block {
    text-align: center;
} 

When the block is added, the cursor is blinking on the left edge of the added block div (hardly visible in the image).

Image

As soon as I start typing the cursor moves to the center (as per text-align: center) and everything looks OK.

Image

If I inspect the DOM however, the following is created:

<div class="title-block" data-title-type="title">
    dfvvdfvdf
    <div class="bn-inline-content inline-content"></div>
</div>

The text is not added to the .inline-content element that holds the contentRef but before that node. Also the document content is not updated and the block has an empty content property. And therefore the UI also considers the block empty replacing it when you try to add a block with the + button on said custom block.

It works however, if I do not start typing immediately after adding the block:

  • add custom block
  • click anywhere into another block (if there's no other block than this does not work)
  • click back into the newly added custom block
  • start typing
  • DOM looks good.

To Reproduce

  • add custom block
  • start typing after the block has been added

The issue is reproducible here: https://stackblitz.com/edit/github-scugpd2y?file=App.tsx

Misc

  • Node version: v24.4.0
  • Package manager: npm 10.9.1
  • Browser: Google Chrome
  • React: 18.3.1

Activity

  1. MetaMmodern commented on Jul 26, 2025

    @MetaMmodern

    I actually have the same thing, but in my case cursor appears right after my custom block. @sgehrig Have you found a solution so far?

  2. sgehrig commented on Jul 26, 2025

    @sgehrig
    Author

    @MetaMmodern Not yet. To be honest, at this point I was simply hoping for a fix.

  3. MetaMmodern commented on Jul 27, 2025

    @MetaMmodern

    I've tried digging more and found this issue: #1802

    So decided to try that same approach and digged more into TipTap.

    I mixed in React stuff through addNodeView and could reproduce it in my app.

    The funny part is that this versions works without bugs:

      addNodeView() {
        return () => {
          const dom = document.createElement("div");
    
          dom.classList.add("node-view");
    
          const label = document.createElement("label");
    
          label.innerHTML = "Node view";
          label.contentEditable = false;
    
          const content = document.createElement("div");
    
          content.classList.add("content");
          content.classList.add("is-editable");
    
          dom.append(label, content);
    
          return {
            dom,
            contentDOM: content,
          };
        };
      },

    but this doesn't:

      addNodeView() {
        return ReactNodeViewRenderer(() => (
          <NodeViewWrapper className="node-view">
            <label contentEditable={false}>React Component</label>
    
            <NodeViewContent className="content is-editable" />
          </NodeViewWrapper>
        ));
      },

    It renders cursor underneath the block:

    Image

    chatgpt has been telling that this is somehow related to how React handles refs, not attaching them right away before render. I guess NodeViewContent is using a ref internally.
    But I don't understand why it works in tipTap and BlockNote examples but doesn't work inside my app...

    I'm not even sure I can reproduce this in sandbox and I'm tired:(

  4. MetaMmodern commented on Jul 27, 2025

    @MetaMmodern

    I checked BlockNote source code as well, it uses the exact same approach of ReactNodeViewRenderer. So, that means it's something breaking on that TipTap level.

  5. MetaMmodern commented on Jul 27, 2025

    @MetaMmodern

    @nperez0111 can you please look into this and let us know if this is even something we could fix ourselves? The wild part is that official examples work, while our attempts fail with this cursor bug.

  6. sgehrig commented on Jul 27, 2025

    @sgehrig
    Author

    One thing to note: we're using React 18 (and that's what my reproducer uses as well) but most official examples use React 19 if I'm not mistaken.

  7. MetaMmodern commented on Jul 27, 2025

    @MetaMmodern

    One thing to note: we're using React 18 (and that's what my reproducer uses as well) but most official examples use React 19 if I'm not mistaken.

    I use react 19.1
    So probably not the cause

    P.S. although, our issues are slightly different, so maybe maybe
    Can you bump it to 19 in your stackblitz?

  8. sgehrig commented on Jul 28, 2025

    @sgehrig
    Author

    One thing to note: we're using React 18 (and that's what my reproducer uses as well) but most official examples use React 19 if I'm not mistaken.

    I use react 19.1 So probably not the cause

    P.S. although, our issues are slightly different, so maybe maybe Can you bump it to 19 in your stackblitz?

    The problem is that we need React 18 because the application is not yet ready for 19. That's why I explicitly tried to mimic the real environment.

  9. sgehrig commented on Aug 25, 2025

    @sgehrig
    Author

    @nperez0111 Much appreciated! Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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