-
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
gatsby-develop | useState from react hooks doesn't work in development environment #9489
Comments
Caused by gaearon/react-hot-loader#1088 |
Hey, I wrap the function with React.memo() and it works 😆 |
The more proper fix import { cold } from 'react-hot-loader';
cold(MyComponent); // black list MyComponent. But state would be lost on update. |
Hmm, Edit: here's a reproduction - maybe I'm just doing something dumb? |
Potential automated fix? gaearon/react-hot-loader#1088 (comment) |
The |
This works, import { setConfig } from 'react-hot-loader';
setConfig({ pureSFC: true }); |
Yeah! Just confirmed it by modifying your original Codesandbox: https://codesandbox.io/s/rjqy5y6q3n |
Enabling |
Add the `setConfig` fix from gatsbyjs/gatsby#9489 (comment) to get Hooks working in develop mode using hot module reloading. This may cause issues where the data gets out of sync, but it’s the best we can hope for right now.
The
As a result, I've had to switch back to wrapping functions that use hooks with Thought I'd share in case any decisions are being made about how to permanently enable hooks for Gatsby users. |
Thanks for the heads up, @ooloth! This isn’t an Official Statement™ by any means, but I‘d call it a safe bet to assume that Gatsby won’t ship any hacks to get Hooks working. This issue will end up getting fixed upstream, and once there‘s a stable solution for hot reloading with Hooks — assuming it’s backward-compatible — we’ll bump the dependency and Hooks will Just Work. In the meantime, the hacks to get Hooks support will need to be implemented on a per-project basis by the devs wanting to use them. Hope that helps clear things up! |
This thing was broken by RHL, and should be fixed by RHL. |
Hmm... So, looks like Gatsby did end up deciding to ship a I'll check in with |
Is #10259 supposed to be enough? It still doesn't work for me unless I call
|
@wKovacs64 yeah - you can check out my repo which seems to work just fine for me. Does it not work for you? |
@ooloth whoops; sorry about that! I suppose a positive thing (for now) is that the error can be safely ignored as it's not impacting functionality. It does sound like an issue with react-spring (or perhaps RHL), unfortunately, so let us know how we can help resolve that! |
OK so it works alone, but not in my app. Sigh. 🙄 Will continue to narrow it down. |
@DSchau Yeah, it's probably fine! Always mildly alarming to see the console turn red lol, so just wanted to check. 😳 |
@DSchau It appears hooks aren't working in |
@DSchau I know nothing about the gatsby-browser-entry.js: setConfig({
pureSFC: true,
pureRender: true,
}) |
@wKovacs64 you're right--that does fix it! We won't want to go that way as we want this to be a develop only feature. I'm looking into this now! |
Apparently, the |
Any word on this, @DSchau? |
React-Hot-Loader 4.6.0 should work with hooks out of the box. |
@theKashey that's excellent! I'll check this out later this afternoon unless someone wants to jump on this :) |
@DSchau Upgrading doesn't look too complicated. I will open a PR soon if you don't mind 😃 |
@jgierer12 I was just about to push it, but you can if you'd rather. :) |
@jgierer12 not only do I not mind, that would be great :) Please do! @wKovacs64 @jgierer12 either of you feel free to open, and just reference this issue where we can all take a look! |
Go for it, @jgierer12! Get you some Gatsby swag. 😉 |
#10455 opened @wKovacs64 I already got some - but thanks anyways 💜 |
Fixes #9489 ~~The docs also [recommend](https://github.com/gaearon/react-hot-loader#react--dom) (but don't require) using a patched `react-dom`, but as I understand it that would override the user's `react-dom` version we have as a peer dependency so I left it out.~~ ➡️ 3894f0a /cc @wKovacs64
Fixes gatsbyjs#9489 ~~The docs also [recommend](https://github.com/gaearon/react-hot-loader#react--dom) (but don't require) using a patched `react-dom`, but as I understand it that would override the user's `react-dom` version we have as a peer dependency so I left it out.~~ ➡️ gatsbyjs@3894f0a /cc @wKovacs64
Which version of Gatsby is this fix applied to? |
@MarcCoet this was published in gatsby@2.0.69. If you are still experiencing issues with hooks I recommend you open a new issue and provide reproduction steps and the output of |
Thanks @jgierer12 . That is what I thought. I will dig a bit more. |
@MarcCoet are you using |
Apparently this is a known and expected bug? facebook/react#14257 |
@jlengstorf nope, not on that project but that is really good to know, thanks !! |
I was using |
Description
When running dev server, the state from react hooks is not working without any errors. It works, however, in production after compiling the files.
Steps to reproduce
yarn && gatsby develop
;gatsby build && gatsby serve
Expected result
The state from react-hooks should work in both dev/prod builds.
Actual result
The state from react-hooks is working only in production build.
Environment
The text was updated successfully, but these errors were encountered: