Repository navigation
Conversation
A multiline TextInput re-flows and repaints its text on the keystroke, but its frame only changed once the state update sent from the text watcher was flushed asynchronously (next Choreographer tick, commit and layout on the JS thread, mount on the following UI frame). Every change that adds or removes a line therefore drew one frame with the new text and the old height, which showed up as a content jump. Dispatch that state update with UpdateMode.unstable_Immediate so the commit, layout and mount happen inside onTextChanged, before the frame is drawn, and refresh the cached spannable before notifying the text watchers so the synchronous measure sees the new text. Fixes react#46813 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Contributor
Author
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:
Fixes #46813.
On Android, a multiline
TextInputre-flows and repaints its text on the keystroke, but its frame only changed once the state update sent fromReactTextInputTextWatcherwas flushed asynchronously: next Choreographer tick, commit and layout on the JS thread, mount on the following UI frame. Every change that adds or removes a line therefore drew one frame with the new text and the old height, which shows up as a content jump (and the siblings below the input lag by a frame).This dispatches that state update with
UpdateMode.unstable_Immediate(the same mechanism iOS uses for scroll offsets behindenableImmediateUpdateModeForContentOffsetChanges), so the commit, layout and mount happen insideonTextChanged, before the frame is drawn. The cached spannable is refreshed before the text watchers run so the synchronous measure sees the new text. Unlike #52534 this does not run JS on the UI thread.Changelog:
[ANDROID] [FIXED] - TextInput: fix one-frame content jump of multiline inputs when a line is added or removed
Test Plan:
RNTester Playground with the reproducer from #46813 (
<TextInput multiline style={{fontSize: 20, width: 300, padding: 0}} />plus a sibling below), Pixel emulator (API 36). A temporary log inReactEditText.onDrawreported every frame drawn with a stale height: before, exactly one per height change; after, none. Controlled (value/onChangeText), uncontrolled andmaxHeight-capped inputs behave as before.Full-resolution videos: before.mp4, after.mp4.
Benchmarks
Release RNTester (
assembleRelease, arm64) with the reproducer above, A =main(5dc1d78), B = this PR, on four Argent Fleet phones, A/B/B/A order, 2 blocks × 2 runs per arm (frame table) and 1 block × 2 runs per arm (CPU table). Each run injects 10 × (20 characters + Enter) withadb shell inputinto the focused multiline input (210 keystrokes; each injected character fires two native text changes, so B commits ~440 times per run).UI-thread time per input-handling frame (
dumpsys gfxinfo framestats,SyncQueued − HandleInputStart, all input frames of all runs pooled; jank = frame total > 16.67 ms):CPU time per keystroke (
utime+stimeof the main thread andmqt_v_jsfrom/procover the typing loop ÷ 210):*= bootstrap 95% CI excludes 0.Reading: the commit + layout + mount of a native text change moves from the JS thread to the UI thread (atrace: 0.7–1.3 ms per
ShadowTree::commiton the UI thread, 0.9–2.0 ms on the JS thread before), which is ~0.5–1 ms of extra main-thread CPU per text change. The work no longer lands in a separate frame, so the UI-thread time inside input frames and the p99 go down on all four phones; the extra time is spent in key-event handling before the frame. The JS thread is freed by the same amount.yarn flow-check,yarn format-check-kotlinpass.🤖 Generated with Claude Code