Webpack-based HMR removes style-tag in monorepo setup
See original GitHub issueDescribe the bug
Hi there! After upgrading to create-react-app v5 which uses webpack 5.73.0, HMR is breaking after almost every save in our monorepo setup.
I finally was able to create a minimal repro-case here: https://github.com/danielberndt/vanilla-extract-monorepo-issue
I’m attaching a recording of what is happening: When modifying a css file that is used in both its own package and another package within the monorepo, it’s style tag gets removed:
Interestingly it doesn’t seem to happen if the contents of frontend/src/App.js
get inlined into frontend/src/index.js
Let me know if you need any more details!
Reproduction
https://github.com/danielberndt/vanilla-extract-monorepo-issue
System Info
System:
OS: macOS 11.6.5
CPU: (6) x64 Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz
Memory: 277.28 MB / 20.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.13.0 - /usr/local/bin/node
Yarn: 1.22.10 - ~/.npm-global/bin/yarn
npm: 8.1.0 - /usr/local/bin/npm
Browsers:
Brave Browser: 88.1.20.110
Chrome: 103.0.5060.114
Firefox: 101.0.1
Safari: 15.5
Used Package Manager
yarn
Logs
No response
Validations
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created a year ago
- Comments:7
Top Results From Across the Web
Webpack-based HMR removes style-tag in monorepo setup
Hi there! After upgrading to create-react-app v5 which uses webpack 5.73.0, HMR is breaking after almost every save in our monorepo setup.
Read more >vanilla-extract - githubmemory
Vite plugin not working with monorepo on Windows. gyfchong ... Webpack-based HMR removes style-tag in monorepo setup. dalhaan.
Read more >vanilla-extract-css vanilla-extract Issues - Giters
@vanilla-extract/vite-plugin doesn't work with monorepo aliases. Closed 22 days ago 1 ... Webpack-based HMR removes style-tag in monorepo setup.
Read more >pseudo selector not being applied,about seek-oss/vanilla-extract ...
... Webpack-based HMR removes style-tag in monorepo setup HOT 5; @vanilla-extract/vite-plugin doesn't work with monorepo aliases · @vanilla-extract/css ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Okay, spent some more time, and Identified two issues:
../file.css.js
vs../../file.css.js
), it might result in a race condition that surfaces when hot-reloadingI tried to solve issue 1 with a cache (see comment above), but that’s not necessary. Instead you can change this: https://github.com/seek-oss/vanilla-extract/blob/f33b6a5b2f15dbd3457e1d47eb06864c9498bf51/packages/webpack-plugin/src/loader.ts#L91-L94 into this:
i.e. replace
fileName
withpath.resolve(fileName)
.Issue number 2 can be solved by telling webpack to not put node-module requests into the vendors chunk if the request also includes
vanilla-extract
.this is what my updated
overrides-config.js
looks like:i.e. using
test: '[\\/]node_modules[\\/](?!.*vanilla-extract)'
to tell webpack to ignore vanilla-extract requests for the vendors chunk.Applying both changes to our project results in a buttery smooth webpack 5 experience.
Happy to open a PR for issue 1. Issue 2 probably needs to be added to the docs. It might be the case that the config above can be simplified a lot. Not sure though whether this config wouldn’t be beneficial for production-builds too (i.e. don’t associate all css files with a single vendors-chunk)
Fix 2 for HMR works very well for me too, thanks! 🥳