fix: Protect against view updates after destroyed in async uploads

This commit is contained in:
Tom Moor
2023-11-04 21:57:13 -04:00
parent ec79cab8b8
commit c76aa845f4

View File

@@ -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, {