Skip to content

Scope the TextInput spannable cache to the React instance (#58869) - #58869

Merged
meta-codesync[bot] merged 1 commit into
react:mainfrom
zeyap:export-D122870300
Dec 3, 2026
Merged

meta-codesync[bot] merged 1 commit into
react:mainfrom
zeyap:export-D122870300

Conversation

@zeyap

@zeyap zeyap commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

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

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 5, 2026
@facebook-github-tools facebook-github-tools Bot added p: Facebook Partner: Facebook Partner labels Oct 5, 2026
@meta-codesync

meta-codesync Bot commented Oct 5, 2026

Copy link
Copy Markdown

@zeyap has exported this pull request. If you are a Meta employee, you can view the originating Diff in D122870300.

@meta-codesync meta-codesync Bot changed the title Scope the TextInput spannable cache to the React instance Scope the TextInput spannable cache to the React instance (#58869) Oct 5, 2026
zeyap pushed a commit to zeyap/react-native that referenced this pull request Oct 5, 2026
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
@zeyap
zeyap force-pushed the export-D122870300 branch from aa811de to ecc0b42 Compare October 5, 2026 17:36
zeyap pushed a commit to zeyap/react-native that referenced this pull request Oct 6, 2026
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
@zeyap
zeyap force-pushed the export-D122870300 branch from ecc0b42 to f9dd1fe Compare October 6, 2026 00:31
zeyap pushed a commit to zeyap/react-native that referenced this pull request Oct 6, 2026
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
@zeyap
zeyap force-pushed the export-D122870300 branch from f9dd1fe to 748c414 Compare October 6, 2026 01:00
zeyap pushed a commit to zeyap/react-native that referenced this pull request Oct 6, 2026
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
@zeyap
zeyap force-pushed the export-D122870300 branch from 748c414 to 53eeb98 Compare October 6, 2026 01:04
zeyap pushed a commit to zeyap/react-native that referenced this pull request Oct 6, 2026
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
@zeyap
zeyap force-pushed the export-D122870300 branch from 53eeb98 to bd0c61b Compare October 6, 2026 01:26
zeyap pushed a commit to zeyap/react-native that referenced this pull request Oct 6, 2026
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
@zeyap
zeyap force-pushed the export-D122870300 branch from bd0c61b to 307162b Compare October 6, 2026 01:32
zeyap pushed a commit to zeyap/react-native that referenced this pull request Oct 6, 2026
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
@zeyap
zeyap force-pushed the export-D122870300 branch from 307162b to f67f239 Compare October 6, 2026 01:46
zeyap pushed a commit to zeyap/react-native that referenced this pull request Oct 6, 2026
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
@zeyap
zeyap force-pushed the export-D122870300 branch from f67f239 to 4abba0c Compare October 6, 2026 01:50
@mauricedoepke

Copy link
Copy Markdown

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

  • React Native 0.88.0, Android, New Architecture (bridgeless), release build (R8).
  • Android 12 (API 31) emulator, arm64.
  • The trigger is a reload of the React instance inside a running process. We used Detox's device.reloadReactNative(). An over-the-air update that restarts the app in place does the same reload, which is why this matters to us in production.

What happens

After the reload, changing the text of a controlled TextInput several times in quick succession sometimes throws:

java.lang.IllegalStateException: Required value was null.
    ... (three R8-minified frames)
    at com.facebook.react.fabric.FabricUIManager.measureText
    at com.facebook.jni.NativeRunnable.run(Native Method)
    at android.os.Handler.handleCallback(Handler.java:938)
    ...
    at com.facebook.react.bridge.queue.MessageQueueThreadImpl$Companion.startNewBackgroundThread$lambda$0

It reaches JS as Error: Non-JS exception: ... (in other runs as Error: Exception in HostFunction: ...), ReactHost.handleHostException runs within a few milliseconds, and the instance is destroyed. The process stays alive with a blank window. Nothing comes back by itself (we watched for 15 s); the user has to leave the app.

How we ran it, and the counts

One trial: reload the instance, focus one controlled input (value from state, onChangeText setting it), then change its text with Detox's replaceText, one character longer each time. Where a GC is forced, it is kill -10 <pid> on a rooted emulator (SIGUSR1, on which ART runs a collection). Same build and device for every arm.

arm crashes / trials
after a reload, 20 text changes in quick succession, GC forced as they start 2 / 20
after a reload, the same 20 text changes, nothing forced 1 / 20
cold start (no earlier instance in the process), the same 20 text changes, GC forced the same way 0 / 20
after a reload, a single text change, GC forced 0 to 160 ms before it 0 / 44

The crash in the unforced arm followed an ordinary NativeAlloc concurrent copying GC.

Why we think it is the finalizer path from the summary

  • In all three crashes above, the failure is logged right after a GC of the app's process and a System: A resource failed to call close. warning, which a finalizer logs: 4 ms, 13 ms and 83 ms after that warning.
  • Heap dumps taken after a reload and some typing show two ReactEditText objects with the same view id (26 in three of four reloads): the live one, and the previous instance's, unreachable, with its FinalizerReference still pending. After a forced GC that reference is gone.
  • The cold start never crashes with identical text changes and GC. The other explanation we had considered (state reaching the shadow node before the cache entry is written) would need neither an earlier instance nor a GC.

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 (AndroidTextInputShadowNode::updateStateIfNeeded resets cachedAttributedStringId to 0). For a controlled input that is roughly 10 to 30 ms per text change in our build. So a crash needs the old view at the same tag, not yet finalized, and a GC that finalizes it inside that window. Once the old view has been finalized the exposure is over, so it is about once per reload.

One crash, trimmed (forced-GC arm; the app's process only, log tags shortened)

21:21:06.919  I  SIGUSR1 forcing GC (no HPROF) and profile save
21:21:06.983  I  Explicit concurrent copying GC freed 328975(11MB) AllocSpace objects, 15(2524KB) LOS objects, 49% free, 21MB/42MB, paused 33us,21us total 64.085ms
21:21:06.984  W  System: A resource failed to call close.
21:21:06.988  E  ReactNativeJS: [Error: Non-JS exception: java.lang.IllegalStateException: Required value was null.
21:21:06.990  W  BridgelessReact: ReactHost{0}.handleHostException(message = "Error: Non-JS exception: java.lang.IllegalStateException: Required value was null.

Still present

TextLayoutManager.kt on main (a1b2862, 15 Nov), in v0.88.1 and in v0.89.0-rc.1 still has the single process-wide tagToSpannableCache and the checkNotNull(tagToSpannableCache[cacheId]), so apps that reload in place are exposed on all of them.

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.

@zeyap
zeyap force-pushed the export-D122870300 branch from 4abba0c to 785b743 Compare December 2, 2026 18:18
zeyap added a commit to zeyap/react-native that referenced this pull request Dec 2, 2026
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 Abbondanzo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

zeyap added a commit to zeyap/react-native that referenced this pull request Dec 2, 2026
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
@zeyap
zeyap force-pushed the export-D122870300 branch from 785b743 to 94147d5 Compare December 2, 2026 18:57
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>
@zeyap
zeyap force-pushed the export-D122870300 branch from 94147d5 to bd19b5b Compare December 2, 2026 23:34
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

Visual regression

No visual differences at bd19b5b76947.

ios: no capture

@meta-codesync
meta-codesync Bot merged commit 31ad1f3 into react:main Dec 3, 2026
40 of 41 checks passed
@react-native-bot

Copy link
Copy Markdown
Collaborator

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?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Dec 3, 2026
ide added a commit to expo/react-native that referenced this pull request Dec 4, 2026
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.
ide added a commit to expo/react-native that referenced this pull request Dec 5, 2026
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.
ide added a commit to expo/react-native that referenced this pull request Dec 5, 2026
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.
ide added a commit to expo/react-native that referenced this pull request Dec 5, 2026
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.
ide added a commit to expo/react-native that referenced this pull request Dec 5, 2026
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.
ide added a commit to expo/react-native that referenced this pull request Dec 5, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants