-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Secondary Suspense causing view to be prematurely destroyed #101
Comments
So I can think of two approaches to this. The first feels kind of clunky: we could completely replace the view in the useLayoutEffect if it has been destroyed (which we can determine by inspecting the const directEditorPropsRef = useRef(directEditorProps);
directEditorPropsRef.current = directEditorProps;
const mountRef = useRef(mount);
mountRef.current = mount;
const [view, setView] = useState<EditorView | null>(null);
useLayoutEffect(() => {
if (view && !view.docView) {
if (mountRef.current) {
setView(
new EditorView(
{ mount: mountRef.current },
directEditorPropsRef.current
)
);
}
}
return () => {
if (view) {
view.destroy();
}
};
}, [view]); The second option would be to do the |
Hi! I went through the stack trace and saw the same problem which was described by @ariellebryn (we also use Suspense). @smoores-dev I think both of your ideas are ok, the second one looks a bit more reliable but it's needed to be tested. Btw why do you call Anyways, I'll be happy if you release the fix, thanks! |
We call The issue here is that Suspense calls the layout effect cleanups without unmounting the component. Looking closer though, I'm increasingly feeling like the underlying problem here is actually that we don't set the editor view to null in a cleanup function; we do it in the effect itself. I think this is wrong, is probably separately an issue, and if we fixed it, would also fix this issue. I'll see if I can open a PR for this today! |
In exploring using suspense on a page that has a react-prosemirror field, I'm running into an error when: the page loads, then suspends for some reason, then un-suspends.
This seems to be what's happening:
<ProseMirror>
componentuseLayoutEffect
to run:view.destroy();
, even though the component isn't actually unmountingEditorView
(that haddestroy()
called on it), but now thatview
is missing key fields!The text was updated successfully, but these errors were encountered: