perf: Fix unneccessary re-rendering of link decorations affecting perf in documents with lots of links

This commit is contained in:
Tom Moor
2022-03-31 18:07:48 -07:00
parent a4c8c7d709
commit a1f69b97b0

View File

@@ -116,6 +116,11 @@ export default class Link extends Mark {
}
get plugins() {
const component = <OpenIcon color="currentColor" size={16} />;
const icon = document.createElement("span");
icon.className = "external-link";
ReactDOM.render(component, icon);
const getLinkDecorations = (doc: Node) => {
const decorations: Decoration[] = [];
const links = findLinkNodes(doc);
@@ -130,15 +135,13 @@ export default class Link extends Mark {
// place the decoration at the end of the link
nodeWithPos.pos + nodeWithPos.node.nodeSize,
() => {
const component = <OpenIcon color="currentColor" size={16} />;
const icon = document.createElement("span");
icon.className = "external-link";
ReactDOM.render(component, icon);
return icon;
console.log(icon);
return icon.cloneNode(true);
},
{
// position on the right side of the position
side: 1,
key: "external-link",
}
)
);