From 115f663a5273f0cbd7749bab268b762397a04b98 Mon Sep 17 00:00:00 2001 From: Dhiraj Arun Date: Sun, 11 Sep 2022 19:38:46 +0530 Subject: [PATCH 1/2] fix(devtools): not subscribing to queryCache if devtool is closed This will stop unnecessary rerender of devtools when they are closed. --- .../react-query-devtools/src/devtools.tsx | 330 +++++++++--------- 1 file changed, 170 insertions(+), 160 deletions(-) diff --git a/packages/react-query-devtools/src/devtools.tsx b/packages/react-query-devtools/src/devtools.tsx index e0ee47ff74..fe27dc9a7a 100644 --- a/packages/react-query-devtools/src/devtools.tsx +++ b/packages/react-query-devtools/src/devtools.tsx @@ -377,12 +377,18 @@ export function ReactQueryDevtools({ const useSubscribeToQueryCache = ( queryCache: QueryCache, getSnapshot: () => T, + skip: boolean = false, ): T => { return useSyncExternalStore( React.useCallback( - (onStoreChange) => - queryCache.subscribe(notifyManager.batchCalls(onStoreChange)), - [queryCache], + (onStoreChange) => { + if (!skip) + return queryCache.subscribe(notifyManager.batchCalls(onStoreChange)) + return () => { + return + } + }, + [queryCache, skip], ), getSnapshot, getSnapshot, @@ -422,6 +428,7 @@ export const ReactQueryDevtoolsPanel = React.forwardRef< const queriesCount = useSubscribeToQueryCache( queryCache, () => queryCache.getAll().length, + !isOpen, ) const [activeQueryHash, setActiveQueryHash] = useLocalStorage( @@ -501,188 +508,191 @@ export const ReactQueryDevtoolsPanel = React.forwardRef< }} onMouseDown={handleDragStart} > -
+ + {isOpen && (
-
- +
- setFilter(e.target.value)} - onKeyDown={(e) => { - if (e.key === 'Escape') setFilter('') - }} + +
- {!filter ? ( - <> - - - + - - ) : null} + title={ + isMockOffline + ? 'Restore offline mock' + : 'Mock offline behavior' + } + style={{ + padding: '0', + height: '2em', + }} + > + + {isMockOffline ? ( + <> + + + + + + + + ) : ( + <> + + + + + + + )} + + + + + ) : null} +
+
+ {queries.map((query) => { + return ( + + ) + })} +
-
- {queries.map((query) => { - return ( - - ) - })} -
-
+ )} - {activeQueryHash ? ( + {activeQueryHash && isOpen ? ( Date: Sun, 11 Sep 2022 20:35:32 +0530 Subject: [PATCH 2/2] style(devtools): fix linting issue in devtools.tsx file --- packages/react-query-devtools/src/devtools.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/react-query-devtools/src/devtools.tsx b/packages/react-query-devtools/src/devtools.tsx index fe27dc9a7a..31a467eca5 100644 --- a/packages/react-query-devtools/src/devtools.tsx +++ b/packages/react-query-devtools/src/devtools.tsx @@ -517,7 +517,7 @@ export const ReactQueryDevtoolsPanel = React.forwardRef< maxHeight: '100%', overflow: 'auto', borderRight: `1px solid ${theme.grayAlt}`, - display: isOpen ? 'flex' : 'none', + display: 'flex', flexDirection: 'column', }} > @@ -641,7 +641,11 @@ export const ReactQueryDevtoolsPanel = React.forwardRef< > {isMockOffline ? ( <> - + @@ -650,7 +654,11 @@ export const ReactQueryDevtoolsPanel = React.forwardRef< ) : ( <> - +