Skip to content

"Cannot read properties of null (reading 'removeChild')" during flutter run #192226

Closed

Description

@goderbauer

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):

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

  1. goderbauer commented on Sep 3, 2026

    @goderbauer
    MemberAuthor
  2. added
    in triagePresently being triaged by the triage team
    toolAffects the "flutter" command-line tool. See also t: labels.
    team-webOwned by Web platform team
    platform-webWeb applications specifically
    and removed
    in triagePresently being triaged by the triage team
    on Sep 3, 2026
  3. goderbauer commented on Sep 3, 2026

    @goderbauer
    MemberAuthor

    Did a little more digging:

    The websocket's onReconnect is set to initializeConnection [1], which (via _launchCommunicationWithDebugExtension [2]) unconditionally sends dart-app-ready events [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-ready events 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:

    document.addEventListener('dart-app-ready', function (e) {
    loader.parentNode.removeChild(loader);
    styleSheet.parentNode.removeChild(styleSheet);
    });

    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?

  4. github-actions commented on Sep 22, 2026

    @github-actions

    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 -v and a minimal reproduction of the issue.

  5. locked as resolved and limited conversation to collaborators on Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    platform-webWeb applications specificallyteam-webOwned by Web platform teamtoolAffects the "flutter" command-line tool. See also t: labels.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions