Skip to content
Open
Changes from all commits
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
38 changes: 38 additions & 0 deletions packages/react/src/schema/ReactBlockSpec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,44 @@ 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 attribute mutations for the editable content
// wrapper element. These include class names & other
// attributes set via `contentRef`. Other mutations such as
// `childList` are still valid.
if (
mutation.target === content &&
mutation.type === "attributes"
) {
return true;
}

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