MCPcopy Create free account
hub / github.com/bvaughn/react-window / settle

Function settle

integrations/tests/tests/settle.ts:10–64  ·  view source on GitHub ↗
(
  page: Page,
  {
    maxFrames = 60,
    minFrames = 3,
    stableFrames = 5
  }: { maxFrames?: number; minFrames?: number; stableFrames?: number } = {}
)

Source from the content-addressed store, hash-verified

8 * and isn't necessary once rows have rendered and been measured.
9 */
10export async function settle(
11 page: Page,
12 {
13 maxFrames = 60,
14 minFrames = 3,
15 stableFrames = 5
16 }: { maxFrames?: number; minFrames?: number; stableFrames?: number } = {}
17) {
18 await page.evaluate(
19 async ({ maxFrames, minFrames, stableFrames }) => {
20 const getSnapshot = () => {
21 const scrollPositions = Array.from(
22 document.querySelectorAll(
23 '[data-testid="scroller"], [role="grid"], [role="list"]'
24 )
25 ).map((element) => `${element.scrollLeft},${element.scrollTop}`);
26
27 return [
28 window.scrollX,
29 window.scrollY,
30 ...scrollPositions,
31 document.body.innerHTML
32 ].join("|");
33 };
34
35 // WebKit on Linux (in CI) sometimes stops running animation frames;
36 // don't wait for more than a frame's worth of time (at a low frame rate)
37 const nextFrame = () =>
38 new Promise<void>((resolve) => {
39 const done = () => {
40 cancelAnimationFrame(animationFrameId);
41 clearTimeout(timeoutId);
42 resolve();
43 };
44 const animationFrameId = requestAnimationFrame(done);
45 const timeoutId = setTimeout(done, 50);
46 });
47
48 let snapshot = getSnapshot();
49 let unchangedFrames = 0;
50 for (let frame = 0; frame < maxFrames; frame++) {
51 await nextFrame();
52
53 const nextSnapshot = getSnapshot();
54 unchangedFrames = nextSnapshot === snapshot ? unchangedFrames + 1 : 0;
55 snapshot = nextSnapshot;
56
57 if (frame + 1 >= minFrames && unchangedFrames >= stableFrames) {
58 return;
59 }
60 }
61 },
62 { maxFrames, minFrames, stableFrames }
63 );
64}

Callers 6

getRowBoundsFunction · 0.90
waitForScrollEndFunction · 0.90
changeContentAboveFunction · 0.90
headless.spec.tsxFile · 0.90

Calls 2

getSnapshotFunction · 0.85
nextFrameFunction · 0.85

Tested by 3

getRowBoundsFunction · 0.72
waitForScrollEndFunction · 0.72
changeContentAboveFunction · 0.72