Skip to content

Commit 9b3442d

Browse files
committed
fix(solid): presence ref detection
1 parent e4daa9a commit 9b3442d

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

packages/solid/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## [Unreleased]
22

3+
### Fixed
4+
5+
- **General**: Fix issue where presence closing animation doesn't work as expected
6+
37
## [5.18.2] - 2025-07-26
48

59
### Fixed
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
type PossibleRef<T> = T | ((el: T) => void) | undefined
1+
import { createEffect, createSignal, on } from 'solid-js'
22

3-
const isRefFn = <T>(ref: PossibleRef<T>): ref is (el: T) => void => typeof ref === 'function'
3+
type PossibleRef<T> = T | ((el: T) => void) | undefined
44

5-
function setRef<T>(ref: PossibleRef<T>, value: T) {
6-
if (isRefFn(ref)) {
7-
ref(value)
8-
}
9-
}
5+
const isRefFn = <T>(ref: PossibleRef<T>): ref is (el: T | null) => void => typeof ref === 'function'
106

117
export function composeRefs<T>(...refs: PossibleRef<T>[]) {
12-
return (node: T) => {
13-
for (const ref of refs) {
14-
setRef(ref, node)
15-
}
16-
}
8+
const [node, setNode] = createSignal<T | null>(null)
9+
createEffect(
10+
on(node, (el) => {
11+
for (const ref of refs) {
12+
if (isRefFn(ref)) {
13+
ref(el)
14+
}
15+
}
16+
}),
17+
)
18+
return setNode
1719
}

0 commit comments

Comments
 (0)