-
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
Warn when normalization removes node #4769
Conversation
🦋 Changeset detectedLatest commit: 1ee0fb1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Slate requires the invariant that children are all blocks or all inlines. It enforces this in default normalization by removing children. When such a node is removed, it's almost certainly due to a programming error: the developer needs to fix their application to ensure it maintains this invariant. But currently Slate does not tell the developer this. I made such a programming error, and spent a long time debugging nodes that mysteriously went missing. I would have fixed it within 30 seconds if Slate had warned me when it detected this error. (Note I have used console.warn despite the eslint rule. As far as I can see, Slate has no other facility for runtime warnings.)
c20580f
to
8b63af1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent suggestion, I've been a victim of this as well.
I disagree with how this is implemented. Strongly. Slate core does not emit warnings; that lint rule is there for a reason. The core is used by a variety of editors, not just In particular, collaborative editors can end up in all sorts of weird states that require normalization to fix. This is normal behaviour, I would like to see this reverted (or I can do it) and we look for another way to handle the scenario. Some vague ideas:
|
@TheSpyder ok, no problem, reverting now. I would vote for option 2 if feasible. |
@TheSpyder what's the reason, more explicitly? That you don't want warnings emitted in production? The point about collaborative editing is interesting - I'm not dealing with those kinds of problems. For context, here's how React does it. I think this resembles @TheSpyder's option 3. It seems to work well. Perhaps we can use/copy/steal it. |
Pretty much. Slate is a framework to build editors, and I don’t like frameworks that emit console logs.
React also has separate production and development builds. I’m not sure we want to go that far. I guess the |
* Warn when normalization removes node Slate requires the invariant that children are all blocks or all inlines. It enforces this in default normalization by removing children. When such a node is removed, it's almost certainly due to a programming error: the developer needs to fix their application to ensure it maintains this invariant. But currently Slate does not tell the developer this. I made such a programming error, and spent a long time debugging nodes that mysteriously went missing. I would have fixed it within 30 seconds if Slate had warned me when it detected this error. (Note I have used console.warn despite the eslint rule. As far as I can see, Slate has no other facility for runtime warnings.) * Add changeset
* Warn when normalization removes node Slate requires the invariant that children are all blocks or all inlines. It enforces this in default normalization by removing children. When such a node is removed, it's almost certainly due to a programming error: the developer needs to fix their application to ensure it maintains this invariant. But currently Slate does not tell the developer this. I made such a programming error, and spent a long time debugging nodes that mysteriously went missing. I would have fixed it within 30 seconds if Slate had warned me when it detected this error. (Note I have used console.warn despite the eslint rule. As far as I can see, Slate has no other facility for runtime warnings.) * Add changeset
Description
Slate requires the invariant that children are all blocks or all inlines. It enforces this in default normalization by removing children. When such a node is removed, it's almost certainly due to a programming error: the developer needs to fix their application to ensure it maintains this invariant. But currently Slate does not tell the developer this.
I made such a programming error, and spent a long time debugging nodes that mysteriously went missing. I would have fixed it within 30 seconds if Slate had warned me when it detected this error.
Context
Note I have used
console.warn
despite the eslint rule. As far as I can see, Slate has no other facility for runtime warnings.Checks
yarn test
.yarn lint
. (Fix errors withyarn fix
.)yarn start
.)yarn changeset add
.)