-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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 1 commit
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 |
---|---|---|
|
@@ -20,7 +20,6 @@ let ReactDOM; | |
let ReactDOMServer; | ||
let ReactDOMNodeStream; | ||
let ReactTestUtils; | ||
let ReactFeatureFlags; | ||
|
||
const stream = require('stream'); | ||
|
||
|
@@ -289,8 +288,6 @@ function expectMarkupMismatch(serverElement, clientElement) { | |
let onAfterResetModules = null; | ||
function resetModules() { | ||
jest.resetModuleRegistry(); | ||
ReactFeatureFlags = require('ReactFeatureFlags'); | ||
ReactFeatureFlags.disableNewFiberFeatures = false; | ||
PropTypes = require('prop-types'); | ||
React = require('react'); | ||
ReactDOM = require('react-dom'); | ||
|
@@ -333,16 +330,18 @@ describe('ReactDOMServerIntegration', () => { | |
}); | ||
|
||
if (ReactDOMFeatureFlags.useFiber) { | ||
itRenders('a array type children as a child', async render => { | ||
class AppComponent extends React.Component { | ||
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. We still need this test because it tests both server and client. 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. hmm. Has been resolved, It can test passed both server and client. There is no warning. |
||
render() { | ||
return [<div key={1}>text1</div>, <p key={2}>text2</p>]; | ||
} | ||
} | ||
const e = await render(<AppComponent />); | ||
const parentNode = e.parentNode; | ||
expect(parentNode.childNodes[0].tagName).toBe('DIV'); | ||
expect(parentNode.childNodes[1].tagName).toBe('P'); | ||
it('a array type children as a child', () => { | ||
spyOn(console, 'error'); | ||
let markup = ReactDOMServer.renderToString([ | ||
<div key={1}>text1</div>, | ||
<p key={2}>text2</p>, | ||
]); | ||
|
||
const root = document.createElement('div'); | ||
root.innerHTML = markup; | ||
expect(root.childNodes[0].tagName).toBe('DIV'); | ||
expect(root.childNodes[1].tagName).toBe('P'); | ||
expectDev(console.error.calls.count()).toBe(0); | ||
}); | ||
} | ||
}); | ||
|
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.