Repository navigation
Fix TextInput state retain chain in AndroidTextInputShadowNode - #59980
Open
kellarwindland wants to merge 1 commit into
Open
kellarwindland wants to merge 1 commit into
kellarwindland wants to merge 1 commit into
Conversation
Summary: `AndroidTextInputShadowNode::getAttributedString` builds the fragment for a controlled `value` with `parentShadowView = ShadowView(*this)`. A full `ShadowView` carries the node's current `state` and `props`. `updateStateIfNeeded` stores that attributed string in the next `AndroidTextInputState` (`reactTreeAttributedString`), so every new state keeps the previous state (and props) alive. The chain grows by one link per value change for as long as the input stays mounted. Two effects: - Memory: native heap grows with every change to a controlled `TextInput` and is only released on unmount. - Crash: on unmount the whole chain is destroyed recursively on the JS thread. Long chains overflow the stack, and crash stacks repeat `State → AttributedString → Fragment → ShadowView → State` dozens of times before ending in a SIGSEGV in `~AndroidTextInputState()`. D94267721 fixed the same retain chain for iOS/macOS by adding `shadowViewFromShadowNode()` in `BaseTextInputShadowNode.h`. `AndroidTextInputShadowNode` does not inherit from `BaseTextInputShadowNode`, so Android still had the bug. This change clears `props` and `state` on the parent `ShadowView` before storing it in the fragment, mirroring the iOS fix. On Android, `parentShadowView` is only read for `tag`, `componentHandle` and `layoutMetrics`. Its `state` and `props` are never read. ## Changelog: [Android] [Fixed] - Fix memory leak in TextInput: each state retained the previous one, which could overflow the stack on unmount Differential Revision: D131297146
|
@kellarwindland has exported this pull request. If you are a Meta employee, you can view the originating Diff in D131297146. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
AndroidTextInputShadowNode::getAttributedStringbuilds the fragment for a controlledvaluewithparentShadowView = ShadowView(*this). A fullShadowViewcarries the node's currentstateandprops.updateStateIfNeededstores that attributed string in the nextAndroidTextInputState(reactTreeAttributedString), so every new state keeps the previous state (and props) alive. The chain grows by one link per value change for as long as the input stays mounted.Two effects:
TextInputand is only released on unmount.State → AttributedString → Fragment → ShadowView → Statedozens of times before ending in a SIGSEGV in~AndroidTextInputState().D94267721 fixed the same retain chain for iOS/macOS by adding
shadowViewFromShadowNode()inBaseTextInputShadowNode.h.AndroidTextInputShadowNodedoes not inherit fromBaseTextInputShadowNode, so Android still had the bug.This change clears
propsandstateon the parentShadowViewbefore storing it in the fragment, mirroring the iOS fix. On Android,parentShadowViewis only read fortag,componentHandleandlayoutMetrics. Itsstateandpropsare never read.Changelog:
[Android] [Fixed] - Fix memory leak in TextInput: each state retained the previous one, which could overflow the stack on unmount
Differential Revision: D131297146