Skip to content

Commit a3b898e

Browse files
committed
only resolve the next set of containers when needed
This is just a very very small optimization, but wanted to optimize it since I noticed it. Essentially `containers.flatMap(resolve => resolve())` is a bit wasteful if we you have `n` containers, but you already found a match in the first container. If that's the case, then we resolved `n-1` containers for nothing. Depending on what we actually do during this resolve step it could be a lot of unnecessary work (e.g.: querying the DOM).
1 parent 98113b6 commit a3b898e

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

packages/@headlessui-react/src/hooks/document-overflow/handle-ios-locking.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@ export function handleIOSLocking(): ScrollLockStep<ContainerMetadata> {
1515
return {
1616
before({ doc, d, meta }) {
1717
function inAllowedContainer(el: Element) {
18-
return meta()
19-
.containers.flatMap((resolve) => resolve())
20-
.some((container) => container.contains(el))
18+
for (let resolve of meta().containers) {
19+
for (let element of resolve()) {
20+
if (element.contains(el)) {
21+
return true
22+
}
23+
}
24+
}
25+
26+
return false
2127
}
2228

2329
d.microTask(() => {

0 commit comments

Comments
 (0)