Skip to content
This repository was archived by the owner on Sep 9, 2024. It is now read-only.

Commit edba6a6

Browse files
authored
feat: update react-virtual (#913)
1 parent 0fb04fc commit edba6a6

File tree

4 files changed

+27
-35
lines changed

4 files changed

+27
-35
lines changed

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"@styled-icons/material-rounded": "10.47.0",
8484
"@styled-icons/remix-editor": "10.46.0",
8585
"@styled-icons/simple-icons": "10.46.0",
86+
"@tanstack/react-virtual": "3.0.0-beta.61",
8687
"@udecode/plate": "23.7.4",
8788
"@udecode/plate-cursor": "23.7.4",
8889
"@udecode/plate-juice": "23.7.4",
@@ -146,7 +147,6 @@
146147
"react-router-dom": "6.10.0",
147148
"react-scroll-sync": "0.11.0",
148149
"react-topbar-progress-indicator": "4.1.1",
149-
"react-virtual": "2.10.4",
150150
"react-virtualized-auto-sizer": "1.0.15",
151151
"react-waypoint": "10.3.0",
152152
"react-window": "1.8.9",

packages/core/src/components/collections/entries/EntryListingTable.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { useVirtualizer } from '@tanstack/react-virtual';
12
import React, { useCallback, useEffect, useMemo, useRef } from 'react';
2-
import { useVirtual } from 'react-virtual';
33

44
import useTranslate from '@staticcms/core/lib/hooks/useTranslate';
55
import classNames from '@staticcms/core/lib/util/classNames.util';
@@ -40,20 +40,25 @@ const EntryListingTable: FC<EntryListingTableProps> = ({
4040

4141
const tableContainerRef = useRef<HTMLDivElement | null>(null);
4242

43-
const { virtualItems: virtualRows, totalSize } = useVirtual({
44-
parentRef: tableContainerRef,
45-
size: entryData.length,
43+
const rowVirtualizer = useVirtualizer({
44+
getScrollElement: () => tableContainerRef.current,
45+
count: entryData.length,
4646
overscan: 10,
47+
estimateSize: () => 45,
4748
});
4849

50+
const virtualRows = rowVirtualizer.getVirtualItems();
51+
4952
const paddingTop = useMemo(
5053
() => (virtualRows.length > 0 ? virtualRows?.[0]?.start || 0 : 0),
5154
[virtualRows],
5255
);
5356
const paddingBottom = useMemo(
5457
() =>
55-
virtualRows.length > 0 ? totalSize - (virtualRows?.[virtualRows.length - 1]?.end || 0) : 0,
56-
[totalSize, virtualRows],
58+
virtualRows.length > 0
59+
? rowVirtualizer.getTotalSize() - (virtualRows?.[virtualRows.length - 1]?.end || 0)
60+
: 0,
61+
[rowVirtualizer, virtualRows],
5762
);
5863

5964
const fetchMoreOnBottomReached = useCallback(
@@ -108,7 +113,7 @@ const EntryListingTable: FC<EntryListingTableProps> = ({
108113
<td style={{ height: `${paddingTop}px` }} />
109114
</tr>
110115
)}
111-
{virtualRows.map(virtualRow => {
116+
{rowVirtualizer.getVirtualItems().map(virtualRow => {
112117
const data = entryData[virtualRow.index];
113118
return (
114119
<EntryRow

packages/docs/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
"@next/eslint-plugin-next": "13.5.4",
4141
"@types/js-yaml": "4.0.5",
4242
"@types/node": "18.16.14",
43-
"@types/prettier": "3.0.0",
4443
"@types/prismjs": "1.26.0",
4544
"@types/react": "18.2.0",
4645
"@types/react-dom": "18.2.1",

yarn.lock

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3577,11 +3577,6 @@
35773577
dependencies:
35783578
"@babel/runtime" "^7.13.10"
35793579

3580-
"@reach/observe-rect@^1.1.0":
3581-
version "1.2.0"
3582-
resolved "https://registry.yarnpkg.com/@reach/observe-rect/-/observe-rect-1.2.0.tgz#d7a6013b8aafcc64c778a0ccb83355a11204d3b2"
3583-
integrity sha512-Ba7HmkFgfQxZqqaeIWWkNK0rEhpxVQHIoVyW1YDSkGsGIXzcaW4deC8B0pZrNSSyLTdIk7y+5olKt5+g0GmFIQ==
3584-
35853580
"@react-dnd/asap@^5.0.1":
35863581
version "5.0.2"
35873582
resolved "https://registry.yarnpkg.com/@react-dnd/asap/-/asap-5.0.2.tgz#1f81f124c1cd6f39511c11a881cfb0f715343488"
@@ -3870,6 +3865,18 @@
38703865
dependencies:
38713866
tslib "^2.4.0"
38723867

3868+
"@tanstack/[email protected]":
3869+
version "3.0.0-beta.61"
3870+
resolved "https://registry.yarnpkg.com/@tanstack/react-virtual/-/react-virtual-3.0.0-beta.61.tgz#1c2e64affe677c883a475847e66b8774f731fa69"
3871+
integrity sha512-ElaOqL3FvJE075/6mRbv8VBHhiF5kHjGA7eo1O+x7sPWO7+fzkTr7t7AhNaWzRLxhUpQfbb6XG3ltp8mpfFLQg==
3872+
dependencies:
3873+
"@tanstack/virtual-core" "3.0.0-beta.61"
3874+
3875+
"@tanstack/[email protected]":
3876+
version "3.0.0-beta.61"
3877+
resolved "https://registry.yarnpkg.com/@tanstack/virtual-core/-/virtual-core-3.0.0-beta.61.tgz#a37b29d807e82b33d7d27a5fbee51de0f2a1f98a"
3878+
integrity sha512-C3iu9rkWvjJ/KbYAjuwLTjqiR9fcf9lXjRBLHDzsL/M6cR7/HLSU94abSdVrzuiqRvP7u7e0FeqPK0O3VbvWyg==
3879+
38733880
"@testing-library/[email protected]", "@testing-library/dom@^9.0.0":
38743881
version "9.2.0"
38753882
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-9.2.0.tgz#0e1f45e956f2a16f471559c06edd8827c4832f04"
@@ -4295,13 +4302,6 @@
42954302
resolved "https://registry.yarnpkg.com/@types/parse5/-/parse5-6.0.3.tgz#705bb349e789efa06f43f128cef51240753424cb"
42964303
integrity sha512-SuT16Q1K51EAVPz1K29DJ/sXjhSQ0zjvsypYJ6tlwVsRV9jwW5Adq2ch8Dq8kDBCkYnELS7N7VNCSB5nC56t/g==
42974304

4298-
4299-
version "3.0.0"
4300-
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-3.0.0.tgz#e9bc8160230d3a461dab5c5b41cceef1ef723057"
4301-
integrity sha512-mFMBfMOz8QxhYVbuINtswBp9VL2b4Y0QqYHwqLz3YbgtfAcat2Dl6Y1o4e22S/OVE6Ebl9m7wWiMT2lSbAs1wA==
4302-
dependencies:
4303-
prettier "*"
4304-
43054305
"@types/prettier@^2.1.5":
43064306
version "2.7.2"
43074307
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.7.2.tgz#6c2324641cc4ba050a8c710b2b251b377581fbf0"
@@ -6531,16 +6531,11 @@ ci-info@^2.0.0:
65316531
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-2.0.0.tgz#67a9e964be31a51e15e5010d58e6f12834002f46"
65326532
integrity sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ==
65336533

6534-
ci-info@^3.2.0:
6534+
ci-info@^3.2.0, ci-info@^3.8.0:
65356535
version "3.8.0"
65366536
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-3.8.0.tgz#81408265a5380c929f0bc665d62256628ce9ef91"
65376537
integrity sha512-eXTggHWSooYhq49F2opQhuHWgzucfF2YgODK4e1566GQs5BIfP30B0oenwBJHfWxAs2fyPB1s7Mg949zLf61Yw==
65386538

6539-
ci-info@^3.8.0:
6540-
version "3.9.0"
6541-
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-3.9.0.tgz#4279a62028a7b1f262f3473fc9605f5e218c59b4"
6542-
integrity sha512-NIxF55hv4nSqQswkAeiOi1r83xy8JldOFDTWiug55KBu9Jnblncd2U6ViHmYgHf01TPZS77NJBhBMKdWj9HQMQ==
6543-
65446539
cjs-module-lexer@^1.0.0:
65456540
version "1.2.2"
65466541
resolved "https://registry.yarnpkg.com/cjs-module-lexer/-/cjs-module-lexer-1.2.2.tgz#9f84ba3244a512f3a54e5277e8eef4c489864e40"
@@ -13990,7 +13985,7 @@ prettier-linter-helpers@^1.0.0:
1399013985
dependencies:
1399113986
fast-diff "^1.1.2"
1399213987

13993-
prettier@*, prettier@3.0.3:
13988+
1399413989
version "3.0.3"
1399513990
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.0.3.tgz#432a51f7ba422d1469096c0fdc28e235db8f9643"
1399613991
integrity sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==
@@ -14454,13 +14449,6 @@ react-transition-group@^4.4.5:
1445414449
loose-envify "^1.4.0"
1445514450
prop-types "^15.6.2"
1445614451

14457-
14458-
version "2.10.4"
14459-
resolved "https://registry.yarnpkg.com/react-virtual/-/react-virtual-2.10.4.tgz#08712f0acd79d7d6f7c4726f05651a13b24d8704"
14460-
integrity sha512-Ir6+oPQZTVHfa6+JL9M7cvMILstFZH/H3jqeYeKI4MSUX+rIruVwFC6nGVXw9wqAw8L0Kg2KvfXxI85OvYQdpQ==
14461-
dependencies:
14462-
"@reach/observe-rect" "^1.1.0"
14463-
1446414452
1446514453
version "1.0.15"
1446614454
resolved "https://registry.yarnpkg.com/react-virtualized-auto-sizer/-/react-virtualized-auto-sizer-1.0.15.tgz#84558bcab61a625d13ec37876639bb09c5a3ec0b"

0 commit comments

Comments
 (0)