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.

Gatsby hydration/client-side re-render issue

See original GitHub issue

Describe the bug The first client-side re-render (or hydration?) causes the global styles (styles.global) to get “lost”.

Using:

  • gatsby
  • reflexjs

To Reproduce

  1. Add page
// src/pages/hydration-issue.js
import { Link } from "gatsby"
import * as React from "react"

export default function HydrationIssuePage() {
  return (
    <div sx={{bg: "red"}}>
      <div sx={{variant: "container"}}>
        <h1>Hello</h1>
        <p>World!</p>
        <Link to="/"><span sx={{variant: "text.link"}}>Go home</span></Link>
      </div>
    </div>
  )
}
  1. Run gatsby build && gatsby serve
  2. Open browser, hover over link in page hydration-issue

Expected behavior The styles remains mostly unchanged when hovering over the link. Only the link hover style should be applied. The global styles should not suddenly get “lost”.

Screenshots See above.

Additional context The issue does not occur in dev mode (gatsby develop).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ftescommented, Nov 15, 2022

I’ve since switched tech stacks, so I can’t say if the issue still exists. I suggest closing the bug since nobody else complained and you couldn’t reproduce it.

1reaction
ftescommented, Mar 11, 2021

Update: I narrowed down which prefetched pages cause the bug. Affected: Hovering over a link to any page that executes the @emotion/react keyframes method.

Example:

// src/pages/start-page.js
import * as React from "react"
import {Link} from "gatsby"
const StartPage = () => <Link to="/page-with-keyframes">Go to page with @emotion/react keyframes call</Link>
export default StartPage

// src/pages/page-with-keyframes.js
import * as React from "react"
import {keyframes} from "@emotion/react"

const unused = keyframes``
const PageWithKeyframes = () => <div>Empty</div>
export default PageWithKeyframes

Note that keyframes is called, but the result is not actually consumed anywhere.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fixing Gatsby's rehydration issue - LogRocket Blog
This post shows you how to overcome a rehydration issue when using server side rendering in Gatsby to makes ure your application runs...
Read more >
Understanding React Hydration | Gatsby
Hydration is the process of using client-side JavaScript to add application state and interactivity to server-rendered HTML. It's a feature of React, ...
Read more >
The Perils of Rehydration - Josh W Comeau
A rendering issue causes a newsletter signup form to be squashed and overlapping ... Technically, what Gatsby does is server-side rendering, ...
Read more >
Gatsby, React & Hydration · Discussion #17914 - GitHub
The problem has vague and indirect side-effects, and it not necessarily easy ... Directly rendering from the client, instead of hydrating, is deprecated...
Read more >
How to avoid hydration errors in Gatsby with React.lazy
418: Hydration failed because the initial UI does not match what was rendered on the server. 422: There was an error while hydrating...
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