Skip to content

Commit ade4e3c

Browse files
committed
Harden GitHub query cache validation and cleanup
1 parent ff1ee09 commit ade4e3c

5 files changed

Lines changed: 46 additions & 4 deletions

File tree

apps/dashboard/src/lib/query-client.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type PersistedGitHubQueryCache = {
2020
type PersistBehavior = true | "tab";
2121

2222
type PersistableGitHubQuery = {
23-
state: { status: string };
23+
state: { data?: unknown; status: string };
2424
meta?: Record<string, unknown>;
2525
queryKey: readonly unknown[];
2626
};
@@ -88,6 +88,10 @@ function shouldPersistGitHubQuery(query: PersistableGitHubQuery) {
8888
return false;
8989
}
9090

91+
if (query.state.data == null) {
92+
return false;
93+
}
94+
9195
if (persist === true) {
9296
return true;
9397
}
@@ -108,6 +112,13 @@ function pruneClosedTabQueries(queryClient: QueryClient, tabs: Tab[]) {
108112
});
109113
}
110114

115+
function pruneNullGitHubQueries(queryClient: QueryClient) {
116+
queryClient.removeQueries({
117+
predicate: (query) =>
118+
query.queryKey[0] === "github" && query.state.data == null,
119+
});
120+
}
121+
111122
function usePruneClosedTabQueries(queryClient: QueryClient) {
112123
const tabs = useTabs();
113124
const tabsRef = useRef(tabs);
@@ -143,6 +154,7 @@ function restorePersistedGitHubQueryCache(queryClient: QueryClient) {
143154
}
144155

145156
hydrate(queryClient, persistedState.clientState);
157+
pruneNullGitHubQueries(queryClient);
146158
} catch {
147159
window.localStorage.removeItem(GITHUB_QUERY_CACHE_STORAGE_KEY);
148160
}

apps/dashboard/src/routes/_protected/$owner/$repo/issues.$issueId.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ export const Route = createFileRoute(
1616
});
1717

1818
const cachedData = context.queryClient.getQueryData(pageOptions.queryKey);
19-
if (cachedData !== undefined) {
19+
if (cachedData !== null && cachedData !== undefined) {
2020
return cachedData;
2121
}
22+
if (cachedData === null) {
23+
context.queryClient.removeQueries({
24+
queryKey: pageOptions.queryKey,
25+
exact: true,
26+
});
27+
}
2228

2329
return context.queryClient.ensureQueryData(pageOptions);
2430
},

apps/dashboard/src/routes/_protected/$owner/$repo/pull.$pullId.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ export const Route = createFileRoute("/_protected/$owner/$repo/pull/$pullId")({
1717
});
1818

1919
const cachedData = context.queryClient.getQueryData(pageOptions.queryKey);
20-
if (cachedData !== undefined) {
20+
if (cachedData?.detail) {
2121
void context.queryClient.ensureQueryData(githubViewerQueryOptions(scope));
2222
return cachedData;
2323
}
24+
if (cachedData !== undefined) {
25+
context.queryClient.removeQueries({
26+
queryKey: pageOptions.queryKey,
27+
exact: true,
28+
});
29+
}
2430

2531
const [pageData] = await Promise.all([
2632
context.queryClient.ensureQueryData(pageOptions),

apps/dashboard/src/routes/_protected/$owner/$repo/review.$pullId.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,19 @@ export const Route = createFileRoute("/_protected/$owner/$repo/review/$pullId")(
2222
input,
2323
);
2424

25-
const cachedPageData = context.queryClient.getQueryData(
25+
let cachedPageData = context.queryClient.getQueryData(
2626
pageOptions.queryKey,
2727
);
2828
const cachedFileSummaries = context.queryClient.getQueryData(
2929
fileSummariesOptions.queryKey,
3030
);
31+
if (cachedPageData !== undefined && !cachedPageData?.detail) {
32+
context.queryClient.removeQueries({
33+
queryKey: pageOptions.queryKey,
34+
exact: true,
35+
});
36+
cachedPageData = undefined;
37+
}
3138

3239
// Check if infinite query already has data
3340
const filesQueryKey = githubQueryKeys.pulls.files(scope, input);

paseo.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"worktree": {
3+
"setup": [
4+
"pnpm i && cd apps/dashboard && yes | node ../../scripts/run-d1-migrations.mjs diffkit-db --local; exit 0"
5+
],
6+
"teardown": [
7+
"rm -rf \"$PASEO_WORKTREE_PATH/node_modules\" \"$PASEO_WORKTREE_PATH/apps/*/node_modules\" \"$PASEO_WORKTREE_PATH/packages/*/node_modules\"",
8+
"if [ -n \"$PASEO_WORKTREE_PORT\" ]; then lsof -ti :$PASEO_WORKTREE_PORT | xargs -r kill -9; fi"
9+
]
10+
}
11+
}

0 commit comments

Comments
 (0)