Skip to content

Commit 523c864

Browse files
mejo-backportbot-nextcloud[bot]
authored andcommitted
Prevent dangling debounced extractHeadings function
Our Tiptap heading extension registers a debounced extractHeadings function for onUpdate. If the editor gets removed but a debounced extractHeadings call is still pending, this leads to errors (which sometimes break tests). So let's check whether the editor is still alive and only call debounced extractHeadings in this case. Signed-off-by: Jonas <[email protected]>
1 parent 2843e00 commit 523c864

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/nodes/Heading/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,11 @@ const Heading = TipTapHeading.extend({
6161
}
6262
},
6363

64-
onUpdate: debounce(function onUpdate({ editor }) {
65-
extractHeadings(editor)
64+
onUpdate: debounce(({ editor }) => {
65+
if (editor.view && editor.state && !editor.isDestroyed) {
66+
// Only run if editor still exists (prevent dangling debounced extractHeadings function)
67+
extractHeadings(editor)
68+
}
6669
}, 900),
6770

6871
})

0 commit comments

Comments
 (0)