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

fix: remove ssr warning "Detected multiple renderers" #1262

Merged
merged 1 commit into from
Apr 12, 2024

Conversation

stipsan
Copy link
Member

@stipsan stipsan commented Apr 12, 2024

In App Router there's frequently very long (truncated below) warnings:

Warning: Detected multiple renderers concurrently rendering the same context provider. This is currently unsupported.
    at ThemeProvider (webpack-internal:///(ssr)/./node_modules/@sanity/ui/dist/index.mjs:662:72)
    at ThemeProvider (webpack-internal:///(ssr)/./app/[lang]/ThemeProvider.tsx:14:26)
    at Lazy
    at Le (webpack-internal:///(ssr)/./node_modules/styled-components/dist/styled-components.esm.js:32:16022)
    at StyledComponentsRegistry (webpack-internal:///(ssr)/./app/[lang]/registry.tsx:17:37)
    at Lazy
    at body
    at html

It was first reported at next-sanity.

Expo had to solve for the same warning, as it relates to how React deals with contexts during SRR.

This PR solves it by wrapping the usage of globalScope[key] = globalScope[key] || React.createContext in a helper that detects if we're in SSR where it falls back to always calling React.createContext and thus the warning stops showing up.

Copy link

vercel bot commented Apr 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
sanity-ui-storybook ✅ Ready (Inspect) Visit Preview Apr 12, 2024 8:58am
sanity-ui-workshop ✅ Ready (Inspect) Visit Preview Apr 12, 2024 8:58am

Copy link

Removed dependencies detected. Learn more about Socket for GitHub ↗︎

🚮 Removed packages: npm/@sanity/pkg-utils@6.4.1

View full report↗︎

@stipsan stipsan merged commit c48155b into main Apr 12, 2024
13 checks passed
@stipsan stipsan deleted the improve-app-router-ssr-compat branch April 12, 2024 09:04
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.

None yet

1 participant