-
Notifications
You must be signed in to change notification settings - Fork 47.7k
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
fix renderToString fails with array type children when react-dom/server render #10221
Changes from 8 commits
790e65a
c2aeb06
6fd78e5
4b28bc1
f652ed7
322fa40
deb11af
62c042e
6b4eb0e
e53e552
eafb4bd
3df964d
6f7f142
02101d5
d661c5a
97575fd
e0bd356
1d45bae
5f8a2dd
cf005dd
7f5c0a1
60e7e3e
e4dd558
59e0843
5539f09
06d9971
b42dd08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -307,8 +307,6 @@ function createOpenTagMarkup( | |
} | ||
|
||
function resolve(child, context) { | ||
// TODO: We'll need to support Arrays (and strings) after Fiber is rolled out | ||
invariant(!Array.isArray(child), 'Did not expect to receive an Array child'); | ||
while (React.isValidElement(child)) { | ||
if (__DEV__) { | ||
pushElementToDebugStack(child); | ||
|
@@ -416,7 +414,7 @@ function resolve(child, context) { | |
class ReactDOMServerRenderer { | ||
constructor(element, makeStaticMarkup) { | ||
var topFrame = { | ||
children: [element], | ||
children: Array.isArray() ? element : [element], | ||
childIndex: 0, | ||
context: emptyObject, | ||
footer: '', | ||
|
@@ -484,6 +482,19 @@ class ReactDOMServerRenderer { | |
if (child === null || child === false) { | ||
return ''; | ||
} else { | ||
if (Array.isArray(child)) { | ||
var frame = { | ||
children: child, | ||
childIndex: 0, | ||
context: context, | ||
footer: '', | ||
}; | ||
if (__DEV__) { | ||
frame.debugElementStack = []; | ||
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. Why do we need to do this? (Note: I'm not very familiar with this code so I'm learning it too.) 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. "setCurrentDebugStack" method will set debugElementStack.length = 1, This is to init the debugElementStack array. The same method handles when HostCompoment return array type children.https://github.com/facebook/react/blob/master/src/renderers/shared/server/ReactPartialRenderer.js#L769 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. Do warnings still work? You can add a test similar to this one but using an array. 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. @gaearo, It's done. Please review. |
||
} | ||
this.stack.push(frame); | ||
return ''; | ||
} | ||
return this.renderDOM(child, context); | ||
} | ||
} | ||
|
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'm not sure this is sufficient. For example it could be a nested array. Conversely, it could be an array of invalid things (e.g. array of objects), and we'd want to throw in that case.
I think the validation should be moved to a further stage at the point where we actually process the next frame. Which is the same strategy we do with Fiber. This way we don’t do validation immediately, but we throw if we meet something invalid.
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 think here can use 'React.Children.toArray' method to deal with this situation.
[[<Hello />,<Dan />],<Cool />] => [<Hello />,<Dan />,<Cool />]
if disableNewFiberFeatures=false then don't do validation immediately.