Commit f03c680
committed
fix(desktop): guard splash-stage teardown races (#6136)
Both pre-existing and the new structural test cases surface two
sub-races between setSplashStage β applySplashStage β
executeJavaScript and the splash BrowserWindow lifecycle:
1. Pre-load destroy (race 1): a stage is deferred while the splash
page is still loading. Before did-finish-load fires, the splash
window is destroyed. The existing registerSplashStageTracking
replay callback unconditionally called applySplashStage on the
destroyed surface, causing executeJavaScript to throw
synchronously in Electron's teardown path. Fix: bail out of the
replay when splash.isDestroyed() OR splash.webContents.isDestroyed().
2. Check-to-call destroy (race 2): the splash survives the
isDestroyed() check in setSplashStage, but the underlying
webContents is torn down before executeJavaScript runs.
Electron throws TypeError("Object has been destroyed")
synchronously β not as a rejected Promise β so the existing
.catch(() => undefined) does not catch it and the exception
escapes to the process. Fix: wrap the entire
executeJavaScript + .catch sequence in try/catch and also
short-circuit via webContents.isDestroyed() before the call.
SplashStageSurface gains webContents.isDestroyed() to the
structural type so callers (both production code and the mock in
the test) can explicitly probe renderer readiness.
Changes:
- apps/desktop/src/main/runtime.ts:
- Add webContents.isDestroyed() to SplashStageSurface type.
- applySplashStage: short-circuit via splash/isDestroyed checks
and wrap executeJavaScript in try/catch.
- registerSplashStageTracking: bail out of the did-finish-load
replay when the surface or its webContents is already destroyed.
- apps/desktop/tests/main/splash-stage-replay.test.ts:
- Add webContents.isDestroyed() to createMockSplash.
- New test: splash destroyed before did-finish-load β no-op.
- New test: sync throw from executeJavaScript β not thrown.
All pre-existing desktop test failures (missing @open-design/download
resolve) are pre-existing and unrelated to this change. The splash
stage replay tests typecheck clean on this branch.
Fixes #6136
Signed-off-by: xxiaoxiong <2482929840@qq.com>1 parent 6b90486 commit f03c680
2 files changed
Lines changed: 76 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1308 | 1308 | | |
1309 | 1309 | | |
1310 | 1310 | | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
1311 | 1319 | | |
1312 | 1320 | | |
1313 | 1321 | | |
1314 | 1322 | | |
| 1323 | + | |
1315 | 1324 | | |
1316 | 1325 | | |
1317 | 1326 | | |
| |||
1324 | 1333 | | |
1325 | 1334 | | |
1326 | 1335 | | |
1327 | | - | |
1328 | | - | |
1329 | | - | |
1330 | | - | |
1331 | | - | |
1332 | | - | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
1333 | 1356 | | |
1334 | 1357 | | |
1335 | 1358 | | |
| |||
1345 | 1368 | | |
1346 | 1369 | | |
1347 | 1370 | | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
1348 | 1376 | | |
1349 | 1377 | | |
1350 | 1378 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| 36 | + | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
| |||
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
| 52 | + | |
50 | 53 | | |
51 | 54 | | |
52 | 55 | | |
| |||
100 | 103 | | |
101 | 104 | | |
102 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
103 | 145 | | |
104 | 146 | | |
105 | 147 | | |
| |||
0 commit comments