Skip to content
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

chore: clean up chakra example #35

Merged
merged 2 commits into from
Oct 19, 2022
Merged

chore: clean up chakra example #35

merged 2 commits into from
Oct 19, 2022

Conversation

jacob-ebey
Copy link
Member

No description provided.

@dusty
Copy link

dusty commented Oct 21, 2022

@jacob-ebey I tried this example out and we were getting hydration errors. The app would load fine on a server render, then lose all the styles when it switched to the client. Just switching to hydrate seemed to fix it, but this is quite different than the chakra docs where they inject styles manually. Do you see anything wrong with below?

import createEmotionCache from '@emotion/cache'
import { CacheProvider } from '@emotion/react'
import { RemixBrowser } from '@remix-run/react'
import { startTransition, StrictMode } from 'react'
// import { hydrateRoot } from 'react-dom/client'
import { hydrate as hydrateOld } from 'react-dom'

function hydrate() {
  const emotionCache = createEmotionCache({ key: 'css' })

  // startTransition(() => {
  //   hydrateRoot(
  //     document,
  //     <StrictMode>
  //       <CacheProvider value={emotionCache}>
  //         <RemixBrowser />
  //       </CacheProvider>
  //     </StrictMode>
  //   )
  // })

  startTransition(() => {
    hydrateOld(
      <StrictMode>
        <CacheProvider value={emotionCache}>
          <RemixBrowser />
        </CacheProvider>
      </StrictMode>,
      document
    )
  })
}

if (window.requestIdleCallback) {
  window.requestIdleCallback(hydrate)
} else {
  // Safari doesn't support requestIdleCallback
  // https://caniuse.com/requestidlecallback
  window.setTimeout(hydrate, 1)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants