Skip to content

Hook state #1299

@dmarkow

Description

@dmarkow

Description

Saving a file using hooks (specifically useState) can sometimes unmount/remount the component. This only started happening after 4.12.0

Expected behavior

State should be preserved across hot reloads (which it did up to and including 4.12.0).

Actual behavior

State is reset since version 4.12.1

Environment

React Hot Loader version: 4.12.6

Run these commands in the project folder and fill in their results:

  1. node -v: v12.6.0
  2. npm -v: 6.9.0

Then, specify:

  1. Operating system: macOS 10.14.5
  2. Browser and version: Chrome 75.0.3770.100

Reproducible Demo

https://github.com/dmarkow/react-hot-loader-hooks-issue

Run the start-working script to launch with 4.12.0 which works fine. Run the start-broken script to launch with 4.12.6 which is broken.

Change something inside the Counter.js file (e.g. add some text to the "Counter: " output) and save. The first save it'll update the text and keep the counter running. However, save again without changing anything and it'll reset the counter and print the "Unmounting" message showing that the component got remounted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions