Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Secondary Suspense causing view to be prematurely destroyed #101

Open
ariellebryn opened this issue Feb 15, 2024 · 0 comments
Open

Secondary Suspense causing view to be prematurely destroyed #101

ariellebryn opened this issue Feb 15, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ariellebryn
Copy link
Contributor

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:

  • The page loads, including the <ProseMirror> component
  • The page suspends for some reason (in my case, I was triggering a refetch and had put the Suspense boundary at a higher level)
    • When React suspends, it calls the cleanup function of layout effects! In their words: "If React needs to hide the already visible content because it suspended again, it will clean up layout Effects in the content tree. When the content is ready to be shown again, React will fire the layout Effects again. This ensures that Effects measuring the DOM layout don’t try to do this while the content is hidden."
  • This causes the cleanup function of this useLayoutEffect to run: view.destroy();, even though the component isn't actually unmounting
  • When suspense ends and the component is re-rendered (with the rest of its state maintained), it still has access to the EditorView (that had destroy() called on it), but now that view is missing key fields!
@ariellebryn ariellebryn added the bug Something isn't working label Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant