Skip to content

Commit

Permalink
fix: React DOM crashes when <option> contains three interpolated valu…
Browse files Browse the repository at this point in the history
…e if one is a conditional. facebook#11911
  • Loading branch information
stephenkingsley committed Jan 23, 2018
1 parent 4d65408 commit 752acda
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/react-dom/src/__tests__/ReactDOMOption-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('ReactDOMOption', () => {
' in div (at **)\n' +
' in option (at **)',
);
expect(node.innerHTML).toBe('1 2');
expect(node.innerHTML).toBe('1 <div></div> 2');
ReactTestUtils.renderIntoDocument(el);
});

Expand Down
11 changes: 10 additions & 1 deletion packages/react-dom/src/client/ReactDOMFiberOption.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,17 @@ function flattenChildren(children) {
if (child == null) {
return;
}

if (typeof child === 'string' || typeof child === 'number') {
content += child;
if (typeof children === 'string') {
content += child;
} else {
if (!content) {
content = document.createElement('span');
}
const textNode = document.createTextNode(child);
content.appendChild(textNode);
}
}
});

Expand Down
24 changes: 12 additions & 12 deletions scripts/rollup/results.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,43 +46,43 @@
"filename": "react-dom.development.js",
"bundleType": "UMD_DEV",
"packageName": "react-dom",
"size": 569094,
"gzip": 133855
"size": 569227,
"gzip": 133885
},
{
"filename": "react-dom.production.min.js",
"bundleType": "UMD_PROD",
"packageName": "react-dom",
"size": 94278,
"gzip": 30883
"size": 94375,
"gzip": 30893
},
{
"filename": "react-dom.development.js",
"bundleType": "NODE_DEV",
"packageName": "react-dom",
"size": 553111,
"gzip": 130124
"size": 553244,
"gzip": 130155
},
{
"filename": "react-dom.production.min.js",
"bundleType": "NODE_PROD",
"packageName": "react-dom",
"size": 92696,
"gzip": 29923
"size": 92793,
"gzip": 29943
},
{
"filename": "ReactDOM-dev.js",
"bundleType": "FB_DEV",
"packageName": "react-dom",
"size": 571833,
"gzip": 132486
"size": 571966,
"gzip": 132522
},
{
"filename": "ReactDOM-prod.js",
"bundleType": "FB_PROD",
"packageName": "react-dom",
"size": 267496,
"gzip": 51395
"size": 267649,
"gzip": 51426
},
{
"filename": "react-dom-test-utils.development.js",
Expand Down

0 comments on commit 752acda

Please sign in to comment.