Open
Description
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