Skip to content

Commit 52c04b9

Browse files
committed
Fix race condition when evicting aborted requests from cache
1 parent 533c300 commit 52c04b9

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

packages/app/src/App.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ function App(props: Props) {
4141
const { valuesStore } = useDataContext();
4242
function onSelectPath(path: string) {
4343
setSelectedPath(path);
44-
valuesStore.abortAll('entity changed');
45-
valuesStore.evictErrors();
44+
valuesStore.abortAll('entity changed', true);
4645
}
4746

4847
return (

packages/app/src/visualizer/VisManager.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ function VisManager(props: Props) {
3131
const { valuesStore } = useDataContext();
3232
function onVisChange(index: number) {
3333
setActiveVis(index);
34-
valuesStore.abortAll('visualization changed');
35-
valuesStore.evictErrors();
34+
valuesStore.abortAll('visualization changed', true);
3635
}
3736

3837
return (

packages/shared/src/react-suspense-fetch.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export interface FetchStore<Input, Result> {
2222
preset: (input: Input, result: Result) => void;
2323
evict: (input: Input) => void;
2424
evictErrors: () => void;
25-
abort: (input: Input, reason?: string) => void;
26-
abortAll: (reason?: string) => void;
25+
abort: (input: Input, reason?: string, evict?: boolean) => void;
26+
abortAll: (reason?: string, evict?: boolean) => void;
2727
get progressStore(): StoreApi<ProgressState<Input>>;
2828
}
2929

@@ -83,12 +83,20 @@ export function createFetchStore<Input, Result>(
8383
}
8484
});
8585
},
86-
abort: (input: Input, reason?: string): void => {
86+
abort: (input: Input, reason?: string, evict?: boolean): void => {
8787
cache.get(input)?.abort(reason);
88+
89+
if (evict) {
90+
cache.delete(input);
91+
}
8892
},
89-
abortAll: (reason?: string): void => {
90-
cache.values().forEach((instance) => {
93+
abortAll: (reason?: string, evict?: boolean): void => {
94+
cache.entries().forEach(([input, instance]) => {
9195
instance.abort(reason);
96+
97+
if (evict) {
98+
cache.delete(input);
99+
}
92100
});
93101
},
94102
get progressStore() {

0 commit comments

Comments
 (0)