Repository navigation
Commit 78ca392
authored
[flutter_tools] Safely remove web loading indicator on dart-app-ready (flutter#192233)
Fixes flutter#192226
### Problem
In `packages/flutter_tools/lib/src/web/bootstrap.dart`, when compiling
the web bootstrap script (`main.dart.js`), an event listener was added
to `window` for `dart-app-ready` that executed:
```javascript
loader.parentNode.removeChild(loader);
```
On initial load, this removes the loader from the DOM, setting
`loader.parentNode` to `null`.
When DWDS reconnects or re-dispatches `dart-app-ready` (e.g. following a
WebSocket disconnect/reconnect), this listener was invoked again.
Attempting to call `.removeChild` on a `null` `parentNode` threw:
```
TypeError: Cannot read properties of null (reading 'removeChild')
```
### Solution
1. Use `loader.remove()` and `styleSheet.remove()` instead of
`parentNode.removeChild()`.
2. Configure the event listener with `{ once: true }` so it is
automatically removed after firing once.
### Tests
Added regression unit tests to
`packages/flutter_tools/test/general.shard/web/bootstrap_test.dart`
verifying that `{ once: true }` and `.remove()` are used in generated
web bootstrap code.1 parent 45f4e3d commit 78ca392
2 files changed
Lines changed: 37 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
348 | 348 | | |
349 | 349 | | |
350 | 350 | | |
351 | | - | |
352 | | - | |
353 | | - | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
354 | 354 | | |
355 | 355 | | |
356 | 356 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
61 | 77 | | |
62 | 78 | | |
63 | 79 | | |
| |||
249 | 265 | | |
250 | 266 | | |
251 | 267 | | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
252 | 286 | | |
253 | 287 | | |
254 | 288 | | |
| |||
0 commit comments