ClaimList: fix infinite effect loop (#1523)

`tileUris` is being used as an effect dependency, but it gets re-created on every render (same content, different reference), so the `setUriBuffer` effect ended up in a loop.
This commit is contained in:
infinite-persistence 2022-05-19 01:30:07 +08:00 committed by GitHub
parent b0b2056d78
commit 855d3dae01
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -119,14 +119,16 @@ export default function ClaimList(props: Props) {
const timedOut = uris === null; const timedOut = uris === null;
const urisLength = (uris && uris.length) || 0; const urisLength = (uris && uris.length) || 0;
let tileUris = (prefixUris || []).concat(uris || []); const tileUris = React.useMemo(() => {
const x = (prefixUris || []).concat(uris || []);
if (prefixUris && prefixUris.length) tileUris.splice(prefixUris.length * -1, prefixUris.length); if (prefixUris && prefixUris.length) {
x.splice(prefixUris.length * -1, prefixUris.length);
}
return maxClaimRender ? x.slice(0, maxClaimRender) : x;
}, [prefixUris, uris, maxClaimRender]);
const totalLength = tileUris.length; const totalLength = tileUris.length;
if (maxClaimRender) tileUris = tileUris.slice(0, maxClaimRender);
const sortedUris = (urisLength > 0 && (currentSort === SORT_NEW ? tileUris : tileUris.slice().reverse())) || []; const sortedUris = (urisLength > 0 && (currentSort === SORT_NEW ? tileUris : tileUris.slice().reverse())) || [];
React.useEffect(() => { React.useEffect(() => {