Skip to content

isUnloading flag stuck as true after user cancels "Leave site?" dialog, blocking HMR/Live Reload #5571

@nakjun12

Description

@nakjun12

Bug report

isUnloading flag stuck as true after user cancels "Leave site?" or "Reload Site?" dialog, blocking HMR/Live Reload

Actual Behavior

Image

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?

  1. Set up a minimal project with webpack and webpack-dev-server
  2. Use the provided example code that includes dynamic beforeunload event controls (I will provide an example in the PR that fixes this issue at examples/client/beforeunload)
  3. Run npx webpack serve
  4. Open the page in a browser
  5. Click the "Add Beforeunload Event" button to activate the beforeunload listener
  6. Click the "Reload Page" button (or press the browser's refresh button)
  7. When the "Leave site?" dialog appears, click "Cancel"
  8. Make a change to a source file (examples/client/beforeunload/app.js - modify it to trigger HMR)
  9. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions