Prevent infinite re-renders in extensions (#457)
Regression introduced with 593acc7f89
This commit is contained in:
@@ -26,7 +26,7 @@ import {
|
|||||||
useSubscription,
|
useSubscription,
|
||||||
} from '@apollo/client';
|
} from '@apollo/client';
|
||||||
import { OperationVariables } from '@apollo/client/core';
|
import { OperationVariables } from '@apollo/client/core';
|
||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||||
import { IRestClient, RestClient } from '@/lib/requests/client/RestClient.ts';
|
import { IRestClient, RestClient } from '@/lib/requests/client/RestClient.ts';
|
||||||
import * as storage from '@/util/localStorage.tsx';
|
import * as storage from '@/util/localStorage.tsx';
|
||||||
import { GraphQLClient } from '@/lib/requests/client/GraphQLClient.ts';
|
import { GraphQLClient } from '@/lib/requests/client/GraphQLClient.ts';
|
||||||
@@ -876,12 +876,25 @@ export class RequestManager {
|
|||||||
{},
|
{},
|
||||||
{ refetchQueries: [GET_EXTENSIONS], ...options },
|
{ refetchQueries: [GET_EXTENSIONS], ...options },
|
||||||
);
|
);
|
||||||
|
const [, setUpdatedCache] = useState({});
|
||||||
|
|
||||||
if (result.data?.fetchExtensions.extensions) {
|
useEffect(() => {
|
||||||
this.cache.cacheResponse(EXTENSION_LIST_CACHE_KEY, undefined, result);
|
if (result.loading) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!result.data?.fetchExtensions.extensions) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.cache.cacheResponse(EXTENSION_LIST_CACHE_KEY, undefined, result);
|
||||||
|
setUpdatedCache({});
|
||||||
|
}, [result.loading]);
|
||||||
|
|
||||||
const cachedResult = this.cache.getResponseFor<typeof result>(EXTENSION_LIST_CACHE_KEY, undefined, 1000 * 60);
|
const cachedResult = this.cache.getResponseFor<typeof result>(EXTENSION_LIST_CACHE_KEY, undefined, 1000 * 60);
|
||||||
const normalizedCachedResult = !cachedResult
|
const normalizedCachedResult = useMemo(
|
||||||
|
() =>
|
||||||
|
!cachedResult
|
||||||
? result
|
? result
|
||||||
: {
|
: {
|
||||||
...cachedResult,
|
...cachedResult,
|
||||||
@@ -902,7 +915,9 @@ export class RequestManager {
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
},
|
||||||
|
[this.cache.getFetchTimestampFor(EXTENSION_LIST_CACHE_KEY, undefined)],
|
||||||
|
);
|
||||||
|
|
||||||
const wrappedMutate = async (mutateOptions: Parameters<typeof mutate>[0]) => {
|
const wrappedMutate = async (mutateOptions: Parameters<typeof mutate>[0]) => {
|
||||||
if (cachedResult) {
|
if (cachedResult) {
|
||||||
|
|||||||
Reference in New Issue
Block a user