fix(hmr): only reconnect a closed WebSocket on visibilitychange/online
The visibilitychange/online handlers added in #91416 replace the HMR WebSocket whenever it is not OPEN. A socket that is still CONNECTING was replaced too, which closes it and fires its disconnect handler; that handler schedules another reconnect one second later, which closes the new socket, and so on indefinitely. Chrome activates prerendered pages (Speculation Rules, omnibox preloading) while the deferred WebSocket handshake is still pending, so every prerendered dev page hit this. If the first socket had already reached the server it also consumed the React debug channel for the request, and the page never hydrated. Only reconnect when the socket is CLOSED. By then the disconnect handler has already run and only a retry timer is pending, so the sleep/wake reconnect keeps working. Fixes #98212
Showing
Please
register
or
sign in
to comment