Repository navigation
Commit fb19d4e
Pull the transaction that stops a surface in the pull model (#59030)
Summary:
With `enableMountingCoordinatorPullModelAndroid`, the UI thread pulls a surface's transaction through `FabricUIManagerBinding`'s surface registry. `stopSurfaceWithSurfaceHandler` removes the surface from the registry before `SurfaceHandler::stop()` commits the empty tree, so the transaction that deletes the surface's views is never pulled. Mounting override delegates such as LayoutAnimations and C++ Animated never see those Deletes. With `enableLayoutAnimationsOnAndroid`, a layout animation that is running when its surface stops stays in flight. `FabricUIManager` then calls `driveCxxAnimations` on every frame until another surface pulls a transaction.
This PR:
- Pulls and executes a commit on the commit thread in `schedulerShouldRenderTransactions` when its surface is not registered, as push does.
- Makes `stopSurface(int)` unregister the surface before stopping it, like `stopSurfaceWithSurfaceHandler`.
- Registers a bridgeless surface before `SurfaceHandler::start()`, like `startSurface` and `startSurfaceWithConstraints`. Otherwise a commit made during the start would also take the commit-thread path and mount after the next pull. Only a stopping surface now commits while unregistered.
- Skips a registered surface that is not running in `pullAndExecuteTransaction` and `reportMount`. A restarted surface keeps its id and is now registered before it starts, so a pull left over from its previous run could reach it before it has a shadow tree.
The legacy `setConstraints` commits while it holds the registry's shared lock, so the new registry check nests a shared lock there. `pullAndExecuteTransaction` already does the same on main.
## Changelog:
[ANDROID] [FIXED] - Pull the transaction that stops a surface with `enableMountingCoordinatorPullModelAndroid`
Test Plan:
New `FabricMountingManagerInstrumentationTest` cases drive a real `FabricUIManagerBinding`. The test helper commits to the surface's shadow tree directly, without JavaScript. The pull-model cases run with the Props 2.0 flags and `enablePreallocatedPropsDiffOnInsertAndroid`.
| Test | Without the fix | With the fix |
| --- | --- | --- |
| `native_stopSurfaceWithSurfaceHandler_pullModel_pullsDeletes` | fails: no Deletes are pulled | passes |
| `native_stopSurfaceWithSurfaceHandler_pushModel_pullsDeletes` | passes | passes |
| `native_startSurfaceWithSurfaceHandler_pullModel_mountsCommitDuringStartInOrder` | passes | passes |
| `native_registeredSurfaceThatIsNotRunning_pullModel_skipsPullAndMountReport` | crashes in `SurfaceHandler::getMountingCoordinator()` | passes |
The start test passes on main, where nothing takes the commit-thread path. It guards the registration order: with the fallback in place but the surface registered after `start()`, it fails with the views mounted as `[42, 43]` instead of `[43, 42]`.
The test class has no Gradle target in the open-source repository, so I ran it on an Android emulator through a local androidTest source set:
```
./gradlew :packages:react-native:ReactAndroid:assembleReleaseAndroidTest -PreactNativeArchitectures=arm64-v8a
adb install -r -t packages/react-native/ReactAndroid/build/outputs/apk/androidTest/release/ReactAndroid-release-androidTest.apk
adb shell am instrument -w -e class com.facebook.react.fabric.FabricMountingManagerInstrumentationTest \
com.facebook.react.tests.gradle/androidx.test.runner.AndroidJUnitRunner
```
With the fix, the whole class passes.
I also used RNTester with a temporary hook: the Playground starts a 60 s `LayoutAnimation`, then `ReactDelegate.unloadApp()` stops the surface while the activity stays resumed. Props 2.0 and `enableLayoutAnimationsOnAndroid` were on:
| | Before | After |
| --- | --- | --- |
| Pull | no `onAllAnimationsComplete`; `driveCxxAnimations` still runs every frame 100 s after the stop | `onAllAnimationsComplete` right after the stop, then no more frames |
| Push | `onAllAnimationsComplete` right after the stop | same |
Differential Revision: D124966432
Pulled By: bartlomiejbloniarz1 parent 8d61635 commit fb19d4e
6 files changed
Lines changed: 433 additions & 53 deletions
File tree
- packages/react-native/ReactAndroid/src
- main/jni/react/fabric
- test_helper
- test/java/com/facebook/react/fabric
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
38 | 65 | | |
39 | 66 | | |
40 | 67 | | |
| |||
89 | 116 | | |
90 | 117 | | |
91 | 118 | | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
108 | 123 | | |
109 | 124 | | |
110 | 125 | | |
| |||
130 | 145 | | |
131 | 146 | | |
132 | 147 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
| 148 | + | |
147 | 149 | | |
148 | 150 | | |
149 | 151 | | |
| |||
169 | 171 | | |
170 | 172 | | |
171 | 173 | | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
172 | 179 | | |
173 | 180 | | |
174 | 181 | | |
| |||
195 | 202 | | |
196 | 203 | | |
197 | 204 | | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
198 | 212 | | |
199 | 213 | | |
200 | 214 | | |
| |||
208 | 222 | | |
209 | 223 | | |
210 | 224 | | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | 225 | | |
218 | 226 | | |
219 | 227 | | |
| |||
459 | 467 | | |
460 | 468 | | |
461 | 469 | | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
462 | 473 | | |
463 | 474 | | |
464 | | - | |
465 | | - | |
466 | | - | |
467 | | - | |
468 | | - | |
469 | | - | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
470 | 482 | | |
471 | | - | |
472 | | - | |
473 | | - | |
474 | | - | |
475 | | - | |
476 | | - | |
477 | | - | |
478 | | - | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
479 | 489 | | |
480 | 490 | | |
481 | 491 | | |
| |||
727 | 737 | | |
728 | 738 | | |
729 | 739 | | |
730 | | - | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
731 | 745 | | |
732 | 746 | | |
733 | 747 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
| 140 | + | |
| 141 | + | |
140 | 142 | | |
141 | 143 | | |
142 | 144 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
| 12 | + | |
| 13 | + | |
11 | 14 | | |
12 | 15 | | |
13 | 16 | | |
| 17 | + | |
14 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
15 | 22 | | |
16 | 23 | | |
17 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
18 | 60 | | |
19 | 61 | | |
20 | 62 | | |
| |||
81 | 123 | | |
82 | 124 | | |
83 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
84 | 229 | | |
85 | 230 | | |
86 | 231 | | |
| |||
99 | 244 | | |
100 | 245 | | |
101 | 246 | | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
102 | 270 | | |
103 | 271 | | |
104 | 272 | | |
| |||
0 commit comments