Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hot reloading doesn't work with CSS-in-JS components in certain conditions #10433

Closed
7 tasks done
tigranpetrossian opened this issue Oct 11, 2022 · 3 comments
Closed
7 tasks done
Labels
duplicate This issue or pull request already exists

Comments

@tigranpetrossian
Copy link

Describe the bug

I'm observing a strange behavior with Vite, when changes to components created with libraries like styled-components do not reflect in the browser, despite HMR running seemingly in a correct manner.

This only happens when the styled component in question is exported and used elsewhere, and is colocated with any other component in the same file (See reproduction).

In order to rule out a particular styling library being the culprit, I've tested this with two different libraries: Stitches and Styled Components, the behavior is exactly the same.

Reproducible in StackBlitz + Additional repository with reproduction

Reproduction

https://stackblitz.com/edit/vitejs-vite-qu9hvs?file=src%2FApp.jsx&terminal=dev

Steps to reproduce

  1. Open Component.stitches.jsx
  2. Change backgroundColor of ComponentToHotReload to 'blue' - no changes in the browser
  3. Comment out RandomComponent
  4. Reload the browser
  5. Change backgroundColor of ComponentToHotReload again - updates are reflected

Same is reproducible for Component.styled-components.jsx
Check the mentioned files for more details.

System Info

System:
    OS: macOS 12.1
    CPU: (10) x64 Apple M1 Pro
    Memory: 29.89 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.18.2 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 8.12.2 - /usr/local/bin/npm
  Browsers:
    Chrome: 106.0.5249.103
    Firefox: 104.0.2
    Safari: 15.2

And StackBlitz

Used Package Manager

yarn

Logs

No response

Validations

@PsySolix
Copy link

PsySolix commented Oct 11, 2022

Hmm I'm encountering something similar. The HMR does not trigger correctly when using CSSModules in React and changing something in the *.module.css.

How to reproduce:
When you for example add a *.module.css to a React Component (build with react-ts template & pnpm): Like so import { footer, footerMenu } from "./Footer.module.css";
Footer.module.css contains: .footer {} .footerMenu {}

You can change the Footer.module.css as much as you want, the HMR will not trigger and no refresh happens.. At least on my side?

**Something related? **

@PsySolix
Copy link

I do want to mention, a workaround for now is setting es2020 in tsconfig.json (mentioned in another open issue)

As soon as I changed that the Vite dev server auto restarted and started picking up changes in *.module.css files again! :D

@sapphi-red
Copy link
Member

Duplicate of vitejs/vite-plugin-react#6

@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Oct 14, 2022
@sapphi-red sapphi-red added duplicate This issue or pull request already exists and removed pending triage labels Oct 14, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Oct 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants