Skip to content

Commit

Permalink
[lexical] surface more error details in reconciler (#6511)
Browse files Browse the repository at this point in the history
  • Loading branch information
potatowagon authored Aug 12, 2024
1 parent 3f79ca0 commit db4c743
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions packages/lexical/src/LexicalReconciler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,18 @@ function reconcileElementTerminatingLineBreak(
const element = dom.__lexicalLineBreak;

if (element != null) {
dom.removeChild(element);
try {
dom.removeChild(element);
} catch (error) {
if (typeof error === 'object' && error != null) {
const msg = `${error.toString()} Parent: ${dom.tagName}, child: ${
element.tagName
}.`;
throw new Error(msg);
} else {
throw error;
}
}
}

// @ts-expect-error: internal field
Expand Down Expand Up @@ -501,7 +512,22 @@ function $reconcileChildren(
} else {
const lastDOM = getPrevElementByKeyOrThrow(prevFirstChildKey);
const replacementDOM = $createNode(nextFrstChildKey, null, null);
dom.replaceChild(replacementDOM, lastDOM);
try {
dom.replaceChild(replacementDOM, lastDOM);
} catch (error) {
if (typeof error === 'object' && error != null) {
const msg = `${error.toString()} Parent: ${
dom.tagName
}, new child: {tag: ${
replacementDOM.tagName
} key: ${nextFrstChildKey}}, old child: {tag: ${
lastDOM.tagName
}, key: ${prevFirstChildKey}}.`;
throw new Error(msg);
} else {
throw error;
}
}
destroyNode(prevFirstChildKey, null);
}
const nextChildNode = activeNextNodeMap.get(nextFrstChildKey);
Expand Down

0 comments on commit db4c743

Please sign in to comment.