From c76aa845f4dffd7a2f724999a863bd2677d44344 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 4 Nov 2023 21:57:13 -0400 Subject: [PATCH] fix: Protect against view updates after destroyed in async uploads --- shared/editor/commands/insertFiles.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/shared/editor/commands/insertFiles.ts b/shared/editor/commands/insertFiles.ts index a1941d066..0af48d777 100644 --- a/shared/editor/commands/insertFiles.ts +++ b/shared/editor/commands/insertFiles.ts @@ -81,6 +81,9 @@ const insertFiles = function ( // happening in the background in parallel. uploadFile?.(upload.file) .then(async (src) => { + if (view.isDestroyed) { + return; + } if (upload.isImage) { const newImg = new Image(); newImg.onload = () => { @@ -88,6 +91,9 @@ const insertFiles = function ( if (result === null) { return; } + if (view.isDestroyed) { + return; + } const [from, to] = result; view.dispatch( @@ -115,6 +121,10 @@ const insertFiles = function ( const [from, to] = result; const dimensions = await FileHelper.getVideoDimensions(upload.file); + if (view.isDestroyed) { + return; + } + view.dispatch( view.state.tr .replaceWith( @@ -159,6 +169,10 @@ const insertFiles = function ( // eslint-disable-next-line no-console console.error(error); + if (view.isDestroyed) { + return; + } + // cleanup the placeholder if there is a failure view.dispatch( view.state.tr.setMeta(uploadPlaceholderPlugin, {