-
Notifications
You must be signed in to change notification settings - Fork 48.4k
Add warning for rendering into container that was updated manually #10210
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
Merged
flarnie
merged 20 commits into
facebook:master
from
flarnie:testForEmptyingContainerOutsideOfReact
Jul 21, 2017
Merged
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
845d349
RFC Add warning for rendering into container that was updated manually
flarnie 72dfbaf
Add test and tweak check for rendering into manually updated container
flarnie a439ba6
Stub our `console.error` in one of the portal tests
flarnie 5a7da89
Skip warning in 'ReactDOMFiberEntry' when mounting to Comment node
flarnie cfd3c35
Improve warning message, remove dedup check, and unmock console.error
flarnie fff93e3
Possible fix for issue of incorrect warning for portal re-render
flarnie 178ac2b
Fix logic for checking if the host instance container is a portal
flarnie c9a6e6c
Clean up new tests in ReactDOMFiber-test
flarnie 194adf1
Add 'unmountComponentAtNode' call in test for reconciling pre-rendere…
flarnie a2fdfd2
ran prettier
flarnie 48f8f83
remove unused variable
flarnie 64ce334
run scripts/fiber/record-tests
flarnie c927309
Fix type error and improve name of portal container flag
flarnie 7f9648b
Add flag to portalContainer on mount instead of in `createPortal`
flarnie 2225b98
Force an 'any' type for the `hostInstance.parentNode` in warning check
flarnie f7efe64
Ignore portals in `DOMRenderer.findHostInstance`
flarnie e64c2c1
Ran prettier
flarnie 0b0035c
Remove error snapshot test
flarnie 178e1a4
Remove expando that we were adding to portal container
flarnie f9edf89
Fork `findHostInstance` to make `findHostInstanceWithNoPortals`
flarnie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
As suggested by @spicyj we could expose another method here that doesn't drill through portals. The problem with that is dead code elimination. It's a bit awkward that we expose a new method on the public Reconciler API that is only ever needed for a specific DEV warning.
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.
If it would be possible to write such a method, without adding a flag to the
portalContainer
node, then there must already be something we could look at here that would tell us if it's a portal. Is that right?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.
No because the portal is between the container and the hostInstance.
HostRoot -> ... -> HostPortal -> ... -> HostComponent
You'd have to traverse the Fibers to figure that out.
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.
Ah, ok. Interesting.
What is the advantage of adding another method to
DOMRenderer
rather than setting a boolean flag on theportalContainer
node?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 lets us not mutate the node in what seems to be a pure function.
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.
Does it help that we now do the mutating inside of
ReactFiberCommitWork
? That is where we do other DOM updates.If we really want to avoid adding this flag then I can implement another method on
DOMRenderer
but I think @sebmarkbage's point that "It's a bit awkward that we expose a new method on the public Reconciler API that is only ever needed for a specific DEV warning." is valid, and I'd rather avoid that.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.
In a situation like this:
render([<Portal />,<div />], container)
we'd find the portal node and then ignore checking the second one. So no warning if we mutated container. If we did @spicyj's suggestion, we could find all the direct children or at least the first one.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.
Good point - talked more with @spicyj offline also and it looks like we may also just be able to change this spot to filter portals out, and then we might not need a new method?
react/src/renderers/shared/fiber/ReactFiberTreeReflection.js
Line 245 in 7b9f643