Skip to content

Commit

Permalink
Ignore when a text string or number is supplied as a child.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sota000 authored and facebook-github-bot committed Jul 27, 2021
1 parent c2ba886 commit d3e8362
Showing 1 changed file with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,25 @@ void YogaLayoutableShadowNode::appendChild(
yogaNode_.setDirty(true);

// All children of a non-leaf `YogaLayoutableShadowNode` must be a
// `YogaLayoutableShadowNode`s.
react_native_assert(
traitCast<YogaLayoutableShadowNode const *>(childNode.get()));

// Appending the Yoga node.
appendYogaChild(*childNode);

ensureYogaChildrenLookFine();
ensureYogaChildrenAlighment();

// Adopting the Yoga node.
adoptYogaChild(getChildren().size() - 1);

ensureConsistency();
// `YogaLayoutableShadowNode`s to be appended. This happens when invalid
// string/numeric child is passed which is not YogaLayoutableShadowNode
// (e.g. RCTRawText). This used to throw an error, but we are ignoring it
// because we want core library components to be fault-tolerant and degrade
// gracefully. A soft error will be emitted from JavaScript.
if (traitCast<YogaLayoutableShadowNode const *>(childNode.get())) {
// Appending the Yoga node.
appendYogaChild(*childNode);

ensureYogaChildrenLookFine();
ensureYogaChildrenAlighment();

// Adopting the Yoga node.
adoptYogaChild(getChildren().size() - 1);

ensureConsistency();
} else {
LOG(ERROR) << "Text strings must be rendered within a <Text> component.";
}
}

bool YogaLayoutableShadowNode::doesOwn(
Expand Down

0 comments on commit d3e8362

Please sign in to comment.