Skip to content

Commit d3e8362

Browse files
sota000facebook-github-bot
authored andcommitted
Ignore when a text string or number is supplied as a child.
Summary: Currently, React Native throws an invariant violation error when a text string or number is supplied as a child. This is undesirable because core library components should be fault-tolerant and degrade gracefully (with soft errors, if relevant). This change will work when a change in the host configs are landed (facebook/react#21953). Changelog: [internal] Reviewed By: yungsters, sammy-SC Differential Revision: D29894182 fbshipit-source-id: 827ff299991a476b57981382d196c7ee1396ec28
1 parent c2ba886 commit d3e8362

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -209,20 +209,25 @@ void YogaLayoutableShadowNode::appendChild(
209209
yogaNode_.setDirty(true);
210210

211211
// All children of a non-leaf `YogaLayoutableShadowNode` must be a
212-
// `YogaLayoutableShadowNode`s.
213-
react_native_assert(
214-
traitCast<YogaLayoutableShadowNode const *>(childNode.get()));
215-
216-
// Appending the Yoga node.
217-
appendYogaChild(*childNode);
218-
219-
ensureYogaChildrenLookFine();
220-
ensureYogaChildrenAlighment();
221-
222-
// Adopting the Yoga node.
223-
adoptYogaChild(getChildren().size() - 1);
224-
225-
ensureConsistency();
212+
// `YogaLayoutableShadowNode`s to be appended. This happens when invalid
213+
// string/numeric child is passed which is not YogaLayoutableShadowNode
214+
// (e.g. RCTRawText). This used to throw an error, but we are ignoring it
215+
// because we want core library components to be fault-tolerant and degrade
216+
// gracefully. A soft error will be emitted from JavaScript.
217+
if (traitCast<YogaLayoutableShadowNode const *>(childNode.get())) {
218+
// Appending the Yoga node.
219+
appendYogaChild(*childNode);
220+
221+
ensureYogaChildrenLookFine();
222+
ensureYogaChildrenAlighment();
223+
224+
// Adopting the Yoga node.
225+
adoptYogaChild(getChildren().size() - 1);
226+
227+
ensureConsistency();
228+
} else {
229+
LOG(ERROR) << "Text strings must be rendered within a <Text> component.";
230+
}
226231
}
227232

228233
bool YogaLayoutableShadowNode::doesOwn(

0 commit comments

Comments
 (0)