Repository navigation
Scope the TextInput spannable cache to the React instance (#58869) - #58869
Conversation
|
@zeyap has exported this pull request. If you are a Meta employee, you can view the originating Diff in D122870300. |
Summary:
On Fabric, `ReactEditText` caches its spannable in `TextLayoutManager` keyed by react tag, and the shadow node's state keeps that tag as `cachedAttributedStringId` to re-measure against. The cache was a single process-global map keyed only by tag. React tags restart for every new React instance, so after a reload the old and new instances can use the same tags in the same map: the new instance can read the old instance's spannable, and when an old `ReactEditText` is finalized it removes the new view's entry. The next cached measure then fails `checkNotNull` in `getOrCreateSpannableForText` with "Required value was null".
This change gives each React instance its own spannable cache:
- `TextLayoutManager` keeps one map per `ReactApplicationContext`. `FabricUIManager` creates it in its constructor and removes it in `invalidate()`.
- `FabricUIManager.measureText` passes its own context, so a cached measure only looks in that instance's map.
- `ReactEditText` writes to and evicts from the map of the context it was created with (`ThemedReactContext.reactApplicationContext`). Create, destroy, read and write all resolve the key through one helper, so a view's `ThemedReactContext` and `FabricUIManager`'s `ReactApplicationContext` always hit the same map. After teardown, an old view's set or evict does nothing because its map is gone.
- A layout that started before `invalidate()` can still reach `measureText` after the map is removed. In that case the cached measure uses an empty spannable instead of throwing, because the cache-id `MapBuffer` carries only the id and there is nothing to rebuild from. The result belongs to an instance that is going away. A missing entry in a live map still fails `checkNotNull`.
This replaces the previous version of this diff, where `finalize()` only evicted the spannable the instance itself had cached. Per-tag eviction still happens in `finalize()`, but now only within the view's own instance, where tags are never reused. I did not move eviction to `onDropViewInstance`: a commit whose layout is still running on a background thread can measure a TextInput after the UI thread has already processed that view's delete, so evicting right away would add a new way to hit the same `checkNotNull`.
Changelog:
[Android][Fixed] - Fix TextInput measurement crash ("Required value was null") after a React instance reload, by scoping the cached TextInput spannables to the React instance
Reviewed By: zeyap
Differential Revision: D122870300
aa811de to
ecc0b42
Compare
Summary:
On Fabric, `ReactEditText` caches its spannable in `TextLayoutManager` keyed by react tag, and the shadow node's state keeps that tag as `cachedAttributedStringId` to re-measure against. The cache was a single process-global map keyed only by tag. React tags restart for every new React instance, so after a reload the old and new instances can use the same tags in the same map: the new instance can read the old instance's spannable, and when an old `ReactEditText` is finalized it removes the new view's entry. The next cached measure then fails `checkNotNull` in `getOrCreateSpannableForText` with "Required value was null".
This change gives each React instance its own spannable cache:
- `TextLayoutManager` keeps one map per `ReactApplicationContext`. `FabricUIManager` creates it in its constructor and removes it in `invalidate()`.
- `FabricUIManager.measureText` passes its own context, so a cached measure only looks in that instance's map.
- `ReactEditText` writes to and evicts from the map of the context it was created with (`ThemedReactContext.reactApplicationContext`). Create, destroy, read and write all resolve the key through one helper, so a view's `ThemedReactContext` and `FabricUIManager`'s `ReactApplicationContext` always hit the same map. After teardown, an old view's set or evict does nothing because its map is gone.
- A layout that started before `invalidate()` can still reach `measureText` after the map is removed. In that case the cached measure uses an empty spannable instead of throwing, because the cache-id `MapBuffer` carries only the id and there is nothing to rebuild from. The result belongs to an instance that is going away. A missing entry in a live map still fails `checkNotNull`.
This replaces the previous version of this diff, where `finalize()` only evicted the spannable the instance itself had cached. Per-tag eviction still happens in `finalize()`, but now only within the view's own instance, where tags are never reused. I did not move eviction to `onDropViewInstance`: a commit whose layout is still running on a background thread can measure a TextInput after the UI thread has already processed that view's delete, so evicting right away would add a new way to hit the same `checkNotNull`.
Changelog:
[Android][Fixed] - Fix TextInput measurement crash ("Required value was null") after a React instance reload, by scoping the cached TextInput spannables to the React instance
Reviewed By: zeyap
Differential Revision: D122870300
ecc0b42 to
f9dd1fe
Compare
Summary:
On Fabric, `ReactEditText` caches its spannable in `TextLayoutManager` keyed by react tag, and the shadow node's state keeps that tag as `cachedAttributedStringId` to re-measure against. The cache was a single process-global map keyed only by tag. React tags restart for every new React instance, so after a reload the old and new instances can use the same tags in the same map: the new instance can read the old instance's spannable, and when an old `ReactEditText` is finalized it removes the new view's entry. The next cached measure then fails `checkNotNull` in `getOrCreateSpannableForText` with "Required value was null".
This change gives each React instance its own spannable cache:
- `TextLayoutManager` keeps one map per `ReactApplicationContext`. `FabricUIManager` creates it in its constructor and removes it in `invalidate()`.
- `FabricUIManager.measureText` passes its own context, so a cached measure only looks in that instance's map.
- `ReactEditText` writes to and evicts from the map of the context it was created with (`ThemedReactContext.reactApplicationContext`). Create, destroy, read and write all resolve the key through one helper, so a view's `ThemedReactContext` and `FabricUIManager`'s `ReactApplicationContext` always hit the same map. After teardown, an old view's set or evict does nothing because its map is gone.
- A layout that started before `invalidate()` can still reach `measureText` after the map is removed. In that case the cached measure returns a 0x0 measurement instead of throwing, because the cache-id `MapBuffer` carries only the id and there is nothing to rebuild from. The result belongs to an instance that is going away. A missing entry in a live map still fails `checkNotNull`.
This replaces the previous version of this diff, where `finalize()` only evicted the spannable the instance itself had cached. Per-tag eviction still happens in `finalize()`, but now only within the view's own instance, where tags are never reused. I did not move eviction to `onDropViewInstance`: a commit whose layout is still running on a background thread can measure a TextInput after the UI thread has already processed that view's delete, so evicting right away would add a new way to hit the same `checkNotNull`.
Changelog:
[Android][Fixed] - Fix TextInput measurement crash ("Required value was null") after a React instance reload, by scoping the cached TextInput spannables to the React instance
Reviewed By: zeyap
Differential Revision: D122870300
f9dd1fe to
748c414
Compare
Summary: Pull Request resolved: react#58869 On Fabric, `ReactEditText` caches its spannable in `TextLayoutManager` keyed by react tag, and the shadow node's state keeps that tag as `cachedAttributedStringId` to re-measure against. The cache was a single process-global map keyed only by tag. React tags restart for every new React instance, so after a reload the old and new instances can use the same tags in the same map: the new instance can read the old instance's spannable, and when an old `ReactEditText` is finalized it removes the new view's entry. The next cached measure then fails `checkNotNull` in `getOrCreateSpannableForText` with "Required value was null". This change gives each React instance its own spannable cache: - `TextLayoutManager` keeps one map per `ReactApplicationContext`. `FabricUIManager` creates it in its constructor and removes it in `invalidate()`. - `FabricUIManager.measureText` passes its own context, so a cached measure only looks in that instance's map. - `ReactEditText` writes to and evicts from the map of the context it was created with (`ThemedReactContext.reactApplicationContext`). Create, destroy, read and write all resolve the key through one helper, so a view's `ThemedReactContext` and `FabricUIManager`'s `ReactApplicationContext` always hit the same map. After teardown, an old view's set or evict does nothing because its map is gone. - A layout that started before `invalidate()` can still reach `measureText` after the map is removed. In that case the cached measure returns a 0x0 measurement instead of throwing, because the cache-id `MapBuffer` carries only the id and there is nothing to rebuild from. The result belongs to an instance that is going away. A missing entry in a live map still fails `checkNotNull`. This replaces the previous version of this diff, where `finalize()` only evicted the spannable the instance itself had cached. Per-tag eviction still happens in `finalize()`, but now only within the view's own instance, where tags are never reused. I did not move eviction to `onDropViewInstance`: a commit whose layout is still running on a background thread can measure a TextInput after the UI thread has already processed that view's delete, so evicting right away would add a new way to hit the same `checkNotNull`. Changelog: [Android][Fixed] - Fix TextInput measurement crash ("Required value was null") after a React instance reload, by scoping the cached TextInput spannables to the React instance Reviewed By: zeyap Differential Revision: D122870300
748c414 to
53eeb98
Compare
Summary: WARNING: Generated by Autopilot (alpha) — review carefully, verify the underlying claim before accepting. Agent: React Native Agent (Bugs) | Trajectory: https://www.internalfb.com/intern/devai/devmate/inspector/49205bed-501a-43cd-9059-1e84fb06a6ba/ | SC job: https://www.internalfb.com/intern/sandcastle/instance/45035996995515977/ --- On Fabric, `ReactEditText` caches its spannable in `TextLayoutManager` keyed by react tag, and the shadow node's state keeps that tag as `cachedAttributedStringId` to re-measure against. The cache was a single process-global map keyed only by tag. React tags restart for every new React instance, so after a reload the old and new instances can use the same tags in the same map: the new instance can read the old instance's spannable, and when an old `ReactEditText` is finalized it removes the new view's entry. The next cached measure then fails `checkNotNull` in `getOrCreateSpannableForText` with "Required value was null". This change gives each React instance its own spannable cache: - `TextLayoutManager` keeps one map per `ReactApplicationContext`. `FabricUIManager` creates it in its constructor and removes it in `invalidate()`. - `FabricUIManager.measureText` passes its own context, so a cached measure only looks in that instance's map. - `ReactEditText` writes to and evicts from the map of the context it was created with (`ThemedReactContext.reactApplicationContext`). Create, destroy, read and write all resolve the key through one helper, so a view's `ThemedReactContext` and `FabricUIManager`'s `ReactApplicationContext` always hit the same map. After teardown, an old view's set or evict does nothing because its map is gone. - A layout that started before `invalidate()` can still reach `measureText` after the map is removed. In that case the cached measure returns a 0x0 measurement instead of throwing, because the cache-id `MapBuffer` carries only the id and there is nothing to rebuild from. The result belongs to an instance that is going away. A missing entry in a live map still fails `checkNotNull`. This replaces the previous version of this diff, where `finalize()` only evicted the spannable the instance itself had cached. Per-tag eviction still happens in `finalize()`, but now only within the view's own instance, where tags are never reused. I did not move eviction to `onDropViewInstance`: a commit whose layout is still running on a background thread can measure a TextInput after the UI thread has already processed that view's delete, so evicting right away would add a new way to hit the same `checkNotNull`. Changelog: [Android][Fixed] - Fix TextInput measurement crash ("Required value was null") after a React instance reload, by scoping the cached TextInput spannables to the React instance Reviewed By: zeyap Differential Revision: D122870300
53eeb98 to
bd0c61b
Compare
Summary: WARNING: Generated by Autopilot (alpha) — review carefully, verify the underlying claim before accepting. Agent: React Native Agent (Bugs) | Trajectory: https://www.internalfb.com/intern/devai/devmate/inspector/dea12476-b7e6-441b-8ebb-bd79b2de520a/ | SC job: https://www.internalfb.com/intern/sandcastle/instance/49539596621165635/ --- Pull Request resolved: react#58869 On Fabric, `ReactEditText` caches its spannable in `TextLayoutManager` keyed by react tag, and the shadow node's state keeps that tag as `cachedAttributedStringId` to re-measure against. The cache was a single process-global map keyed only by tag. React tags restart for every new React instance, so after a reload the old and new instances can use the same tags in the same map: the new instance can read the old instance's spannable, and when an old `ReactEditText` is finalized it removes the new view's entry. The next cached measure then fails `checkNotNull` in `getOrCreateSpannableForText` with "Required value was null". This change gives each React instance its own spannable cache: - `TextLayoutManager` keeps one map per `ReactApplicationContext`. `FabricUIManager` creates it in its constructor and removes it in `invalidate()`. - `FabricUIManager.measureText` passes its own context, so a cached measure only looks in that instance's map. - `ReactEditText` writes to and evicts from the map of the context it was created with (`ThemedReactContext.reactApplicationContext`). Create, destroy, read and write all resolve the key through one helper, so a view's `ThemedReactContext` and `FabricUIManager`'s `ReactApplicationContext` always hit the same map. After teardown, an old view's set or evict does nothing because its map is gone. - A layout that started before `invalidate()` can still reach `measureText` after the map is removed. In that case the cached measure returns a 0x0 measurement instead of throwing, because the cache-id `MapBuffer` carries only the id and there is nothing to rebuild from. The result belongs to an instance that is going away. A missing entry in a live map still fails `checkNotNull`. This replaces the previous version of this diff, where `finalize()` only evicted the spannable the instance itself had cached. Per-tag eviction still happens in `finalize()`, but now only within the view's own instance, where tags are never reused. I did not move eviction to `onDropViewInstance`: a commit whose layout is still running on a background thread can measure a TextInput after the UI thread has already processed that view's delete, so evicting right away would add a new way to hit the same `checkNotNull`. Changelog: [Android][Fixed] - Fix TextInput measurement crash ("Required value was null") after a React instance reload, by scoping the cached TextInput spannables to the React instance Reviewed By: zeyap Differential Revision: D122870300
bd0c61b to
307162b
Compare
Summary: WARNING: Generated by Autopilot (alpha) — review carefully, verify the underlying claim before accepting. Agent: React Native Agent (Bugs) | Trajectory: https://www.internalfb.com/intern/devai/devmate/inspector/dea12476-b7e6-441b-8ebb-bd79b2de520a/ | SC job: https://www.internalfb.com/intern/sandcastle/instance/49539596621165635/ --- On Fabric, `ReactEditText` caches its spannable in `TextLayoutManager` keyed by react tag, and the shadow node's state keeps that tag as `cachedAttributedStringId` to re-measure against. The cache was a single process-global map keyed only by tag. React tags restart for every new React instance, so after a reload the old and new instances can use the same tags in the same map: the new instance can read the old instance's spannable, and when an old `ReactEditText` is finalized it removes the new view's entry. The next cached measure then fails `checkNotNull` in `getOrCreateSpannableForText` with "Required value was null". This change gives each React instance its own spannable cache: - `TextLayoutManager` keeps one map per `ReactApplicationContext`. `FabricUIManager` creates it in its constructor and removes it in `invalidate()`. - `FabricUIManager.measureText` passes its own context, so a cached measure only looks in that instance's map. - `ReactEditText` writes to and evicts from the map of the context it was created with (`ThemedReactContext.reactApplicationContext`). Create, destroy, read and write all resolve the key through one helper, so a view's `ThemedReactContext` and `FabricUIManager`'s `ReactApplicationContext` always hit the same map. After teardown, an old view's set or evict does nothing because its map is gone. - A layout that started before `invalidate()` can still reach `measureText` after the map is removed. In that case the cached measure returns a 0x0 measurement instead of throwing, because the cache-id `MapBuffer` carries only the id and there is nothing to rebuild from. The result belongs to an instance that is going away. A missing entry in a live map still fails `checkNotNull`. This replaces the previous version of this diff, where `finalize()` only evicted the spannable the instance itself had cached. Per-tag eviction still happens in `finalize()`, but now only within the view's own instance, where tags are never reused. I did not move eviction to `onDropViewInstance`: a commit whose layout is still running on a background thread can measure a TextInput after the UI thread has already processed that view's delete, so evicting right away would add a new way to hit the same `checkNotNull`. Changelog: [Android][Fixed] - Fix TextInput measurement crash ("Required value was null") after a React instance reload, by scoping the cached TextInput spannables to the React instance Reviewed By: zeyap Differential Revision: D122870300
307162b to
f67f239
Compare
Summary: Pull Request resolved: react#58869 On Fabric, `ReactEditText` caches its spannable in `TextLayoutManager` keyed by react tag, and the shadow node's state keeps that tag as `cachedAttributedStringId` to re-measure against. The cache was a single process-global map keyed only by tag. React tags restart for every new React instance, so after a reload the old and new instances can use the same tags in the same map: the new instance can read the old instance's spannable, and when an old `ReactEditText` is finalized it removes the new view's entry. The next cached measure then fails `checkNotNull` in `getOrCreateSpannableForText` with "Required value was null". This change gives each React instance its own spannable cache: - `TextLayoutManager` keeps one map per `ReactApplicationContext`. `FabricUIManager` creates it in its constructor and removes it in `invalidate()`. - `FabricUIManager.measureText` passes its own context, so a cached measure only looks in that instance's map. - `ReactEditText` writes to and evicts from the map of the context it was created with (`ThemedReactContext.reactApplicationContext`). Create, destroy, read and write all resolve the key through one helper, so a view's `ThemedReactContext` and `FabricUIManager`'s `ReactApplicationContext` always hit the same map. After teardown, an old view's set or evict does nothing because its map is gone. - A layout that started before `invalidate()` can still reach `measureText` after the map is removed. In that case the cached measure returns a 0x0 measurement instead of throwing, because the cache-id `MapBuffer` carries only the id and there is nothing to rebuild from. The result belongs to an instance that is going away. The same applies when `finalize()` has already evicted the tag while a background commit still measures it: the measure returns 0x0 instead of failing `checkNotNull`. This replaces the previous version of this diff, where `finalize()` only evicted the spannable the instance itself had cached. Per-tag eviction still happens in `finalize()`, but now only within the view's own instance, where tags are never reused. I did not move eviction to `onDropViewInstance`: a commit whose layout is still running on a background thread can measure a TextInput after the UI thread has already processed that view's delete, so evicting right away would make that case much more common. Changelog: [Android][Fixed] - Fix TextInput measurement crash ("Required value was null") after a React instance reload, by scoping the cached TextInput spannables to the React instance Reviewed By: zeyap Differential Revision: D122870300
f67f239 to
4abba0c
Compare
|
We hit the crash this PR fixes in a release build and looked into it before finding the PR. What we measured matches the cause in the summary, so here are the numbers in case they help the review. Setup
What happens After the reload, changing the text of a controlled It reaches JS as How we ran it, and the counts One trial: reload the instance, focus one controlled input (
The crash in the unforced arm followed an ordinary Why we think it is the finalizer path from the summary
Why it is rare (our reading of the source, corrections welcome) The cached id seems to be used for a measure only between a native text change and the next commit from JS that carries the text again ( One crash, trimmed (forced-GC arm; the app's process only, log tags shortened) Still present
If it helps this land, we can run the same trials against a nightly or release candidate that includes the change and report the counts here. |
4abba0c to
785b743
Compare
Summary:
On Fabric, `ReactEditText` caches its spannable in `TextLayoutManager` keyed by react tag, and the shadow node's state keeps that tag as `cachedAttributedStringId` to measure against. The cache was one process-wide map, but react tags restart in every React instance. After a reload, an old-instance `ReactEditText` that hasn't been garbage collected yet can share a tag with a new-instance TextInput. When the old view is finalized it removes the new view's entry, and the next cached measure fails `checkNotNull` with "Required value was null".
**Changes**:
- `TextLayoutManager` keeps one map per `ReactApplicationContext`. `FabricUIManager` creates it at the end of `initialize()`, removes it in `invalidate()`, and passes its context to `measureText`. `ReactEditText` writes and evicts through its own context, so instances never see each other's entries.
- A cached measure whose instance map is already gone (a layout still in flight during teardown) returns 0x0.
- A cached measure whose entry is missing from a live map also returns 0x0, but logs a soft exception: only `ReactEditText.finalize()` evicts within an instance, so this would be a different bug and should stay visible.
Changelog:
[Android][Fixed] - Fix TextInput measurement crash ("Required value was null") after a React instance reload
Differential Revision: D122870300
Abbondanzo
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
Summary:
On Fabric, `ReactEditText` caches its spannable in `TextLayoutManager` keyed by react tag, and the shadow node's state keeps that tag as `cachedAttributedStringId` to measure against. The cache was one process-wide map, but react tags restart in every React instance, so instances that coexist (an instance being reloaded and its replacement, or several hosts in one app) share entries. A not-yet-collected `ReactEditText` from one instance can then evict another instance's entry for the same tag in `finalize()`, and the next cached measure fails `checkNotNull` with "Required value was null"; an instance can also measure another instance's text.
**Changes**:
- `TextLayoutManager` keeps one map per `ReactApplicationContext`. `FabricUIManager` creates it at the end of `initialize()`, removes it in `invalidate()`, and passes its context to `measureText`. `ReactEditText` writes and evicts through its own context, so instances never see each other's entries. Dropping the map on teardown also releases that instance's cached spannables, even for views that are never finalized.
- A cached measure whose instance map is already gone (a layout still in flight during teardown) returns 0x0.
- A cached measure whose entry is missing from a live map also returns 0x0, but logs a soft exception: only `ReactEditText.finalize()` evicts within an instance, so this would be a different bug and should stay visible.
Changelog:
[Android][Fixed] - Fix TextInput measurement crash ("Required value was null") when multiple React instances share the TextInput spannable cache
Reviewed By: Abbondanzo
Differential Revision: D122870300
785b743 to
94147d5
Compare
Summary:
On Fabric, `ReactEditText` caches its spannable in `TextLayoutManager` keyed by react tag, and the shadow node's state keeps that tag as `cachedAttributedStringId` to measure against. The cache was one process-wide map, but react tags restart in every React instance, so instances that coexist (an instance being reloaded and its replacement, or several hosts in one app) share entries. A not-yet-collected `ReactEditText` from one instance can then evict another instance's entry for the same tag in `finalize()`, and the next cached measure fails `checkNotNull` with "Required value was null"; an instance can also measure another instance's text.
**Changes**:
- `TextLayoutManager` keeps one map per `ReactApplicationContext`. `FabricUIManager` creates it at the end of `initialize()`, removes it in `invalidate()`, and passes its context to `measureText`. `ReactEditText` writes and evicts through its own context, so instances never see each other's entries. Dropping the map on teardown also releases that instance's cached spannables, even for views that are never finalized.
- A cached measure whose instance map is already gone (a layout still in flight during teardown) returns 0x0.
- A cached measure whose entry is missing from a live map also returns 0x0, but logs a soft exception: only `ReactEditText.finalize()` evicts within an instance, so this would be a different bug and should stay visible.
Changelog:
[Android][Fixed] - Fix TextInput measurement crash ("Required value was null") when multiple React instances share the TextInput spannable cache
Reviewed By: Abbondanzo
Differential Revision: D122870300
Signed-off-by: Zeya Peng <zeyap@meta.com>
94147d5 to
bd19b5b
Compare
Visual regressionNo visual differences at ios: no capture |
|
This pull request was successfully merged by @zeyap in 31ad1f3 When will my fix make it into a release? | How to file a pick request? |
Why === ReactAndroid did not compile after the rebase. Upstream added `spannableCacheOwner` after `textEffectRegistry` (react#58869), while frontier had added `floatExclusionsDip` before `textEffectRegistry` and `hugsWrappedLines` at the end. In the merged signature, the overload without `fontWeightAdjustment` passed `hugsWrappedLines` where `spannableCacheOwner` now is, a type error, and upstream's `ReactEditTextSpannableCacheTest` passed its React context where frontier expected a `TextEffectRegistry`. How === Put upstream's parameters first, in upstream's order, and frontier's `floatExclusionsDip` and `hugsWrappedLines` after them, in both overloads. Upstream's positional callers keep working, the overload passes its optional arguments by name, and `FabricUIManager`, which calls from Java and so passes every argument by position, follows the new order. Test Plan ========= `./gradlew :packages:chat-demo:android:app:assembleRelease -Preact.internal.useHermesStable=true -PreactNativeArchitectures=arm64-v8a` succeeds, and so does the same task for RN Tester and Astryx. `./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests 'com.facebook.react.views.textinput.ReactEditTextSpannableCacheTest' --tests 'com.facebook.react.views.text.TextLayoutManager*'` passes. The three Release apps launch on an Android 16 emulator.
Why === ReactAndroid did not compile after the rebase. Upstream added `spannableCacheOwner` after `textEffectRegistry` (react#58869), while frontier had added `floatExclusionsDip` before `textEffectRegistry` and `hugsWrappedLines` at the end. In the merged signature, the overload without `fontWeightAdjustment` passed `hugsWrappedLines` where `spannableCacheOwner` now is, a type error, and upstream's `ReactEditTextSpannableCacheTest` passed its React context where frontier expected a `TextEffectRegistry`. How === Put upstream's parameters first, in upstream's order, and frontier's `floatExclusionsDip` and `hugsWrappedLines` after them, in both overloads. Upstream's positional callers keep working, the overload passes its optional arguments by name, and `FabricUIManager`, which calls from Java and so passes every argument by position, follows the new order. Test Plan ========= `./gradlew :packages:chat-demo:android:app:assembleRelease -Preact.internal.useHermesStable=true -PreactNativeArchitectures=arm64-v8a` succeeds, and so does the same task for RN Tester and Astryx. `./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests 'com.facebook.react.views.textinput.ReactEditTextSpannableCacheTest' --tests 'com.facebook.react.views.text.TextLayoutManager*'` passes. The three Release apps launch on an Android 16 emulator.
Why === ReactAndroid did not compile after the rebase. Upstream added `spannableCacheOwner` after `textEffectRegistry` (react#58869), while frontier had added `floatExclusionsDip` before `textEffectRegistry` and `hugsWrappedLines` at the end. In the merged signature, the overload without `fontWeightAdjustment` passed `hugsWrappedLines` where `spannableCacheOwner` now is, a type error, and upstream's `ReactEditTextSpannableCacheTest` passed its React context where frontier expected a `TextEffectRegistry`. How === Put upstream's parameters first, in upstream's order, and frontier's `floatExclusionsDip` and `hugsWrappedLines` after them, in both overloads. Upstream's positional callers keep working, the overload passes its optional arguments by name, and `FabricUIManager`, which calls from Java and so passes every argument by position, follows the new order. Test Plan ========= `./gradlew :packages:chat-demo:android:app:assembleRelease -Preact.internal.useHermesStable=true -PreactNativeArchitectures=arm64-v8a` succeeds, and so does the same task for RN Tester and Astryx. `./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests 'com.facebook.react.views.textinput.ReactEditTextSpannableCacheTest' --tests 'com.facebook.react.views.text.TextLayoutManager*'` passes. The three Release apps launch on an Android 16 emulator.
Why === ReactAndroid did not compile after the rebase. Upstream added `spannableCacheOwner` after `textEffectRegistry` (react#58869), while frontier had added `floatExclusionsDip` before `textEffectRegistry` and `hugsWrappedLines` at the end. In the merged signature, the overload without `fontWeightAdjustment` passed `hugsWrappedLines` where `spannableCacheOwner` now is, a type error, and upstream's `ReactEditTextSpannableCacheTest` passed its React context where frontier expected a `TextEffectRegistry`. How === Put upstream's parameters first, in upstream's order, and frontier's `floatExclusionsDip` and `hugsWrappedLines` after them, in both overloads. Upstream's positional callers keep working, the overload passes its optional arguments by name, and `FabricUIManager`, which calls from Java and so passes every argument by position, follows the new order. Test Plan ========= `./gradlew :packages:chat-demo:android:app:assembleRelease -Preact.internal.useHermesStable=true -PreactNativeArchitectures=arm64-v8a` succeeds, and so does the same task for RN Tester and Astryx. `./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests 'com.facebook.react.views.textinput.ReactEditTextSpannableCacheTest' --tests 'com.facebook.react.views.text.TextLayoutManager*'` passes. The three Release apps launch on an Android 16 emulator.
Why === ReactAndroid did not compile after the rebase. Upstream added `spannableCacheOwner` after `textEffectRegistry` (react#58869), while frontier had added `floatExclusionsDip` before `textEffectRegistry` and `hugsWrappedLines` at the end. In the merged signature, the overload without `fontWeightAdjustment` passed `hugsWrappedLines` where `spannableCacheOwner` now is, a type error, and upstream's `ReactEditTextSpannableCacheTest` passed its React context where frontier expected a `TextEffectRegistry`. How === Put upstream's parameters first, in upstream's order, and frontier's `floatExclusionsDip` and `hugsWrappedLines` after them, in both overloads. Upstream's positional callers keep working, the overload passes its optional arguments by name, and `FabricUIManager`, which calls from Java and so passes every argument by position, follows the new order. Test Plan ========= `./gradlew :packages:chat-demo:android:app:assembleRelease -Preact.internal.useHermesStable=true -PreactNativeArchitectures=arm64-v8a` succeeds, and so does the same task for RN Tester and Astryx. `./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests 'com.facebook.react.views.textinput.ReactEditTextSpannableCacheTest' --tests 'com.facebook.react.views.text.TextLayoutManager*'` passes. The three Release apps launch on an Android 16 emulator.
Why === ReactAndroid did not compile after the rebase. Upstream added `spannableCacheOwner` after `textEffectRegistry` (react#58869), while frontier had added `floatExclusionsDip` before `textEffectRegistry` and `hugsWrappedLines` at the end. In the merged signature, the overload without `fontWeightAdjustment` passed `hugsWrappedLines` where `spannableCacheOwner` now is, a type error, and upstream's `ReactEditTextSpannableCacheTest` passed its React context where frontier expected a `TextEffectRegistry`. How === Put upstream's parameters first, in upstream's order, and frontier's `floatExclusionsDip` and `hugsWrappedLines` after them, in both overloads. Upstream's positional callers keep working, the overload passes its optional arguments by name, and `FabricUIManager`, which calls from Java and so passes every argument by position, follows the new order. Test Plan ========= `./gradlew :packages:chat-demo:android:app:assembleRelease -Preact.internal.useHermesStable=true -PreactNativeArchitectures=arm64-v8a` succeeds, and so does the same task for RN Tester and Astryx. `./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests 'com.facebook.react.views.textinput.ReactEditTextSpannableCacheTest' --tests 'com.facebook.react.views.text.TextLayoutManager*'` passes. The three Release apps launch on an Android 16 emulator.
Summary:
On Fabric,
ReactEditTextcaches its spannable inTextLayoutManagerkeyed by react tag, and the shadow node's state keeps that tag ascachedAttributedStringIdto measure against. The cache was one process-wide map, but react tags restart in every React instance, so instances that coexist (an instance being reloaded and its replacement, or several hosts in one app) share entries. A not-yet-collectedReactEditTextfrom one instance can then evict another instance's entry for the same tag infinalize(), and the next cached measure failscheckNotNullwith "Required value was null"; an instance can also measure another instance's text.Changes:
TextLayoutManagerkeeps one map perReactApplicationContext.FabricUIManagercreates it at the end ofinitialize(), removes it ininvalidate(), and passes its context tomeasureText.ReactEditTextwrites and evicts through its own context, so instances never see each other's entries. Dropping the map on teardown also releases that instance's cached spannables, even for views that are never finalized.ReactEditText.finalize()evicts within an instance, so this would be a different bug and should stay visible.Changelog:
[Android][Fixed] - Fix TextInput measurement crash ("Required value was null") when multiple React instances share the TextInput spannable cache
Reviewed By: Abbondanzo
Differential Revision: D122870300