question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.currentDispatcher gets set to null when calling ReactDOMServer from ReactDOM

See original GitHub issue

I happened to notice that React will throw Hooks can only be called inside the body of a function component if a sibling element calls ReactDOMServer.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?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
edoardo-bluframecommented, Jun 6, 2019

Hey everybody!

Still same error!

I upgraded react, react-dom, react-apollo and everything else to latest yesterday

Then I decided to try useState again and…

As soon as I do SSR hydrate in production it breaks

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??

5reactions
edoardo-bluframecommented, Feb 17, 2019

Hey guys!

Still having this error - I think it’s this! - on react@16.8.2, SSR, and react-apollo@2.4.1

SSR works fine and the error throws on React.hydrate

Also I am using react-loadable@5.5.0

Here is my index.js

// @flow
/* eslint-disable react/jsx-max-depth */

import "intersection-observer"
import { ApolloProvider } from "react-apollo"
import App from "./app"
import { AppContainer } from "react-hot-loader"
import { BrowserRouter } from "react-router-dom"
import Loadable from "react-loadable"
import React from "react"
import ReactDOM from "react-dom"
import graphql from "api"

const app = document.getElementById("app")

const shell = Component => (
  <ApolloProvider client={graphql}>
    <AppContainer>
      <BrowserRouter>
        <Component />
      </BrowserRouter>
    </AppContainer>
  </ApolloProvider>
)

const render = Component => {
  if (app !== null) {
    // eslint-disable-next-line no-process-env
    if (process.env.NODE_ENV === "development") {
      ReactDOM.render(shell(Component), app)
    } else {
      Loadable.preloadReady().then(() => {
        ReactDOM.hydrate(shell(Component), app)
      })
    }
  }
}

render(App)

// Webpack Hot Module Replacement API
if (module.hot) {
  module.hot.accept("./app", () => {
    // eslint-disable-next-line global-require
    render(require("./app").default)
  })
}

Is anybody else having a similar problem? 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hooks can only be called inside the body of a function ...
Whenever I try and use a hook in my app, I get the Hooks can only be called inside the body of a...
Read more >
ReactDOMServer – React
If you call ReactDOM.hydrateRoot() on a node that already has this server-rendered markup, React will preserve it and only attach event handlers, ...
Read more >
How Does setState Know What to Do? - Overreacted
When you call setState in a component, what do you think happens? import React from 'react'; import ReactDOM from 'react-dom'; class Button ...
Read more >
react-dom | Yarn - Package Manager
React DOM. Provide a component stack as a second argument to onRecoverableError . (@gnoff in #24591); Fix hydrating into document causing a blank...
Read more >
Managing DOM components with ReactDOM - LogRocket Blog
With Server-Side Rendering, we don't render an empty page anymore. With this approach, the server creates static HTML files which the browser ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found