Skip to content

Commit 46af6e5

Browse files
committed
fix(themer): drop the debug toast, keep persistence out of the sidebar's Activity
The navbar toggle's prerender handler, which runs on hover and focus, pushed a leftover 'Hello' toast, so moving the pointer over the button showed it. PersistActorSnapshot was rendered inside ResizableSidebar, which the layout renders under <Activity>. Hiding the sidebar runs the effect cleanup, which cancelled the scheduled write, so theme edits made just before closing could never reach localStorage. It belongs to the actor's lifetime, not the sidebar's visibility, so it now sits next to the other actor-level effects in ThemerLayout.
1 parent b57c014 commit 46af6e5

3 files changed

Lines changed: 45 additions & 49 deletions

File tree

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

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {startTransition, useCallback, useEffect, useRef, useState} from 'react'
33

44
import type {ThemerProps} from '#types'
55

6-
import {PersistActorSnapshot} from './PersistActorSnapshot'
76
import {MAXIMUM_WIDTH, MINIMUM_WIDTH} from './sidebarWidth'
87
import {ThemerSidebar} from './ThemerSidebar'
98

@@ -105,49 +104,46 @@ export default function ResizableSidebar({
105104
const [boundaryElement, setBoundaryElement] = useState<HTMLDivElement | null>(null)
106105

107106
return (
108-
<>
109-
<Layer className={sidebar} style={{width}} zOffset={100}>
110-
<Card
111-
borderLeft
112-
className={frame}
113-
height="fill"
114-
ref={(boundaryElement) => {
115-
startTransition(() => setBoundaryElement(boundaryElement))
116-
// Intentionally not unsetting the element as it would create unnecessary work when <Activity> unhides
117-
return () => {}
118-
}}
119-
>
120-
<div
121-
aria-label="Resize the themer"
122-
className={resizeHandle}
123-
aria-orientation="vertical"
124-
aria-valuemax={MAXIMUM_WIDTH}
125-
aria-valuemin={MINIMUM_WIDTH}
126-
aria-valuenow={width}
127-
data-dragging={dragging}
128-
onDoubleClick={() => setWidth(MINIMUM_WIDTH)}
129-
onKeyDown={handleKeyDown}
130-
onPointerCancel={handlePointerUp}
131-
onPointerDown={handlePointerDown}
132-
onPointerMove={handlePointerMove}
133-
onPointerUp={handlePointerUp}
134-
// oxlint-disable-next-line prefer-tag-over-role -- a window splitter is a focusable, draggable separator, which an hr is not
135-
role="separator"
136-
tabIndex={0}
137-
/>
138-
<Box className={content} height="fill" overflow="hidden">
139-
<BoundaryElementProvider element={boundaryElement}>
140-
<ThemerSidebar
141-
split={split}
142-
navbarHeight={navbarHeight}
143-
actorRef={actorRef}
144-
dispatch={dispatch}
145-
/>
146-
</BoundaryElementProvider>
147-
</Box>
148-
</Card>
149-
</Layer>
150-
<PersistActorSnapshot actorRef={actorRef} />
151-
</>
107+
<Layer className={sidebar} style={{width}} zOffset={100}>
108+
<Card
109+
borderLeft
110+
className={frame}
111+
height="fill"
112+
ref={(boundaryElement) => {
113+
startTransition(() => setBoundaryElement(boundaryElement))
114+
// Intentionally not unsetting the element as it would create unnecessary work when <Activity> unhides
115+
return () => {}
116+
}}
117+
>
118+
<div
119+
aria-label="Resize the themer"
120+
className={resizeHandle}
121+
aria-orientation="vertical"
122+
aria-valuemax={MAXIMUM_WIDTH}
123+
aria-valuemin={MINIMUM_WIDTH}
124+
aria-valuenow={width}
125+
data-dragging={dragging}
126+
onDoubleClick={() => setWidth(MINIMUM_WIDTH)}
127+
onKeyDown={handleKeyDown}
128+
onPointerCancel={handlePointerUp}
129+
onPointerDown={handlePointerDown}
130+
onPointerMove={handlePointerMove}
131+
onPointerUp={handlePointerUp}
132+
// oxlint-disable-next-line prefer-tag-over-role -- a window splitter is a focusable, draggable separator, which an hr is not
133+
role="separator"
134+
tabIndex={0}
135+
/>
136+
<Box className={content} height="fill" overflow="hidden">
137+
<BoundaryElementProvider element={boundaryElement}>
138+
<ThemerSidebar
139+
split={split}
140+
navbarHeight={navbarHeight}
141+
actorRef={actorRef}
142+
dispatch={dispatch}
143+
/>
144+
</BoundaryElementProvider>
145+
</Box>
146+
</Card>
147+
</Layer>
152148
)
153149
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {ThemerProps} from '#types'
88

99
import {addThemerTransitionType} from './addThemerTransitionType'
1010
import {themerMachine} from './machine'
11+
import {PersistActorSnapshot} from './PersistActorSnapshot'
1112
import type {ToolReducerAction, ToolReducerState} from './reducer'
1213
import {resolveActiveThemeOptions} from './selectors'
1314
import type {readPersistedSnapshot} from './storage'
@@ -138,6 +139,9 @@ export function ThemerLayout({
138139
</Activity>
139140
</Flex>
140141

142+
{/* Outside the sidebar's `Activity`, which would run the cleanup that
143+
drops a scheduled write every time the sidebar is hidden */}
144+
<PersistActorSnapshot actorRef={actorRef} />
141145
<ThemerThemeCrossfader actorRef={actorRef} dispatch={dispatch} />
142146
<RevokeImageUrls actorRef={actorRef} />
143147
</>

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {ColorWheelIcon} from '@sanity/icons/ColorWheel'
22
import {Box, Button, Text} from '@sanity/ui'
3-
import {useToast} from '@sanity/ui/toast'
43
import {Tooltip} from '@sanity/ui/tooltip'
54
import {lazy, startTransition, Suspense, use, useRef, useTransition, ViewTransition} from 'react'
65
import {type NavbarProps} from 'sanity'
@@ -57,7 +56,6 @@ function ThemerNavbarButton() {
5756
dispatch({type: 'prerender'})
5857
// Do a little fun spin
5958
if (!open) iconRef.current?.spin()
60-
toast.push({title: 'Hello'})
6159
})
6260

6361
// The sidebar's header takes the height of the Studio navbar, so the two
@@ -85,8 +83,6 @@ function ThemerNavbarButton() {
8583

8684
const {title} = config
8785

88-
const toast = useToast()
89-
9086
// The `Box` is here because a `ViewTransition` cannot be the direct child
9187
// of the `Tooltip`: it needs a child that renders a DOM node
9288
return (

0 commit comments

Comments
 (0)