From 37b519bdaa2a46cd2e8afc1cb852f10e7f7af735 Mon Sep 17 00:00:00 2001 From: Ryan Elainska Date: Sat, 19 Sep 2020 22:09:32 -0400 Subject: [PATCH] Add workaround for bug that causes query `skip` parameter to be ignored when `client.resetStore()` is called --- src/components/files/FileActions/FileVersions.tsx | 8 +++++++- src/scenes/Projects/Files/ProjectFilesList.tsx | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/components/files/FileActions/FileVersions.tsx b/src/components/files/FileActions/FileVersions.tsx index db0acd1b02..2347a8058a 100644 --- a/src/components/files/FileActions/FileVersions.tsx +++ b/src/components/files/FileActions/FileVersions.tsx @@ -34,9 +34,15 @@ export const FileVersions: FC = (props) => { const classes = useStyles(); const id = file?.id ?? ''; + const shouldSkipQuery = !file; const { data, loading } = useFileVersionsQuery({ variables: { id }, - skip: !file, + // Workaround for a known bug in Apollo client that causes + // `skip` to suddenly be ignored when `client.resetStore` is + // called: + // https://github.com/apollographql/react-apollo/issues/3492#issuecomment-622573677 + fetchPolicy: shouldSkipQuery ? 'cache-only' : 'cache-first', + skip: shouldSkipQuery, }); const total = data?.file.children.total; diff --git a/src/scenes/Projects/Files/ProjectFilesList.tsx b/src/scenes/Projects/Files/ProjectFilesList.tsx index 6738754ef1..65556cb76c 100644 --- a/src/scenes/Projects/Files/ProjectFilesList.tsx +++ b/src/scenes/Projects/Files/ProjectFilesList.tsx @@ -143,11 +143,17 @@ const ProjectFilesListWrapped: FC = () => { const isNotRootDirectory = directoryId !== rootDirectoryId; + const shouldSkipQuery = !directoryId; const { data, loading, error } = useProjectDirectoryQuery({ variables: { id: directoryId, }, - skip: !directoryId, + // Workaround for a known bug in Apollo client that causes + // `skip` to suddenly be ignored when `client.resetStore` is + // called: + // https://github.com/apollographql/react-apollo/issues/3492#issuecomment-622573677 + fetchPolicy: shouldSkipQuery ? 'cache-only' : 'cache-first', + skip: shouldSkipQuery, }); const parents = data?.directory.parents;