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.

ChakraProvider breaks Suspense in Next.js projects, even without suspended components

See original GitHub issue

Description

When you add ChakraProvider to _app.tsx, any usage of Suspense breaks the app.

Link to Reproduction

https://codesandbox.io/s/nice-wood-50d2lj?file=/pages/index.tsx

Steps to reproduce

  1. Create a vanilla Next.js app
  2. Add a Suspense component with <p>Hello world</p> as children into pages/index.tsx
  3. Verify it works fine (should)
  4. Add @chakra-ui/react and <ChakraProvider> into _app.tsx
  5. Reload the page - emits the following error:

Error: This Suspense boundary received an update before it finished hydrating. This caused the boundary to switch to client rendering. The usual way to fix this is to wrap the original update in startTransition.

Chakra UI Version

1.8.8 and @next

Browser

No response

Operating System

  • macOS
  • Windows
  • Linux

Additional Information

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:14
  • Comments:15 (1 by maintainers)

github_iconTop GitHub Comments

10reactions
dasdasdasd1232134commented, May 16, 2022
(
    <EnvironmentProvider>
        <Suspense fallback={<Spinner />}>
            <ComponentThatSuspend />
        </Suspense>
    </EnvironmentProvider>
)

setNode(el) in EnvironmentProvider will cause it re-render, and the context value has changed from defaultEnv to { document, window } React recived an update during streaming rendering react doesn’t know if this update will affect the <ComponentThatSuspend /> component

So react will have to replace the server HTML with the suspense fallback. This is because it is stale

More detail: https://github.com/reactwg/react-18/discussions/38

I think we need refactor EnvironmentProvider to avoid the top-level updates during the app startup. @segunadebayo

5reactions
draqistcommented, Jun 29, 2022

This issue still persists and is still occurring, I tried wrapping my api call with a startTransition but it’s still isn’t working

Read more comments on GitHub >

github_iconTop Results From Across the Web

Blog - Next.js 13
Next.js 13 introduces layouts, React Server Components, and streaming in the app directory, as well as Turbopack, an improved image ...
Read more >
How to Use Chakra UI with Next.js and React - freeCodeCamp
To get a good idea of how Chakra works, we're going to essentially rebuild the default Next.js template with Chakra UI components.
Read more >
Fetching and caching Supabase data in Next.js 13 Server ...
Next.js 13 introduces new data fetching and caching methods to enable React Server Components and Suspense.
Read more >
Getting Started with Next.js - Chakra UI
A guide for installing Chakra UI with Nextjs projects. ... pages/_app.tsx (create it if it doesn't exist) and wrap the Component with the...
Read more >
Building a Mini Next.js - Jonas Galvez
But the massive complexity and dependency tree is still there. You can integrate any Vite-bundled application with Fastify, with any framework ...
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