Closed colin-jiang closed 1 week ago
As far as I can tell this looks like a bug in next.js, the minifier is doing an incorrect rename
Here's a segment of the production code that's broken:
Here are just the relevant parts:
function so(t, e) {
const r = t._rootElement;
if (…) {
try {
const o = t._dirtyLeaves;
} catch (o) {
return;
} finally {
g.observe(o, Hr);
}
}
}
This is the original (only relevant parts):
export function commitPendingUpdates(
editor: LexicalEditor,
recoveryEditorState?: EditorState,
): void {
const rootElement = editor._rootElement;
if (…) {
try {
const dirtyLeaves = editor._dirtyLeaves;
} catch (error) {
return;
} finally {
observer.observe(rootElement as Node, observerOptions);
}
}
}
It looks like there's an unsafe and incorrect renaming in the production output. Maybe upgrading next.js would help fix this, I don't think there's anything that can be done in lexical to work around it.
This is what lexical's prod build looks like, which would be what next.js's minifier is using as input and explains why next.js got this wrong in this specific way.
function Vi(t, n) {
const i = t._rootElement;
if (...) {
try {
const i = t._dirtyLeaves;
} catch (e) {
return;
} finally {
g.observe(i, Ii);
}
}
}
A correct minifier implementation would realize that the try {}
and finally {}
do not have the same scope.
You can try it yourself in any JavaScript implementation:
(() => { const i = 'outer'; try { const i = 'inner'; } finally { console.log(i); } })()
outer
If anyone else is seeing this: I've heard reports that the swc minifier does not have this bug, and it's the default minifier in the latest version of next.js.
I'm getting a MutationObserver production error when using Lexical 0.14, I can't reproduce it on localhost and it fails only in production when I deploy to Vercel. This error goes away once I revert to Lexical 0.13
Error message: TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'
Example repo reproducing this issue: https://github.com/colin-jiang/lexical-mutationobserver-bug
Steps To Reproduce
Dependencies listed in package.json Next.js page router and Next.js version 12.0.9.
The current behavior
Lexical editor throws error on load when deployed, no error on localhost
The expected behavior
No error