Skip to content

Commit

Permalink
Merge pull request #7 from RonasIT/ipakhomov/fix-updating-entity-cach…
Browse files Browse the repository at this point in the history
…e-for-infintite-queries

Temporary fix for updating entity cache of infinite queries
  • Loading branch information
ipakhomov authored May 8, 2024
2 parents e807744 + f529a44 commit 7b2ac16
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/utils/create-entity-api-utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { PatchCollection } from '@reduxjs/toolkit/dist/query/core/buildThunks.d';
import { ClassConstructor } from 'class-transformer';
import { merge } from 'lodash';
import { EntityTagID } from '../enums';
import { BaseEntity, EntityRequest, PaginationRequest, PaginationResponse } from '../models';
import {
EntityApi,
Expand Down Expand Up @@ -50,7 +51,11 @@ export const createEntityApiUtils = <
return patchResults;
}

const cachedQueries = api.util.selectInvalidatedBy(getState(), [{ type: entityName, id: entityData.id }]);
const cachedQueries = api.util.selectInvalidatedBy(getState(), [
{ type: entityName, id: entityData.id },
// TODO: Remove selecting all lists once issue is fixed: https://github.com/reduxjs/redux-toolkit/issues/3583
{ type: entityName, id: EntityTagID.LIST }
]);

for (const { endpointName, originalArgs } of cachedQueries) {
const existingEntity = shouldRefetchEntity
Expand Down Expand Up @@ -86,7 +91,11 @@ export const createEntityApiUtils = <
return patchResults;
}

const cachedQueries = api.util.selectInvalidatedBy(getState(), [{ type: entityName, id }]);
const cachedQueries = api.util.selectInvalidatedBy(getState(), [
{ type: entityName, id },
// TODO: Remove selecting all lists once issue is fixed: https://github.com/reduxjs/redux-toolkit/issues/3583
{ type: entityName, id: EntityTagID.LIST }
]);

for (const { endpointName, originalArgs } of cachedQueries) {
const action = api.util.updateQueryData(
Expand Down

0 comments on commit 7b2ac16

Please sign in to comment.