From a1f69b97b09c40ed8e793387b21fa1e81c034dcc Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 31 Mar 2022 18:07:48 -0700 Subject: [PATCH] perf: Fix unneccessary re-rendering of link decorations affecting perf in documents with lots of links --- shared/editor/marks/Link.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/shared/editor/marks/Link.tsx b/shared/editor/marks/Link.tsx index 1460cc260..b548a667f 100644 --- a/shared/editor/marks/Link.tsx +++ b/shared/editor/marks/Link.tsx @@ -116,6 +116,11 @@ export default class Link extends Mark { } get plugins() { + const component = ; + 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 = ; - 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", } ) );