-
Notifications
You must be signed in to change notification settings - Fork 19
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
useEditorEffect
runs before node views render
#40
Comments
Hmmmm.. Right. I think (it's been a minute) that the order of events is:
Does that match what you're experiencing? Can you share a bit more about what you're trying to do in your |
Yep, that matches my experience. Consider a widget that needs to reposition itself via |
In what component are you trying to use |
Right; if you need to obtain the coords of some position, you likely need to use |
So a few notes: I don't have dependencies declared on my effect. And the incorrect behavior i.e. the position not being computed correctly only happens when the nodeview is created or destroyed i.e. via input rule. Once it's in there, position gets computed correctly. I was building a repro of this, but I ran into a potentially more pressing bug. Here's the demo: https://stackblitz.com/edit/stackblitz-starters-ffsnxj?file=src%2FApp.tsx Repro:
The editor throws an error "The object cannot be found here". Looking at the console, looks like it some garbage collection issue since it's happening in native code. |
I think I've seen something similar even in the demo of this repo! I'll look into it and see if we can get that addressed as its own issue. Thanks! |
Ah, I missed this message previously. This is my problem. I'm doing the positioning in a child element of the editor but assuming the nodeviews are rendered when I perform that positioning. Is there a simple workaround here? Otherwise, I might either try rendering my widget as a part of the schema (ew) or having a context that node views call into after rendering (and then runs the positioning effect) |
The approach we've generally used is to just run the positioning code on every render, and if it can't find its target it can do nothing. I might be able to help more if I can make a reproduction. Ignoring the issue of deleting the first and only paragraph, can you build out the stack to show me what you're doing more? |
Just layout out some background for all of us here, to help understand what might be happening: The layout effect that updates the ProseMirror editor view is in the However, I find React's scheduler is a little bit hard to reason about sometimes. We can rely on it to flush the |
A little more information: to force group effects to run, we force an update in the layout group whenever an effect in the group needs to be created or destroyed. We try to do that conditionally, to limit re-renders. So, we don't force multiple updates in a single cycle. Unfortunately, during a top-down update of everything, React doesn't give us any good lifecycle hook for knowing that we're about to update anyway. If we could skip the forced update altogether, that might solve our problem, but I was too worried that any way we tried to do that would be too hacky and brittle. |
Sorry for the late message. I amended the stackblitz to do a repro, but oddly, I don't see the behavior I reported here. I'm going to dig into why later. Here's my demo. Basically, the red dot is supposed to be tracking the cursor. The behavior I'm seeing in my editor (the widget stops tracking as soon as a new node view is created e.g. as soon as I press enter) is not there but there's still a bug: The widget stops tracking if you do cmd-delete then start typing. In fact, it seems like the effect doesn't run at all (see logs). This only happens when the shortcut goes to the beginning of the node view: alt-backspace works fine if you're not going to the beginning of the paragraph, but if you are, it breaks in the same way as cmd-delete. |
It's also kind of in a weird spot when the doc is empty and the cursor is all the way at the beginning, but I can live with that. |
@tanishqkancharla Sorry that this has languished for so long without response, but your issues here and in #42 actually were the driving force behind the new architecture that we've been working on! If you have a moment, I would be interested to hear whether you're still seeing issues with this approach on the new beta version, |
No need to apologize @smoores-dev! This is open-source, after all :) I really appreciate the work you guys have put into this. Unfortunately, I think I'm still running into the problems: I modified the above demo to use the new beta version. As soon as i start typing, I get an error (position -1 out of range). If you look at the logs, it seems like |
Ah! Ok, I finally took a look at this. I highly recommend changing your schema from |
Ah yes you're completely right. That was a mistake on my part. Thanks! |
Hey! I noticed that
useEditorEffect
runs before node views have been rendered. This is causing a bug where the editor effect tries to do something that is only valid after the node view finishes rendering...have you all noticed/thought about this or have a recommended fix?I think I can cobble together a fix where I defer the effect by having a node view let a context know when it finishes rendering. And then I can run the effect. Seems a little hacky + similar to soemthing you guys have already with the
useLayoutGroupEffect
, although I'm not sure that's related. Any suggestions?The text was updated successfully, but these errors were encountered: