-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Slate throws exceptions too liberally in relation to selection failures #3641
Comments
Perhaps some error handling could be relaxed, but I personally don't have a strong opinion. However, I can't help but wonder why people aren't catching the errors and letting the page crash? https://reactjs.org/blog/2017/07/26/error-handling-in-react-16.html |
Hi @CameronAckermanSEL, I use Slate seems to think it has to do something based on every interaction with the editor otherwise there is a bug but I don't think this is right. I guess raising errors was just the easiest approach for the library devs when trying to get 0.50 ready but I don't think this is the best longterm approach for the library consumers who should ideally decide what is critical and what is not. |
So far the only error that have been really problematic for me is this one (Cannot resolve a DOM point from Slate point): Tracked in own issue here: #3575 It makes collaborative editing near impossible, because as far as I can tell, there is no way we are able to adjust the selection when a new value is coming in through props before |
@skogsmaskin I've been working around it by storing the selection, then doing const contenteditableElement: any = window
.getSelection()
?.anchorNode?.parentElement?.closest("[contenteditable]").blur(); then changing the value, and afterwards restoring the selection I am not suggesting this horrible hack as a viable workaround. I have been using this because I am super annoyed at this bug and wanted to move on to something else while still avoiding the crashes. |
A tale from a developers first experience with slate: We researched a buch of richtext editors and decided that slate would make the best fit for our prupose (react-admin and a custom markdown editor). We followed the installation guide and the first thing that hit us was the very error message @skogsmaskin erorted as #3575. I've seen a fix in a fork from @mpkelly but that's no long term fix. My 2 cents are: When slate throws an error, it should not take the application down with it. And for the specific error #3575 a smart default would fix most cases. |
@karlludwigweise my fork wasn't intended to fix #3575 per se but only stop Slate from raising errors for things my app does not care about, like clicking on some structural HTML elements. I still think Slate should be changed to return Should also point out that my fork is a quick and dirty fix done with a simple code search. It was not intended to be a community fix and I only mentioned it above to make it clear which parts of the Slate codebase I think should be changed. |
Still need to reiterate that exceptions are catchable via react lifecycle events. It is possible for these selection problems to be caught and dealt with. I hate to be blunt here, but in my opinon if the developer is allowing slate to crash their application, then that's on the developer. I also suspect that many of these errors can be pre-empted with checks before applying an OT in the case of collaborative editing. But unfortunately, there aren't a lot of provided reproductions of the problem. I have a few things I want to respond to and points I want to make:
I am thinking that it's probably better in the long run to close this issue and lock discussion in favor of splitting this up into more specific instances of this problem. Interested in people's thoughts. Thanks! |
Current categories of selection failures (from this thread):
Suggestions:
|
I was developing an editor with Slate and React, but found several situations where I can not avoid the errors thrown by it: for example, when using Katex library to render math formulas. Of course we can add an error boundary to the Just wonder if there was some work done in the direction mentioned by @mpkelly and @cameracker |
I don't believe much has progressed in this area, though the topic does come up pretty regularly, and along with things like #4769 . It's an area I too would like to see improve this year. |
Thanks for the response @dylans. I'll we looking forward for it: in its current implementation we can not go to production with slate due to this issue. |
@antondc I've been using katex for math rendering and haven't run into the issues you mentioned. If you can post a reproducible example on codepen or something that would be useful. I do think the error could be more detailed sometimes and provide a path of action for resolving it. |
Discussed with @12joan on that one. We've ended up on a design that uses a separate "staging" editor that is not rendered:
The goal is to have a system that prevents:
The alternative would have been to not use a staging editor and "rollback" faulty operations but I'm not comfortable with implementing that design. As for the error throwing debate, there are many opinions:
For functions having PR is WIP. |
Could you share an example on how you use Katex with the Editor please ? |
Addressed in #5407 |
Hello,
I would like to start a discussion about error handling in Slate which I think is too strict as Errors are often thrown for things that could just as easily be ignored or replaced by a warning. These are in functions like
toDOMPoint
ortoSlateRange
when Slate is trying to do things like map aHTMLElement
to aNode
but cannot because there is no direct mapping (theHTMLElement
is created indirectly by a SlateNode
). In many cases Slate will throw anError
that will take down the whole page. I understand that various attributes can be applied to have Slate ignore certain regions of the editor but I've still found it a bit of a fight and I really don't understand why Slate can't just return early in cases where no DOM-to-Slate mapping exists. In fact, I have forked Slate and disabled these Errors (here and here) and made Slate return early and while this fork is a WIP, I can tell you that my app is much better for it - it's less work for me and I will still find problems where things aren't wired-up correctly and I no longer have anxiety of deploying to production and worrying about the WSOD when the user's only crime was clicking on an empty<div/>
(I know prod apps should have error handling but again it feels like I am having to handle more errors than is really necessary).Some ideas:
Error
when it is absolutely necessary (cannot be recovered/ignored).onError
callback to its API for users to learn about errorsThoughts?
The text was updated successfully, but these errors were encountered: