Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions packages/react/src/schema/ReactBlockSpec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,39 @@ export function createReactBlockSpec<
},
{
className: "bn-react-node-view-renderer",
// Any change to a block's content causes ProseMirror to
// re-render the block. On desktop, this change is detected
// using key presses. On mobile, it's instead detected using
// DOM mutations as touchscreen keyboards don't use typical key
// events. However, React's own rendering causes DOM mutations,
// triggering ProseMirror to re-render the block even if the
// mutation is outside the block's editable content. Therefore,
// we need to explicitly ignore mutations outside the block's
// editable content.
ignoreMutation: ({ mutation }) => {
if (mutation.type === "selection") {
return false;
}

const target =
mutation.target.nodeType === Node.ELEMENT_NODE
? (mutation.target as HTMLElement)
: mutation.target.parentElement;
const content = target?.closest("[data-node-view-content]");

// Ignore mutations outside a block's editable content.
if (!content) {
return true;
}

// Also ignore mutations for the editable content wrapper
// element.
if (mutation.target === content) {
return true;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

return false;
},
},
)(this.props!) as ReturnType<BlockImplementation["render"]>;
} else {
Expand Down
Loading