-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Bug report
isUnloading flag stuck as true after user cancels "Leave site?" or "Reload Site?" dialog, blocking HMR/Live Reload
Actual Behavior

When a user cancels the native confirmation dialog triggered by a beforeunload
event listener, the webpack-dev-server
client's internal state (isUnloading
) gets stuck as true
.
This causes all subsequent HMR and live reloads from file changes to be completely ignored, forcing the developer to manually refresh the page to see any updates.
Expected Behavior
After canceling the beforeunload
confirmation dialog, the client's internal state should properly reset to reflect that the page is no longer unloading. Subsequent file changes should trigger HMR or live reloads as expected, without requiring a manual refresh.
How Do We Reproduce?
- Set up a minimal project with webpack and webpack-dev-server
- Use the provided example code that includes dynamic
beforeunload
event controls (I will provide an example in the PR that fixes this issue atexamples/client/beforeunload
) - Run
npx webpack serve
- Open the page in a browser
- Click the "Add Beforeunload Event" button to activate the
beforeunload
listener - Click the "Reload Page" button (or press the browser's refresh button)
- When the "Leave site?" dialog appears, click "Cancel"
- Make a change to a source file (
examples/client/beforeunload/app.js
- modify it to trigger HMR) - Observe: The page does not update
Note: I've prepared cases for live reload and cases that execute when HMR fails.
This example is intentionally designed to cause HMR to fail and trigger a full page reload to reproduce the issue more reliably, because issue #841 deals with refresh cases and the issue described in #841 does not occur with regular HMR.
Please paste the results of npx webpack-cli info
here, and mention other relevant information
System:
OS: Windows 10 10.0.19045
CPU: (12) x64 Intel(R) Core(TM) i5-10400 CPU @ 2.90GHz
Memory: 3.01 GB / 15.94 GB
Binaries:
Node: 22.14.0 - C:\Program Files\nodejs\node.EXE
Yarn: 4.6.0 - C:\Program Files\nodejs\yarn.CMD
npm: 10.9.2 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Chromium (139.0.3405.111)
Internet Explorer: 11.0.19041.5794
Additional Context
Confirmed this is related to existing work in #1611 and #841, which address similar beforeunload
event handling issues.