-
Notifications
You must be signed in to change notification settings - Fork 50.4k
Only reuse server-rendered React nodes if there are no unexpected siblings #1912
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
Conversation
|
what should i expect if i use server side to render version of the page which wasn't done with react that anyway is a bit different from the react server? |
|
@oriSomething React require identical markup to reuse server-render nodes, but that is not what this PR addresses, this is just about an edge-case some people have gotten confused by. |
|
This throws if you have any existing markup in the element, regardless of if it was produced using React's server rendering? Seems a little aggressive. |
@spicyj :) |
|
Can you add a test for that? |
src/browser/ui/ReactMount.js
Outdated
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.
this should really be a warning since it's dev-only.
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.
Can do, I was a bit unsure and did a quick search, found a file using invariant in dev and didn't think more about it. We really should allow people to turn some warnings into errors though, because this is a clear case of "you really don't want to do/miss this".
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.
Fixed (wups, gotta fix test too, EDIT: fixed).
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.
What file does dev-only invariants?
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.
|
@spicyj Added. |
Warn if mounting into node with dirty rendered markup
PR for #996
I choose to believe that users should be correcting their own "mistakes", rather than have React transparently fix and unknowingly introduce weird edge-cases and visual artifacts.
Quite simply, this PR enforces that there are no other nodes except the node rendered by React inside the target, it obviously does not warn if there isn't a node rendered by React inside the target. It only performs this check in DEV.
There is another test in #1903 which complements this PR.