Skip to content

Commit f8e53c6

Browse files
authored
Fix web onboarding dismissal infinite loop bug (#5742)
1 parent f31c2c6 commit f8e53c6

File tree

1 file changed

+5
-24
lines changed

1 file changed

+5
-24
lines changed

src/routes/Onboarding/index.tsx

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import { reportRejection } from 'lib/trap'
2525
import { useNetworkContext } from 'hooks/useNetworkContext'
2626
import { NetworkHealthState } from 'hooks/useNetworkStatus'
2727
import { EngineConnectionStateType } from 'lang/std/engineConnection'
28-
import { settingsActor, useSettings } from 'machines/appMachine'
29-
import { useSelector } from '@xstate/react'
28+
import { settingsActor } from 'machines/appMachine'
3029
import { CustomIcon } from 'components/CustomIcon'
3130
import Tooltip from 'components/Tooltip'
31+
import { waitFor } from 'xstate'
3232

3333
export const kbdClasses =
3434
'py-0.5 px-1 text-sm rounded bg-chalkboard-10 dark:bg-chalkboard-100 border border-chalkboard-50 border-b-2'
@@ -125,38 +125,19 @@ export function useNextClick(newStatus: string) {
125125

126126
export function useDismiss() {
127127
const filePath = useAbsoluteFilePath()
128-
const settings = useSettings()
129128
const send = settingsActor.send
130-
const isSettingsActorIdle = useSelector(settingsActor, (s) =>
131-
s.matches('idle')
132-
)
133129
const navigate = useNavigate()
134130

135131
const settingsCallback = useCallback(() => {
136132
send({
137133
type: 'set.app.onboardingStatus',
138134
data: { level: 'user', value: 'dismissed' },
139135
})
136+
waitFor(settingsActor, (state) => state.matches('idle'))
137+
.then(() => navigate(filePath))
138+
.catch(reportRejection)
140139
}, [send])
141140

142-
/**
143-
* A "listener" for the XState to return to "idle" state
144-
* when the user dismisses the onboarding, using the callback above
145-
*/
146-
useEffect(() => {
147-
if (
148-
settings.app.onboardingStatus.current === 'dismissed' &&
149-
isSettingsActorIdle
150-
) {
151-
navigate(filePath)
152-
}
153-
}, [
154-
filePath,
155-
navigate,
156-
isSettingsActorIdle,
157-
settings.app.onboardingStatus.current,
158-
])
159-
160141
return settingsCallback
161142
}
162143

0 commit comments

Comments
 (0)