Skip to content

Commit 9ab4086

Browse files
RitaDiasbjoerge
andauthored
refactor(structure): add timeout to reconnecting message (#7531)
* refactor(structure): add timeout for reconnecting pane provider * docs(structure): add comment * refactor(structure): add timeout clean up * chore(structure): update type Co-authored-by: Bjørge Næss <[email protected]> --------- Co-authored-by: Bjørge Næss <[email protected]>
1 parent 3593bf5 commit 9ab4086

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

packages/sanity/src/structure/panes/document/DocumentPaneProvider.tsx

+11-5
Original file line numberDiff line numberDiff line change
@@ -748,12 +748,18 @@ export const DocumentPaneProvider = memo((props: DocumentPaneProviderProps) => {
748748
)
749749

750750
useEffect(() => {
751+
let timeout: ReturnType<typeof setTimeout>
751752
if (connectionState === 'reconnecting') {
752-
pushToast({
753-
id: 'sanity/structure/reconnecting',
754-
status: 'warning',
755-
title: t('panes.document-pane-provider.reconnecting.title'),
756-
})
753+
timeout = setTimeout(() => {
754+
pushToast({
755+
id: 'sanity/structure/reconnecting',
756+
status: 'warning',
757+
title: t('panes.document-pane-provider.reconnecting.title'),
758+
})
759+
}, 2000) // 2 seconds, we can iterate on the value
760+
}
761+
return () => {
762+
if (timeout) clearTimeout(timeout)
757763
}
758764
}, [connectionState, pushToast, t])
759765

0 commit comments

Comments
 (0)