-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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 CSS broken when component lives in wrapPageElement #23606
Comments
Some more info: I tried to just manually wrap every page in I think this might not be related to wrapPageLayout, but nested components? |
Are you sure about case of wrapping every page in I can for sure reproduce this problem when using Just so there is no misunderstandings here - way I understand manually wrapping means to me something like we do in default starter - https://github.com/gatsbyjs/gatsby-starter-default/blob/95a4d12f3341460c638dde2fbf13c5f2c9b04cdc/src/pages/index.js#L9-L18 where each page uses |
Can you also try running This will use |
It appears to me that with default module hot reloading (using gatsby/packages/gatsby/src/bootstrap/requires-writer.js Lines 148 to 170 in fbdb4de
The I have tracked when we started applying It seems to work with |
Great - thanks for the explanation. I tried once again with just wrapping the page in my Switching to fast refresh does fix the issue though! SO that is a good solution |
Do you know if I can stick |
Is there a plan to switch to Fast Refresh by default? React Hot Loader is extremely fragile and I hope we can phase it out asap. |
Unfortunately this will likely not work right now. We are aware of this and do plan improvement and streamlining those for next major - #21004 but those will need breaking changes so those are reserver for v3.
Yes! We just can't do it in version 2 of Gatsby, because it still supports
So we do hope that timing will align and |
Shoot it seems like the new hot reloading works for CSS, but is broken for my react components. It gives me: Ignored an update to unaccepted module ./src/pages/index.js -> ./.cache/sync-requires.js -> ./.cache/app.js -> 0
[HMR] The following modules couldn't be hot updated: (Full reload needed)
This is usually because the modules which have changed (and their parents) do not know how to hot reload themselves. See https://webpack.js.org/concepts/hot-module-replacement/ for more details.
[HMR] - ./src/pages/index.js And doesn't even refresh the page. |
What does your |
That's just a template we copy paste in all new packages. It's been used in React Native for almost a year now and is stable. The part that needs work is how it's integrated. I'm assuming you are doing this via the current webpack plugin? That plugin needs more work to be good. |
@gaearon - looks like a restart solved it for now - will keep an eye on what causes if it if happens again |
@wesbos Are you using wrapPageElement or gatsby-plugin-layout? With wrapPageElement |
I'm using wrapPageElement |
Updated react-refresh README. facebook/react@5b89d35 |
Ah, you sorted it out, good stuff. The ol' plug it-out-and-plug-it-back-in-again trick! :) |
There is some bugginess with
We use |
You might want to track pmmmwh/react-refresh-webpack-plugin#75. @Timer has forked the plugin for Next, using a new webpack feature (which was also backported into 4.x) to improve the resilience. We need to get those changes merged back into the |
@gaearon I'm absolutely tracking all of this :) Here's our rough plan of action:
Since fast-refresh should fix these rough edges for us, I don't think it's worth our effort fixing this in hot-loader as it will eventually be fully replaced. |
Oh. I am waiting for this for the half year. |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. Thanks for being a part of the Gatsby community! 💪💜 |
Still an issue, can be closed if Gatsby ships fast-refresh as default and this doesn't need fixing |
Thanks @wesbos! It should be the default in v3 |
Description
I'm using Styled Components (and the gatsby plugin for it) but I can confirm this is an issue with CSS modules as well.
Hot reloading of CSS works great when you are editing a component on a page.
However if you use the wrapPageElement or wrapRootElement API in
gatsby-browser.js
and have a styled component that lives in that layout, it's reloads the whole page - losing at state you might have.So for example, if I have a Layout component:
And then either in Layout.js directry, or inside of another component - like Nav - I have my styled component:
Now if I change
green
toblue
. The whole page reloads.If I were to move that Nav component out of
Layout.js
and into a page likepages/index.js
, it hot reloads fine without reloading the page.Environment
This happens in both Firefox and Chrome
System:
OS: macOS 10.15.2
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 13.9.0 - /usr/local/bin/node
Yarn: 1.22.0 - /usr/local/bin/yarn
npm: 6.13.7 - /usr/local/bin/npm
Languages:
Python: 2.7.15 - /usr/local/bin/python
Browsers:
Chrome: 81.0.4044.122
Firefox: 59.0.1
Safari: 13.0.4
npmGlobalPackages:
gatsby: 2.15.14
The text was updated successfully, but these errors were encountered: