-
Notifications
You must be signed in to change notification settings - Fork 46.7k
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
.currentDispatcher gets set to null when calling ReactDOMServer from ReactDOM #14022
Comments
This happens because when renderToStaticMarkup exits, it sets currentDispatcher to null in the shared React package:
Instead of setting it to its previous value. (ReactFiberScheduler does the same.) That means that when you call useState in the child component, there is no dispatcher present. @acdlite Thoughts? Should we restore the old value? |
I think we should since it's a legit (even if not recommended) use case to call e.g. |
For those of you using next.js, the issue was resolved for me (temporarily) by just dropping the custom |
Is there a simple way to know if a particular commit has been added to a certain React version? I'm using |
Hey guys! Still having this error - I think it's this! - on SSR works fine and the error throws on Also I am using Here is my
Is anybody else having a similar problem? 😄 |
Hey everybody! Still same error! I upgraded Then I decided to try As soon as I do SSR SSR load works 100% a-okay, and as soon as we hydrate we get a blank page and invariant violation This is has been happening for months now! And this issue is already referenced from #13972 I cannot believe it is so edge-case that we cannot fix it?? |
@edoardo-bluframe How have you managed to work around this? |
@joaquindk Totally not! Cannot use hooks on an Apollo SSR project Really nobody wants to fix it?? |
I am super stuck on this, too. But if you download and install/run it, it fails with this hook error. Can't figure out any workaround. |
I got the same 'Invalid Hook Call' Error. Reached to the point of ReactCurrentDispatcher.current is null. Found out react instance duplication due to having a custom distDir in Next.js (And obviously my mistake) |
FYI I ended up fixing it... by moving all my React SSR projects to NextJS 😄 It does make setting up SSR child's play and the caching features are fantastic Very glad that I used a manual SSR setup before and got to work out the ins and outs! |
I happened to notice that React will throw
Hooks can only be called inside the body of a function component
if a sibling element callsReactDOMServer.renderToStaticMarkup
. I have a fiddle that shows this behavior (I think you need to manually open your console to see the error).If you wrap the sibling element in a component or even just assign it a variable, this issue does not occur.
It's easy to get around and is a pretty specific bug, but why might this be happening?
The text was updated successfully, but these errors were encountered: