-
Notifications
You must be signed in to change notification settings - Fork 435
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
fix(structure): make sync document toast dismisable #7209
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
No changes to documentation |
Component Testing Report Updated Aug 21, 2024 7:20 AM (UTC) ✅ All Tests Passed -- expand for details
|
const conditionalToastParams = useMemo( | ||
() => ({ | ||
id: `sync-lock-${documentId}`, | ||
status: 'warning' as const, | ||
enabled: isLocked, | ||
title: t('document-view.form-view.sync-lock-toast.title'), | ||
description: t('document-view.form-view.sync-lock-toast.description'), | ||
closable: true, | ||
}), | ||
[documentId, isLocked, t], | ||
) | ||
|
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.
Memoizing this params to avoid unnecessary calls to the useEffect in the useConditionalToast
hook, which uses the params as a dependency.
return () => { | ||
// Close the toast when the component unmounts, even if the condition is still true | ||
if (wasEnabled && params.enabled) { | ||
toast.push({ | ||
...params, | ||
// Note: @sanity/ui fallbacks to the default duration of 4s in case of falsey values | ||
duration: 0.01, | ||
}) | ||
} | ||
} |
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.
This will close the toast when the component unmounts, preventing it to be forever present
cd83cf1
to
759b387
Compare
@@ -18,19 +10,20 @@ const LONG_ENOUGH_BUT_NOT_TOO_LONG = 1000 * 60 * 60 * 24 * 24 | |||
export function useConditionalToast(params: ToastParams & {id: string; enabled?: boolean}) { | |||
const toast = useToast() | |||
|
|||
const wasEnabled = usePrevious(params.enabled) |
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.
This is not necessary now that the cleanup function was added to the useEffect.
If the params.enabled condition was true, then the cleanup will take care of closing the toast when params.enabled changes or when the component is unmounted
dac1623
to
ff02fc6
Compare
* fix(structure): make sync document toast dismissable * fix(structure): close conditional toast when component unmounts * chore(structure): remove the usePrevious hook in useConditionalToast * fix(structure): update sync lock toast id to make it unique across documents
Description
An issue is present in structure in which sync toasts are forever present.
For what was discussed with the internal team, is that the toast is persisted even though the condition for it is gone or and even if the document is not in view anymore.
This seems to be caused because when the
FormView
component is unmounted, the toast doesn't trigger a close action, to solve this a cleanup function was added to the useEffect to close the toast if it is still shown.This seems to be happening even if the
FormView
is not visually unmounted (document is still open), this seems to be caused because theFormView
component takes a keykey={documentId + (ready ? '_ready' : '_pending')}
, so when the key changes, the form is unmounted and mounted again, but given there are no clean up functions in the conditional toast hook, the toast will be kept forever.In this video two buttons were added to force the states that show or hide the toast.
Screen.Recording.2024-07-20.at.10.58.38.mov
It also adds support to close the syncing document toast.
What to review
Testing
Notes for release