Skip to content

Commit 1c6b155

Browse files
committed
fix(home): add pointercancel handler; fix(settings): sync name on profile refetch
1 parent 4f41c01 commit 1c6b155

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

apps/sim/app/workspace/[workspaceId]/home/hooks/use-mothership-resize.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,40 @@ export function useMothershipResize() {
3333
document.body.style.cursor = 'ew-resize'
3434
document.body.style.userSelect = 'none'
3535

36-
const handlePointerMove = (moveEvent: PointerEvent) => {
37-
const newWidth = window.innerWidth - moveEvent.clientX
38-
const maxWidth = window.innerWidth * MOTHERSHIP_WIDTH.MAX_PERCENTAGE
39-
el.style.width = `${Math.min(Math.max(newWidth, MOTHERSHIP_WIDTH.MIN), maxWidth)}px`
40-
}
36+
// AbortController removes all listeners at once on cleanup/cancel/unmount
37+
const ac = new AbortController()
38+
const { signal } = ac
4139

4240
const cleanup = () => {
41+
ac.abort()
4342
el.style.transition = prevTransition
4443
document.body.style.cursor = ''
4544
document.body.style.userSelect = ''
46-
handle.removeEventListener('pointermove', handlePointerMove)
47-
handle.removeEventListener('pointerup', handlePointerUp)
4845
cleanupRef.current = null
4946
}
5047

51-
const handlePointerUp = (upEvent: PointerEvent) => {
52-
handle.releasePointerCapture(upEvent.pointerId)
53-
cleanup()
54-
}
48+
handle.addEventListener(
49+
'pointermove',
50+
(moveEvent: PointerEvent) => {
51+
const newWidth = window.innerWidth - moveEvent.clientX
52+
const maxWidth = window.innerWidth * MOTHERSHIP_WIDTH.MAX_PERCENTAGE
53+
el.style.width = `${Math.min(Math.max(newWidth, MOTHERSHIP_WIDTH.MIN), maxWidth)}px`
54+
},
55+
{ signal }
56+
)
57+
58+
handle.addEventListener(
59+
'pointerup',
60+
(upEvent: PointerEvent) => {
61+
handle.releasePointerCapture(upEvent.pointerId)
62+
cleanup()
63+
},
64+
{ signal }
65+
)
5566

56-
cleanupRef.current = cleanup
57-
handle.addEventListener('pointermove', handlePointerMove)
58-
handle.addEventListener('pointerup', handlePointerUp)
67+
// Browser fires pointercancel when it reclaims the gesture (scroll, palm rejection, etc.)
68+
// Without this, body cursor/userSelect and transition would be permanently stuck
69+
handle.addEventListener('pointercancel', cleanup, { signal })
5970
}, [])
6071

6172
// Tear down any active drag if the component unmounts mid-drag

apps/sim/app/workspace/[workspaceId]/settings/components/general/general.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ export function General() {
6868
const [name, setName] = useState(profile?.name || '')
6969
const [isEditingName, setIsEditingName] = useState(false)
7070
const inputRef = useRef<HTMLInputElement>(null)
71-
const hasInitializedNameRef = useRef(false)
71+
const [prevProfileName, setPrevProfileName] = useState(profile?.name)
7272

73-
if (!hasInitializedNameRef.current && profile?.name) {
74-
hasInitializedNameRef.current = true
73+
if (profile?.name && profile.name !== prevProfileName) {
74+
setPrevProfileName(profile.name)
7575
setName(profile.name)
7676
}
7777

0 commit comments

Comments
 (0)