-
Notifications
You must be signed in to change notification settings - Fork 18
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
Deleting the last node view can throw errors #42
Comments
In trying to diagnose this, I've determined that the basic keymap from |
This seems to vary depending on which elements are This is really unfortunate and is one of the real problems with using the mutation model from prosemirror-view as opposed to the more modern |
Interestingly, adding |
Firefox seems to have no trouble, with or without |
Okay, I can confirm that when we have
and we delete the If we add This is going to require more thinking. It probably isn't a problem with more complex node views where the non-content parts aren't editable, but for simple node views this is a real problem. We haven't run into this internally since we're still using a different, hacky, implementation for these kinds of node views that we were maybe hoping to move away from. |
Just making sure I'm getting this right; the result of these mutations is the following?
|
I think that's right, yes. |
I'm also experiencing this issue. I have a simple schema with a NodeView that reads attributes from the node to determine styles for a wrapping
and I delete the
This is causing the Node to still exist in the view, but it is not editable or selectable. I would expect to see the following DOM tree get created as a result:
The difference is that the regular backspacing inserts this non-styled I'm running this on the latest version of Chrome. Even more interesting, I don't seem to be able to reproduce this consistently - either it will always produce the first output, or it will always produce the second output. If I could get some direction on what may be causing this, please let me know. |
I don't think this is a problem we can solve. I would suggest avoiding single-element node views for the moment, until we can ship something much more comprehensive like #47. We'll try to document the limitations in the next weeks and make the roadmap more clear. |
I'm finding that running the code on #47 locally, I still see the DOM errors we've encountered here. I'm not yet sure what to make of that, but figured I'd share here, by way of maybe hypothesizing that it's possible that this issue isn't 100% solved by moving over to React-managed views. |
@jcayabyab I've also seen something similar, and what I found is that it looks like the DOM mutations produced by the browser (later picked up by ProseMirrors' MutationObserver, and forwarded thru react-prosemirror) are sometimes unexpected or incorrect, in a way that seems to vary depending on the specific HTML structure of the node view and child toDOM. To wit, with a node view configuration for a node whose schema is ....this configuration produces the error in this issue (note that the const reactNodeViews: Record<string, ReactNodeViewConstructor> = {
myNode: () => ({
component: ({ children }) => <div><p>Some uneditable text</p><div>{children}</div></div>,
dom: document.createElement("div"),
contentDOM: document.createElement("div"),
}),
};
// produces a DOM that looks like: <div><p>Some uneditable text</p><div><div><span>inline content</span></div></div></div> ....a slightly different configuration — with a const reactNodeViews: Record<string, ReactNodeViewConstructor> = {
myNode: () => ({
component: ({ children }) => <div><p>Some uneditable text</p><div>{children}</div></div>,
dom: document.createElement("div"),
contentDOM: document.createElement("span"),
}),
};
// produces a DOM that looks like: <div><p>Some uneditable text</p><div><span><span>inline content</span></span></div></div> ....I found, at least in my case, that ensuring the const reactNodeViews: Record<string, ReactNodeViewConstructor> = {
myNode: () => ({
component: ({ children }) => <div><p>Some uneditable text</p><div>{children}</div></div>,
dom: document.createElement("div"),
contentDOM: document.createElement("p"),
}),
};
// produces a DOM that looks like: <div><p>Some uneditable text</p><div><p><span>inline content</span></p></div></div> |
I wouldn't be terribly surprised. It's possible the mutation-based approached might simply not work with React and we absolutely need proper |
@smoores-dev, if I recall correctly, you started looking into the mutation-based approached to try to minimize diff with prosemirror-view and also support mobile. Does what I'm speculating about mutations make sense to you? Do you think it makes sense just to draw a line and say that we only support browsers with proper editing events implementations? |
I have to look into this a bit more; @saranrapjs what are you running locally, exactly, that you're seeing these errors? I can reproduce this if I'm using the ProseMirror View-style node views (which is not surprising, and I don't know that we'll be able to get around that), but I don't see it with the React-based ones. It would be possible to switch back to beforeinput, yes; on the whole, I suspect that would be a good move, if we're comfortable with the limitations. But I'm not totally sure that I am comfortable with the limitations?? (and yes, to be clear, we moved away from beforeinput because Chrome-on-Android's beforeinput implementation is completely broken). Ugh. Definitely interested in hearing others' thoughts. |
On the |
Though I'm finding that this error gets thrown when deleting near a mark boundary, and in the demo I think only paragraphs have a defined nodeView — so maybe your assumption still stands, that this only should happen on |
Ah, ok, thanks; I had been deleting entire paragraphs at a time, but deleting only a character at a time I'm also seeing that error when I get to the marks. Marks are also rendered with React on that branch, though; unless you click the "Switch to ProseMirror node views" button, everything is being rendered with the new React components, regardless of whether there are custom node views defined or not. I can take a look at this this week and see if there's anything obvious, but @tilgovi's right that this behavior definitely comes from the DOMObserver/MutationObserver implementation, and isn't a problem with the beforeinput-based approach. The beforeinput approach also makes IME input trivial (it just works, with no special handling necessary), whereas someone just identified a lingering IME bug in Chrome with the DOMObserver implementation (in #41). @saranrapjs what's your gut reaction to this library basically not supporting Android Chrome? |
Ah, actually what I'm seeing is that the error shows up when I get into the inline decoration, not the marks. I actually have on my list of things to do to look into some DOMObserver related issues with inline decorations, so this might not be as much of a concern/show-stopper as it seems, actually. |
I just posted this in Gitter, but I just learned that Slate.js (which also relies on
https://docs.slatejs.org/general/faq#what-browsers-and-devices-does-slate-support So I might take a look into what they're doing there! |
I can try to find out whether Chrome on Android is likely to align better soon. |
While we're evaluating how the new architecture should handle this, I think I have a fix that should work within the architecture on |
@saranrapjs thank you for resolving this! I'm going to call this closed, as it's fixed by #62 and released in v0.4.0. @jcayabyab please give that a shot! Note that there is a breaking change in there; React node views no longer get their position as a prop, instead they can use the |
As reported in #40 (comment), deleting the last character in the only remaining node view can throw errors. This is reproducible in the provided demo.
The text was updated successfully, but these errors were encountered: