Skip to content

createReactBlockSpec weird behaviour for placeholder and cursor for custom blocks #1802

Closed

Description

@kanishk619

Description

When creating a custom block using createReactBlockSpec, I encountered several rendering issues that make it impractical for use in certain scenarios.

❌ Problems Encountered

  • Placeholders do not appear when the block is empty
  • Cursor disappears if the context text is entirely removed

✅ Workaround

Switching to createStronglyTypedTiptapNode resolves the issues.

💡 Example (Working)

import {
  createStronglyTypedTiptapNode,
  createBlockSpecFromStronglyTypedTiptapNode,
  propsToAttributes,
  createDefaultBlockDOMOutputSpec,
  defaultProps,
} from "@blocknote/core";

const sectionPropSchema = {
  ...defaultProps,
};

const SectionBlockContent = createStronglyTypedTiptapNode({
  name: "section",
  content: "inline*",
  group: "blockContent",

  addAttributes() {
    return propsToAttributes(sectionPropSchema);
  },

  parseHTML() {
    return [
      {
        tag: "div[data-content-type=section]",
        contentElement: ".bn-inline-content",
      },
      {
        tag: "section",
        getAttrs: (element) => {
          if (typeof element === "string" || !element.textContent?.trim()) {
            return false;
          }
          return {};
        },
        node: "section",
      },
    ];
  },

  renderHTML({ HTMLAttributes }) {
    return createDefaultBlockDOMOutputSpec(
      this.name,
      "section",
      {
        ...HTMLAttributes,
      }
    );
  },
});

export const Section = createBlockSpecFromStronglyTypedTiptapNode(
  SectionBlockContent,
  sectionPropSchema
);

Not sure if I am missing something with createReactBlockSpec

Activity

  1. changed the title [-]### 🐛 Bug: `createReactBlockSpec` weird behaviour for placeholder and cursor for custom blocks[/-] [+]createReactBlockSpec weird behaviour for placeholder and cursor for custom blocks[/+] on Jun 30, 2025
  2. YousefED commented on Jul 1, 2025

    @YousefED
    Collaborator

    Thanks for reporting. We're planning a refactor that streamlines these two methods of creating blocks that should resolve this issue as well

  3. nperez0111 commented on Sep 18, 2025

    @nperez0111
    Contributor

    There has been a number of changes to the blocknote API as part of the refactor, please try again & let us know if you have issues!

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