Closed jet2jet closed 10 months ago
When query for different fields in same type (such as requesting Todo.description and requesting Todo.tags), one query is fetched twice. This only happens when SSR data is available.
Todo.description
Todo.tags
I suspect following lines (https://github.com/urql-graphql/urql/blob/%40urql/exchange-graphcache%406.3.3/exchanges/graphcache/src/cacheExchange.ts#L134-L140)
// Upon completion, all dependent operations become reexecuting operations, preventing // them from reexecuting prior operations again, causing infinite loops const _reexecutingOperations = reexecutingOperations; if (operation.kind === 'query') { (reexecutingOperations = dependentOperations).add(operation.key); } (dependentOperations = _reexecutingOperations).clear();
When operation.kind is not 'query', reexecutingOperations will not be changed, causing reexecutingOperations and dependentOperations is equal. I think this affects the line https://github.com/urql-graphql/urql/blob/%40urql/exchange-graphcache%406.3.3/exchanges/graphcache/src/cacheExchange.ts#L378 and results fetching is performed again. (When moving reexecutingOperations = dependentOperations code to outer of if, the problem seems to be fixed.)
operation.kind
'query'
reexecutingOperations
dependentOperations
reexecutingOperations = dependentOperations
if
https://github.com/jet2jet/urql-multi-query-with-ssr-test
npm ci
npm run start
1
ID:
Get
TodoTags
TodoDetail
urql v4.0.5 @urql/exchange-graphcache v6.3.3
Describe the bug
When query for different fields in same type (such as requesting
Todo.description
and requestingTodo.tags
), one query is fetched twice. This only happens when SSR data is available.I suspect following lines (https://github.com/urql-graphql/urql/blob/%40urql/exchange-graphcache%406.3.3/exchanges/graphcache/src/cacheExchange.ts#L134-L140)
When
operation.kind
is not'query'
,reexecutingOperations
will not be changed, causingreexecutingOperations
anddependentOperations
is equal. I think this affects the line https://github.com/urql-graphql/urql/blob/%40urql/exchange-graphcache%406.3.3/exchanges/graphcache/src/cacheExchange.ts#L378 and results fetching is performed again.(When moving
reexecutingOperations = dependentOperations
code to outer ofif
, the problem seems to be fixed.)Reproduction
https://github.com/jet2jet/urql-multi-query-with-ssr-test
npm ci
)npm run start
1
toID:
and clickGet
TodoTags
query is fetched twice (Expected: bothTodoDetail
andTodoTags
queries are fetched once)Urql version
urql v4.0.5 @urql/exchange-graphcache v6.3.3
Validations