Skip to content

Commit fa0625b

Browse files
committed
Fix multiple text nodes in an option tag
1 parent cd905f1 commit fa0625b

File tree

3 files changed

+5
-50
lines changed

3 files changed

+5
-50
lines changed

packages/react-dom/src/client/ReactDOMFiberComponent.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ export function setInitialProperties(
499499
break;
500500
case 'option':
501501
ReactDOMFiberOption.validateProps(domElement, rawProps);
502-
props = ReactDOMFiberOption.getHostProps(domElement, rawProps);
502+
props = rawProps;
503503
break;
504504
case 'select':
505505
ReactDOMFiberSelect.initWrapperState(domElement, rawProps);
@@ -581,11 +581,6 @@ export function diffProperties(
581581
nextProps = ReactDOMFiberInput.getHostProps(domElement, nextRawProps);
582582
updatePayload = [];
583583
break;
584-
case 'option':
585-
lastProps = ReactDOMFiberOption.getHostProps(domElement, lastRawProps);
586-
nextProps = ReactDOMFiberOption.getHostProps(domElement, nextRawProps);
587-
updatePayload = [];
588-
break;
589584
case 'select':
590585
lastProps = ReactDOMFiberSelect.getHostProps(domElement, lastRawProps);
591586
nextProps = ReactDOMFiberSelect.getHostProps(domElement, nextRawProps);

packages/react-dom/src/client/ReactDOMFiberOption.js

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,8 @@
77
* @flow
88
*/
99

10-
import React from 'react';
1110
import warning from 'fbjs/lib/warning';
1211

13-
function flattenChildren(children) {
14-
let content = '';
15-
16-
// Flatten children and warn if they aren't strings or numbers;
17-
// invalid types are ignored.
18-
// We can silently skip them because invalid DOM nesting warning
19-
// catches these cases in Fiber.
20-
React.Children.forEach(children, function(child) {
21-
if (child == null) {
22-
return;
23-
}
24-
if (typeof child === 'string' || typeof child === 'number') {
25-
content += child;
26-
}
27-
});
28-
29-
return content;
30-
}
31-
3212
/**
3313
* Implements an <option> host component that warns when `selected` is set.
3414
*/
@@ -50,14 +30,3 @@ export function postMountWrapper(element: Element, props: Object) {
5030
element.setAttribute('value', props.value);
5131
}
5232
}
53-
54-
export function getHostProps(element: Element, props: Object) {
55-
const hostProps = {children: undefined, ...props};
56-
const content = flattenChildren(props.children);
57-
58-
if (content) {
59-
hostProps.children = content;
60-
}
61-
62-
return hostProps;
63-
}

packages/react-dom/src/server/ReactPartialRenderer.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -830,13 +830,12 @@ class ReactDOMServerRenderer {
830830
} else if (tag === 'option') {
831831
var selected = null;
832832
var selectValue = this.currentSelectValue;
833-
var optionChildren = flattenOptionChildren(props.children);
834833
if (selectValue != null) {
835834
var value;
836835
if (props.value != null) {
837836
value = props.value + '';
838837
} else {
839-
value = optionChildren;
838+
value = flattenOptionChildren(props.children);
840839
}
841840
selected = false;
842841
if (Array.isArray(selectValue)) {
@@ -851,17 +850,9 @@ class ReactDOMServerRenderer {
851850
selected = '' + selectValue === value;
852851
}
853852

854-
props = Object.assign(
855-
{
856-
selected: undefined,
857-
children: undefined,
858-
},
859-
props,
860-
{
861-
selected: selected,
862-
children: optionChildren,
863-
},
864-
);
853+
props = Object.assign({}, props, {
854+
selected: selected,
855+
});
865856
}
866857
}
867858

0 commit comments

Comments
 (0)