Skip to content

React Fast Refresh (HMR) not working with styled components in certain conditions #26

Closed
@robertmusil

Description

@robertmusil

Describe the bug

When using styled components (@emotion/styled in my case) if the file contains any other react-like-components (detected by isComponentLikeIdentifier) and doesn't contain any other non-react-like exports, then changes to those styled components are not properly refreshed by HMR.

All the react-like-components are being refreshed by $RefreshReg$ and the file is accepted, but styled components in that case are not caught in the refresh.

If, however, there are other non-component-like exports or there aren't any other component-like identifiers then the file is not accepted and refreshes properly by its parent(s) being HMR'd

Reproduction

https://codesandbox.io/s/vite-emotion-hmr-bug-rkk0hi?file=/src/HmrTest.tsx

Steps to reproduce

Steps to reproduce described in comments in minimal reproduction

System Info

sandbox@sse-sandbox-rkk0hi:/sandbox$ npx envinfo --system --npmPackages '{vite,@vitejs/*}' --binaries --browsers
npx: installed 1 in 0.915s

  System:
    OS: Linux 5.4 Debian GNU/Linux 10 (buster) 10 (buster)
    CPU: (16) x64 Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
    Memory: 8.26 GB / 62.72 GB
    Container: Yes
    Shell: 5.0.3 - /bin/bash
  Binaries:
    Node: 14.19.3 - ~/.nvm/versions/node/v14.19.3/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v14.19.3/bin/yarn
    npm: 6.14.17 - ~/.nvm/versions/node/v14.19.3/bin/npm
  npmPackages:
    @vitejs/plugin-react: ^2.1.0 => 2.2.0
    @vitejs/plugin-react-refresh: ^1.3.1 => 1.3.3
    vite: ^3.1.0 => 3.2.4

Used Package Manager

yarn

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: hmrp3-minor-bug 🔨An edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions