Skip to content

Commit fd2147f

Browse files
committed
fix(themer): paint the layout and body with the built theme background
The layout read the raw `background` option, which is unset for the presets and themes that only pick an accent, and nothing painted the body anymore — so the chrome, the overscroll area and the gaps in the layout kept the colors of whatever theme was showing before.
1 parent 3b2c35b commit fd2147f

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

‎plugins/@sanity/themer/src/tool/ThemerLayout.tsx‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,23 @@ export function ThemerLayout({
7676
}: ThemerLayoutProps & {backgroundColor: string | undefined; scheme: ThemeColorSchemeKey}) {
7777
const actorRef = useActorRef(themerMachine, {snapshot: persistedSnapshot})
7878
const oppositeScheme: ThemeColorSchemeKey = scheme === 'dark' ? 'light' : 'dark'
79+
80+
// The Studio paints the body with its configured theme from above this
81+
// layout, and Safari tints its chrome from the body — so the applied theme
82+
// has to reach the body too, in the scheme the Studio is showing
83+
useEffect(() => {
84+
if (backgroundColor === undefined) return undefined
85+
86+
const {style} = document.body
87+
const previous = style.backgroundColor
88+
89+
style.backgroundColor = backgroundColor
90+
91+
return () => {
92+
style.backgroundColor = previous
93+
}
94+
}, [backgroundColor])
95+
7996
return (
8097
<>
8198
<Flex

‎plugins/@sanity/themer/src/tool/ThemerProvider.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ export function ThemerProvider({
4343
// Split screen needs some space
4444
const split = state.split && !isTooSmallForSplitScreen
4545

46+
const theme = state.theme !== null ? buildTheme(state.theme) : undefined
47+
4648
return (
47-
<ThemeProvider theme={(state.theme !== null ? buildTheme(state.theme) : null) ?? undefined}>
49+
<ThemeProvider theme={theme}>
4850
<ThemerLayout
4951
config={config}
50-
backgroundColor={state.theme?.[scheme]?.background}
52+
backgroundColor={theme?.v2?.color[scheme].default.bg}
5153
dispatch={dispatch}
5254
navbarHeight={state.navbarHeight}
5355
open={open}

0 commit comments

Comments
 (0)