Repository navigation
Description
I occasionally see the following error in my browser console when running flutter run --machine -d web-server --web-port 3000 --web-hostname 0.0.0.0 and accessing the app in my browser:
Uncaught TypeError: Cannot read properties of null (reading 'removeChild')
at HTMLDocument.<anonymous> (main.dart.js:71:22)
at Object._dispatchEvent (client.js:8429:44)
at StaticClosure.initializeConnection (client.js:8321:9)
at client.js:17625:24
at _wrapJsFunctionForAsync_closure.$protected (client.js:3873:17)
at _wrapJsFunctionForAsync_closure.call$2 (client.js:11771:12)
at _awaitOnObject_closure.call$1 (client.js:11759:32)
at Zone._runUnaryZoned$2$3 (client.js:13278:27)
at _Future__propagateToListeners_handleValueCallback.call$0 (client.js:12192:38)
at Object._Future__propagateToListeners (client.js:4066:93)
at _Future._completeWithValue$1 (client.js:12030:9)
at _Future__asyncCompleteWithValue_closure.call$0 (client.js:12114:18)
at Zone._runZoned$1$2 (client.js:13260:25)
at Zone.runGuarded$1 (client.js:13165:20)
at Zone_bindCallbackGuarded_closure.call$0 (client.js:13388:25)
at Object._microtaskLoop (client.js:4128:24)
at StaticClosure._startMicrotaskLoop (client.js:4134:11)
at _AsyncRun__initializeScheduleImmediate_internalCallback.call$1 (client.js:11676:9)
I don't have a reliable way of reproducing it, but it appears to happen when the WebSocket connection temporarily drops and is reconnected. I wonder, if the reconnection (or something else) causes the dart-app-ready event to be fired multiple times, which causes this code to run multiple times (and crash after the first time because the child has already been removed):
flutter/packages/flutter_tools/lib/src/web/bootstrap.dart
Lines 350 to 353 in 0c2d270
| document.addEventListener('dart-app-ready', function (e) { | |
| loader.parentNode.removeChild(loader); | |
| styleSheet.parentNode.removeChild(styleSheet); | |
| }); |
Should this event listener maybe be removed after it has removed the loader so it doesn't attempt to remove it a second time? Or maybe the dart-app-ready event shouldn't be fired multiple times in the first place?
Activity
goderbauer commentedon Sep 3, 2026
cc @bkonyi
goderbauer commentedon Sep 3, 2026
Did a little more digging:
The websocket's
onReconnectis set toinitializeConnection[1], which (via_launchCommunicationWithDebugExtension[2]) unconditionally sendsdart-app-readyevents [3].[1] https://github.com/dart-lang/webdev/blob/4855a315fa9ce5e06680a0230ac6fe68846a4b76/dwds/web/client.dart#L71-L78
[2] https://github.com/dart-lang/webdev/blob/4855a315fa9ce5e06680a0230ac6fe68846a4b76/dwds/web/client.dart#L301-L313
[3] https://github.com/dart-lang/webdev/blob/4855a315fa9ce5e06680a0230ac6fe68846a4b76/dwds/web/client.dart#L387
So it seems like its possible that multiple
dart-app-readyevents are dispatched when websocket connections disconnect and reconnect, but Flutter's bootstrapping code is not prepared to handle multiple and crashes on subsequent events after the loader has been removed in response to the first event:flutter/packages/flutter_tools/lib/src/web/bootstrap.dart
Lines 350 to 353 in 0c2d270
Unsure if the right fix is to prevent multiple events from getting sent in the first place or whether bootstrap.dart needs to be able to handle multiple events without crashing?
[flutter_tools] Safely remove web loading indicator on dart-app-ready (…
github-actions commentedon Sep 22, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.