-
Notifications
You must be signed in to change notification settings - Fork 499
fix: allow createGlobalStyle to work with auto updating studios
#11313
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
3 Skipped Deployments
|
🧪 E2E Preview environment🔑 Environment Variables for Local TestingThis is the preview URL for the E2E tests: https://e2e-studio-5z2uq29iq.sanity.dev To run the E2E tests locally, you can use the following environment variables, then run 💬 Remember to build the project first with |
📊 Playwright Test ReportThis report contains test results, including videos of failing tests. |
⚡️ Editor Performance ReportUpdated Thu, 27 Nov 2025 16:09:45 GMT
Detailed information🏠 Reference resultThe performance result of
🧪 Experiment resultThe performance result of this branch
📚 Glossary
|
⚡️ Editor Performance ReportDeploying studio and running performance tests… |
Coverage Report
File CoverageNo changed files found. |
Preview this PR with pkg.pr.newCreate a new projectnpx https://pkg.pr.new/create-sanity@23db03fNote: This installs the latest Sanity Studio from the npm registry. To apply the changes from this PR in your newly created project, run the install commands below for each package listed in your package.json ...Or run the Sanity CLI...Or upgrade project dependencies
|
pedrobonamin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing find 🧙🏻 !
Description
On auto updating studios
createGlobalStyleis broken and no global styles are rendered!When we publish auto updating studios we vendor
react,react-domandstyled-components.Unfortunately we vendored
styled-componentstostyled-components/dist/styled-components.esm.jswhile we should've aliased tostyled-components/dist/styled-components.browser.esm.js.styled-components.esm.jsis fornodeenvironments, and using it instead ofstyled-components.browser.esm.jsbreakscreateGlobalStyle.When
styled-componentsbuilds fornpmit sets the__SERVER__constant totrueforstyled-components.esm.jsandfalseforstyled-components.browser.esm.js.This constant branches important logic in
createGlobalStyle: https://github.com/styled-components/styled-components/blob/a21089e1cde9d2492349088787c59dd85358a337/packages/styled-components/src/constructors/createGlobalStyle.ts#L51-L62Because
__SERVER__is false theuseLayoutEffectthat callsrenderStylesisn't there: https://github.com/styled-components/styled-components/blob/a21089e1cde9d2492349088787c59dd85358a337/packages/styled-components/src/constructors/createGlobalStyle.ts#L58C11-L58C76And since
ssc.styleSheet.serveris always false it also doesn't insert styles during render: https://github.com/styled-components/styled-components/blob/a21089e1cde9d2492349088787c59dd85358a337/packages/styled-components/src/constructors/createGlobalStyle.ts#L51-L53Why is
ssc.styleSheet.serverfalse?The value of
ssc.styleSheet.serveris set during the construction of the defaultStyleSheet, theoptions.isServer.The
isServeroption is by default set to!IS_BROWSER.IS_BROWSERis basically defined astypeof window !== 'undefined'We have two cases of
createGlobalStylein our own code:sanity/packages/sanity/src/core/studio/GlobalStyle.tsx
Lines 16 to 73 in 8d6c11d
sanity/packages/sanity/src/presentation/preview/IFrame.tsx
Lines 88 to 101 in 8d6c11d
I've sometimes noticed that auto updating studios have cases of text that lack our
Interfont-family, and never understood why, but today I learned it's because we set the defaultbodyfont-familyin acreateGlobalStyle.I've made a repro showing the issue, during
sanity devit renders the font (it's missing later because I'm intentionally rendering the@sanity/uibutton as<Button>Zoom In</Button>when it's supposed to be<Button text="Zoom In" />):sc.before.mov
Once deployed with
autoUpdates: trueall global styling is missing and clicking the Zoom In/Out button does nothing:after.sc.mov
What to review
Missed anything?
Testing
You can try the pkg.pr.new build on a studio that has auto-updating studio, and once deployed you can verify styles are there by inspecting
bodyand seeing it hasscrollbar-gutter: stable;:Notes for release
Fixes an issue where
createGlobalStylefromstyled-componentsdoesn't work if the Studio is deployed withautoUpdates: true. Styles declared with it were simply not there once deployed, while they work just fine ifautoUpdates: falseor when working locally withsanity dev.Usually this issue would manifest itself in some UI text using Times New Roman instead of Inter, and missing browser scrollbar styling.
If you're affected by this issue you'll need to run a new
sanity deployafter updating tosanity@latest, you might as well use ourstyled-componentsfork while at it and give your studio a nice performance boost.If you're already using
@sanity/styled-componentsinstead ofstyled-componentsthen you're not affected by this issue.