Skip to content

Commit

Permalink
fix(packages/react): prevent fetch loops from cofetching resolvers
Browse files Browse the repository at this point in the history
  • Loading branch information
vicary committed Mar 23, 2024
1 parent cc1b627 commit 523cb55
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 266 deletions.
2 changes: 1 addition & 1 deletion packages/react/src/query/preparedQuery.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GQtyError, type BaseGeneratedSchema, type GQtyClient } from 'gqty';
import { useSyncExternalStore } from 'use-sync-external-store/shim';
import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
import { createMemoryStore } from '../memoryStore';
import type { ReactClientOptionsWithDefaults } from '../utils';

Expand Down
8 changes: 7 additions & 1 deletion packages/react/src/query/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,16 @@ export const createUseQuery = <TSchema extends BaseGeneratedSchema>(
.map(({ context, resolve }) => {
context.shouldFetch = true;

return resolve();
const ret = resolve();

context.shouldFetch = false;

return ret;
})
.concat(resolve());

context.shouldFetch = false;

const promise = Promise.all(pendingPromises);

// Mutex lock, prevents multiple refetches from happening at the
Expand Down
Loading

0 comments on commit 523cb55

Please sign in to comment.