@samitouri / QOS-React / commits / 0934ab948d

Flatten Text children before rendering (#9063)

From FB-internal D4613844.

Ben Alpert committed Feb 24, 2017 at 13:40 UTC 0934ab948ded53f0509ed1914fbcb834e3cf48d1
1 file changed +8 -3
src/renderers/art/ReactARTFiber.js
+8 -3
@@ -270,7 +270,7 @@ function applyShapeProps(instance, props, prevProps = {}) {
270 function applyTextProps(instance, props, prevProps = {}) {
271 applyRenderableNodeProps(instance, props, prevProps);
272
273 - const string = childrenAsString(props.children);
273 + const string = props.children;
274
275 if (
276 instance._currentString !== string ||
@@ -407,6 +407,7 @@ const ARTRenderer = ReactFiberReconciler({
407 appendInitialChild(parentInstance, child) {
408 if (typeof child === 'string') {
409 // Noop for string children of Text (eg <Text>{'foo'}{'bar'}</Text>)
410 + invariant(false, 'Text children should already be flattened.');
411 return;
412 }
413
@@ -443,7 +444,7 @@ const ARTRenderer = ReactFiberReconciler({
444 break;
445 case TYPES.TEXT:
446 instance = Mode.Text(
446 - childrenAsString(props.children),
447 + props.children,
448 props.font,
449 props.alignment,
450 props.path,
@@ -535,6 +536,10 @@ module.exports = {
536 RadialGradient,
537 Shape: TYPES.SHAPE,
538 Surface,
538 - Text: TYPES.TEXT,
539 + Text: function Text(props) {
540 + // TODO: This means you can't have children that render into strings.
541 + const T = TYPES.TEXT;
542 + return <T {...props}>{childrenAsString(props.children)}</T>;
543 + },
544 Transform,
545 };