Skip to content

Commit 975bf1d

Browse files
authored
Pause typekit MutationObserver during scrolling (#6699)
1 parent 9f2bec8 commit 975bf1d

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

packages/@react-aria/virtualizer/src/ScrollView.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ export function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement
102102
state.isScrolling = true;
103103
setScrolling(true);
104104

105+
// Pause typekit MutationObserver during scrolling.
106+
window.dispatchEvent(new Event('tk.disconnect-observer'));
105107
if (onScrollStart) {
106108
onScrollStart();
107109
}
@@ -120,6 +122,7 @@ export function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement
120122
setScrolling(false);
121123
state.scrollTimeout = null;
122124

125+
window.dispatchEvent(new Event('tk.connect-observer'));
123126
if (onScrollEnd) {
124127
onScrollEnd();
125128
}
@@ -135,6 +138,9 @@ export function useScrollView(props: ScrollViewProps, ref: RefObject<HTMLElement
135138
useEffect(() => {
136139
return () => {
137140
clearTimeout(state.scrollTimeout);
141+
if (state.isScrolling) {
142+
window.dispatchEvent(new Event('tk.connect-observer'));
143+
}
138144
};
139145
// eslint-disable-next-line react-hooks/exhaustive-deps
140146
}, []);

packages/@react-stately/layout/src/ListLayout.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ export class ListLayout<T, O = any> extends Layout<Node<T>, O> implements DropTa
244244
}
245245

246246
let layoutNode = this.buildNode(node, x, y);
247-
layoutNode.node = node;
248247

249248
layoutNode.layoutInfo.parentKey = parentKey ?? null;
250249
this.layoutNodes.set(node.key, layoutNode);
@@ -310,7 +309,8 @@ export class ListLayout<T, O = any> extends Layout<Node<T>, O> implements DropTa
310309
return {
311310
layoutInfo,
312311
children,
313-
validRect: layoutInfo.rect.intersection(this.requestedRect)
312+
validRect: layoutInfo.rect.intersection(this.requestedRect),
313+
node
314314
};
315315
}
316316

@@ -347,7 +347,8 @@ export class ListLayout<T, O = any> extends Layout<Node<T>, O> implements DropTa
347347
return {
348348
layoutInfo: header,
349349
children: [],
350-
validRect: header.rect.intersection(this.requestedRect)
350+
validRect: header.rect.intersection(this.requestedRect),
351+
node
351352
};
352353
}
353354

@@ -380,7 +381,9 @@ export class ListLayout<T, O = any> extends Layout<Node<T>, O> implements DropTa
380381
layoutInfo.estimatedSize = isEstimated;
381382
return {
382383
layoutInfo,
383-
validRect: layoutInfo.rect
384+
children: [],
385+
validRect: layoutInfo.rect,
386+
node
384387
};
385388
}
386389

packages/@react-stately/layout/src/TableLayout.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ export class TableLayout<T, O extends TableLayoutProps = TableLayoutProps> exten
113113
return {
114114
layoutInfo,
115115
children,
116-
validRect: layoutInfo.rect
116+
validRect: layoutInfo.rect,
117+
node: this.collection.head
117118
};
118119
}
119120

@@ -143,7 +144,8 @@ export class TableLayout<T, O extends TableLayoutProps = TableLayoutProps> exten
143144
return {
144145
layoutInfo: row,
145146
children: columns,
146-
validRect: rect
147+
validRect: rect,
148+
node: headerRow
147149
};
148150
}
149151

@@ -208,7 +210,9 @@ export class TableLayout<T, O extends TableLayoutProps = TableLayoutProps> exten
208210

209211
return {
210212
layoutInfo,
211-
validRect: layoutInfo.rect
213+
children: [],
214+
validRect: layoutInfo.rect,
215+
node
212216
};
213217
}
214218

@@ -259,7 +263,8 @@ export class TableLayout<T, O extends TableLayoutProps = TableLayoutProps> exten
259263
return {
260264
layoutInfo,
261265
children,
262-
validRect: layoutInfo.rect.intersection(this.requestedRect)
266+
validRect: layoutInfo.rect.intersection(this.requestedRect),
267+
node: this.collection.body
263268
};
264269
}
265270

@@ -296,6 +301,8 @@ export class TableLayout<T, O extends TableLayoutProps = TableLayoutProps> exten
296301
if (layoutNode) {
297302
layoutNode.layoutInfo.rect.x = x;
298303
x += layoutNode.layoutInfo.rect.width;
304+
} else {
305+
break;
299306
}
300307
} else {
301308
let layoutNode = this.buildChild(child, x, y, layoutInfo.key);
@@ -315,7 +322,8 @@ export class TableLayout<T, O extends TableLayoutProps = TableLayoutProps> exten
315322
return {
316323
layoutInfo,
317324
children,
318-
validRect: rect.intersection(this.requestedRect)
325+
validRect: rect.intersection(this.requestedRect),
326+
node
319327
};
320328
}
321329

@@ -330,7 +338,9 @@ export class TableLayout<T, O extends TableLayoutProps = TableLayoutProps> exten
330338

331339
return {
332340
layoutInfo,
333-
validRect: rect
341+
children: [],
342+
validRect: rect,
343+
node
334344
};
335345
}
336346

0 commit comments

Comments
 (0)