Skip to content

Commit e0688c4

Browse files
authored
Improve performance of internal useInertOthers hook (#3181)
* do not use default function for `allowed` and `disallowed` Otherwise the fallback function will be used which will be a new reference on each render. On pages with lots of elements this causes performance issues. * update changelog
1 parent 886fdf7 commit e0688c4

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

packages/@headlessui-react/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
- Nothing yet!
10+
### Fixed
11+
12+
- Improve performance of internal `useInertOthers` hook ([#3181](https://github.com/tailwindlabs/headlessui/pull/3181))
1113

1214
## [2.0.1] - 2024-05-06
1315

packages/@headlessui-react/src/hooks/use-inert-others.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ function markNotInert(element: HTMLElement) {
7474
*/
7575
export function useInertOthers(
7676
{
77-
allowed = () => [],
78-
disallowed = () => [],
77+
allowed,
78+
disallowed,
7979
}: { allowed?: () => (HTMLElement | null)[]; disallowed?: () => (HTMLElement | null)[] } = {},
8080
enabled = true
8181
) {
@@ -85,14 +85,14 @@ export function useInertOthers(
8585
let d = disposables()
8686

8787
// Mark all disallowed elements as inert
88-
for (let element of disallowed()) {
88+
for (let element of disallowed?.() ?? []) {
8989
if (!element) continue
9090

9191
d.add(markInert(element))
9292
}
9393

9494
// Mark all siblings of allowed elements (and parents) as inert
95-
let allowedElements = allowed()
95+
let allowedElements = allowed?.() ?? []
9696

9797
for (let element of allowedElements) {
9898
if (!element) continue

0 commit comments

Comments
 (0)