fix: Capture errors recreating transform and log, these are non-critical

This commit is contained in:
Tom Moor
2023-09-25 20:45:34 -04:00
parent 0014bcf22d
commit b1ddf417be

View File

@@ -2,6 +2,7 @@ import { EditorState, Plugin } from "prosemirror-state";
import { Decoration, DecorationSet } from "prosemirror-view"; import { Decoration, DecorationSet } from "prosemirror-view";
import * as React from "react"; import * as React from "react";
import ReactDOM from "react-dom"; import ReactDOM from "react-dom";
import Logger from "~/utils/Logger";
import FileExtension from "../components/FileExtension"; import FileExtension from "../components/FileExtension";
import { recreateTransform } from "./prosemirror-recreate-transform"; import { recreateTransform } from "./prosemirror-recreate-transform";
@@ -13,17 +14,22 @@ const uploadPlaceholder = new Plugin({
}, },
apply(tr, set: DecorationSet) { apply(tr, set: DecorationSet) {
const ySyncEdit = !!tr.getMeta("y-sync$"); const ySyncEdit = !!tr.getMeta("y-sync$");
let mapping = tr.mapping;
if (ySyncEdit) { if (ySyncEdit) {
const mapping = recreateTransform(tr.before, tr.doc, { try {
complexSteps: true, mapping = recreateTransform(tr.before, tr.doc, {
wordDiffs: false, complexSteps: true,
simplifyDiff: true, wordDiffs: false,
}).mapping; simplifyDiff: true,
set = set.map(mapping, tr.doc); }).mapping;
} else { } catch (err) {
set = set.map(tr.mapping, tr.doc); Logger.warn("Failed to recreate transform", err);
}
} }
set = set.map(mapping, tr.doc);
// See if the transaction adds or removes any placeholders // See if the transaction adds or removes any placeholders
const action = tr.getMeta(this); const action = tr.getMeta(this);