-
Notifications
You must be signed in to change notification settings - Fork 47.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
Prevent infinite loop when SSR-rendering a portal #11709
Merged
Merged
Changes from all commits
Commits
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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,12 @@ import warning from 'fbjs/lib/warning'; | |
import checkPropTypes from 'prop-types/checkPropTypes'; | ||
import describeComponentFrame from 'shared/describeComponentFrame'; | ||
import {ReactDebugCurrentFrame} from 'shared/ReactGlobalSharedState'; | ||
import {REACT_FRAGMENT_TYPE} from 'shared/ReactSymbols'; | ||
import { | ||
REACT_FRAGMENT_TYPE, | ||
REACT_CALL_TYPE, | ||
REACT_RETURN_TYPE, | ||
REACT_PORTAL_TYPE, | ||
} from 'shared/ReactSymbols'; | ||
|
||
import { | ||
createMarkupForCustomAttribute, | ||
|
@@ -585,6 +590,27 @@ class ReactDOMServerRenderer { | |
if (nextChild === null || nextChild === false) { | ||
return ''; | ||
} else if (!React.isValidElement(nextChild)) { | ||
if (nextChild != null && nextChild.$$typeof != null) { | ||
// Catch unexpected special types early. | ||
const $$typeof = nextChild.$$typeof; | ||
invariant( | ||
$$typeof !== REACT_PORTAL_TYPE, | ||
'Portals are not currently supported by the server renderer. ' + | ||
'Render them conditionally so that they only appear on the client render.', | ||
); | ||
invariant( | ||
$$typeof !== REACT_CALL_TYPE && $$typeof !== REACT_RETURN_TYPE, | ||
'The experimental Call and Return types are not currently ' + | ||
'supported by the server renderer.', | ||
); | ||
// Catch-all to prevent an infinite loop if React.Children.toArray() supports some new type. | ||
invariant( | ||
false, | ||
'Unknown element-like object type: %s. This is likely a bug in React. ' + | ||
'Please file an issue.', | ||
($$typeof: any).toString(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't just pass |
||
); | ||
} | ||
const nextChildren = toArray(nextChild); | ||
const frame: Frame = { | ||
domNamespace: parentNamespace, | ||
|
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.
I used a switch here at first but Flow and ESLint started fighting over presence of
break
s (which are technically unreachable). This is shorter anyway. It's not a hot path (always errs).