Skip to content

Commit acfe2d7

Browse files
author
entelostre
committed
Fix TextInput state revisions retaining their predecessor on Android
Summary: #55719 added shadowViewFromShadowNode() to BaseTextInputShadowNode.h, nulling props/state on a fragment's parentShadowView so a text-input state revision does not retain the previous one. AndroidTextInputShadowNode is `final : public ConcreteViewShadowNode<...>` and builds its own fragment for the input's text value, so it never received that fix. ShadowView::state points at the AndroidTextInputState held when the fragment was built, and that fragment is stored into the next state by updateStateIfNeeded(), making revision N retain N-1. The chain grows one link per update and is destroyed by nested recursion, exhausting the native stack. Nothing reads Fragment::parentShadowView.props or .state - only tag, layoutMetrics and componentHandle are consumed - so clearing them is behaviour-preserving, including on the MapBuffer measurement path. Changelog: [Android] [Fixed] - Fix TextInput state revisions retaining their predecessor, causing a native stack overflow after many text updates
1 parent b03652a commit acfe2d7

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

  • packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput

packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputShadowNode.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ AttributedString AndroidTextInputShadowNode::getAttributedString(
190190
// that effect.
191191
fragment.textAttributes.backgroundColor = clearColor();
192192
fragment.parentShadowView = ShadowView(*this);
193+
// Clearing `props` and `state` (which we don't use) allows avoiding
194+
// retaining the previous state revision. Same rationale as
195+
// `shadowViewFromShadowNode()` in `BaseTextInputShadowNode.h`, which this
196+
// platform override does not inherit.
197+
fragment.parentShadowView.props = nullptr;
198+
fragment.parentShadowView.state = nullptr;
193199
attributedString.prependFragment(std::move(fragment));
194200
}
195201

0 commit comments

Comments
 (0)