mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Prevent an infinite loop in Text.onTextLayout
Summary: Changelog: [internal] # Problem onTextLayout was called even if there was no change to text layout. This can cause an infinite loop with onTextLayout triggering commit which triggers onTextLayout. # Fix Do not call onTextLayout if there is nothing to layout. Reviewed By: yungsters Differential Revision: D23648430 fbshipit-source-id: 055dc34a9aca0edf2c78a5812b35b80df32c9e3e
This commit is contained in:
committed by
Facebook GitHub Bot
parent
a8b090b128
commit
a315e4cd30
@@ -164,6 +164,18 @@ void ParagraphShadowNode::layout(LayoutContext layoutContext) {
|
||||
|
||||
updateStateIfNeeded(content);
|
||||
|
||||
if (content.attachments.empty()) {
|
||||
#ifndef ANDROID
|
||||
if (getConcreteProps().onTextLayout) {
|
||||
// `onTextLayout` needs to be called even if text is empty
|
||||
// to be compatible with Paper.
|
||||
getConcreteEventEmitter().onTextLayout({});
|
||||
}
|
||||
#endif
|
||||
// No attachments, nothing to layout.
|
||||
return;
|
||||
}
|
||||
|
||||
auto measurement = textLayoutManager_->measure(
|
||||
AttributedStringBox{content.attributedString},
|
||||
content.paragraphAttributes,
|
||||
@@ -179,11 +191,6 @@ void ParagraphShadowNode::layout(LayoutContext layoutContext) {
|
||||
}
|
||||
#endif
|
||||
|
||||
if (content.attachments.empty()) {
|
||||
// No attachments, nothing to layout.
|
||||
return;
|
||||
}
|
||||
|
||||
// Iterating on attachments, we clone shadow nodes and moving
|
||||
// `paragraphShadowNode` that represents clones of `this` object.
|
||||
auto paragraphShadowNode = static_cast<ParagraphShadowNode *>(this);
|
||||
|
||||
Reference in New Issue
Block a user