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

[Bug]: [Tanstack Start] Uncaught 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. #326

Open
paulm17 opened this issue Nov 18, 2024 · 2 comments
Labels
bug Something isn't working triage

Comments

@paulm17
Copy link

paulm17 commented Nov 18, 2024

What happened?

Hello. I'm using tanstack start and I'm encountering the issue:

Uncaught 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.
    at updateDehydratedSuspenseComponent (react-dom.development.js:20741:48)
    at updateSuspenseComponent (react-dom.development.js:20401:16)
    at beginWork (react-dom.development.js:21663:14)
    at beginWork$1 (react-dom.development.js:27465:14)
    at performUnitOfWork (react-dom.development.js:26596:12)
    at workLoopSync (react-dom.development.js:26505:5)
    at renderRootSync (react-dom.development.js:26473:7)
    at performConcurrentWorkOnRoot (react-dom.development.js:25777:74)
    at workLoop (scheduler.development.js:266:34)
    at flushWork (scheduler.development.js:239:14)

I have resolved by making the following amendments:

const handleMediaQuery = React.useCallback(
    (e: MediaQueryListEvent | MediaQueryList) => {
      const resolved = getSystemTheme(e)
      // setResolvedTheme(resolved)

      // if (theme === 'system' && enableSystem && !forcedTheme) {
      //   applyTheme('system')
      // }
      React.startTransition(() => {
        setResolvedTheme(resolved)
        
        if (theme === 'system' && enableSystem && !forcedTheme) {
          applyTheme('system')
        }
      })
    },
    [theme, forcedTheme]
  )
// Always listen to System preference
  React.useEffect(() => {
    const media = window.matchMedia(MEDIA)

    // // Intentionally use deprecated listener methods to support iOS & old browsers
    // media.addListener(handleMediaQuery)
    // handleMediaQuery(media)

    // Intentionally use deprecated listener methods to support iOS & old browsers
    media.addListener(handleMediaQuery)
    
    // Wrap initial call in startTransition as well
    React.startTransition(() => {
      handleMediaQuery(media)
    })

    return () => media.removeListener(handleMediaQuery)
  }, [handleMediaQuery])

Happy to submit a PR. Please let me know.

Version

0.4.3

What browsers are you seeing the problem on?

Chrome

@paulm17 paulm17 added bug Something isn't working triage labels Nov 18, 2024
@edproton
Copy link

Up

@SoloReverse
Copy link

until this is resolved I published @paulm17's changes
npm install @solorev/react-themes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

No branches or pull requests

3 participants