diff --git a/.changeset/long-teeth-worry.md b/.changeset/long-teeth-worry.md new file mode 100644 index 000000000..3f1d3899c --- /dev/null +++ b/.changeset/long-teeth-worry.md @@ -0,0 +1,5 @@ +--- +"bits-ui": patch +--- + +fix(FloatingContent): watch deps diff --git a/packages/bits-ui/src/lib/bits/utilities/floating-layer/use-floating-layer.svelte.ts b/packages/bits-ui/src/lib/bits/utilities/floating-layer/use-floating-layer.svelte.ts index d0819a4e2..d6453a404 100644 --- a/packages/bits-ui/src/lib/bits/utilities/floating-layer/use-floating-layer.svelte.ts +++ b/packages/bits-ui/src/lib/bits/utilities/floating-layer/use-floating-layer.svelte.ts @@ -293,13 +293,14 @@ export class FloatingContentState { }); watch( - () => this.contentRef.current, - (contentNode) => { - if (!contentNode || !this.opts.enabled.current) return; + [() => this.contentRef.current, () => this.opts.enabled.current], + ([contentNode, enabled]) => { + if (!contentNode || !enabled) return; const win = getWindow(contentNode); const rafId = win.requestAnimationFrame(() => { // avoid applying stale values when refs change quickly - if (this.contentRef.current !== contentNode || !this.opts.enabled.current) return; + if (this.contentRef.current !== contentNode || !this.opts.enabled.current) + return; const zIndex = win.getComputedStyle(contentNode).zIndex; if (zIndex !== this.contentZIndex) { this.contentZIndex = zIndex;