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.

EnvironmentProvider breaks SSR for Next.js

See original GitHub issue

🐛 Bug report

After upgrading from @chakra-ui/react@1.5.0 to @chakra-ui/react@1.5.1, the server side render in Next.js results in a single <span></span>.

Likely point of introduction: https://github.com/chakra-ui/chakra-ui/commit/81a40231f12461dcca0fa0cd3c4e9e2c0497a04d

💥 Steps to reproduce

  1. Go to https://lyhzc.sse.codesandbox.io/
  2. Open dev tools and disable JS
  3. Refresh the page
  4. Observe that the DOM contains <div id="__next"><span></span></div>

Alternatively

  1. http https://lyhzc.sse.codesandbox.io/ | tidy -xml
  2. Observe the same error

💻 Link to reproduction

CodeSandbox reproduction: https://codesandbox.io/s/infallible-bardeen-lyhzc?file=/pages/_app.js

🧐 Expected behavior

Server render should return the expected html content.

🧭 Possible Solution

Only just starting to dig into this, but it looks like the default environment needs to be more sophisticated can relying on canUseDOM().

Interestingly, providing any old string as the environment seems to prevent the issue from occurring i.e.

<ChakraProvider environment="...">
  <MyApp />
</ChakraProvider>

🌍 System information

Software Version(s)
Chakra UI 1.5.1
Browser Chrome 89.0.4389.128
Operating System macOS 10.15.6

📝 Additional information

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
JClackettcommented, Aug 3, 2021

Also just getting this now:

Warning: Did not expect server HTML to contain a <div> in <div>. span EnvironmentProvider@webpack-internal:///../../node_modules/@chakra-ui/react-env/dist/esm/env.js:36:7 ColorModeProvider@webpack-internal:///../..

Will try and get a repro too

1reaction
segunadebayocommented, Apr 17, 2021

This has been fixed and we’re releasing an update shortly

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-hydration-error - Next.js
When css-in-js libraries are not set up for pre-rendering (SSR/SSG) it will often lead to a hydration mismatch. In general this means the...
Read more >
What's New in Next.js 13 - AppSignal Blog
You can dig deeper and use React's Suspense to further break down the UI. You can make sure the layout renders while a...
Read more >
Server-side rendering broken after upgrading to MUI 5 (with ...
I launched the official SSR Next.js implementation. It showed it doesn't work either. Server-side rendering with JavaScript disabled. For more ...
Read more >
What's new in Next.js 13, and what do they really do?
A practical guide to Next.js 13. How real-world code and architecture need to adapt to Server Components, Streaming SSR, Layouts, and Turbopack.
Read more >
NextJS / React SSR: 21 Universal Data Fetching Patterns ...
In NextJS, you can simply define an endpoint in the "/api" directory, which can then be called by using "swr" or just "fetch"....
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