Wait for the search view's ref before watching it

Alpine registers x-ref as it walks the children, so $refs.view is not
there yet when the component's init() runs.

Plan step 13, finding IN-01.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qwx5USif3wFFmxtHg5U1g9
This commit is contained in:
Andreas Reinhold / reini
2026-09-14 06:14:40 +02:00
co-authored by Claude Fable 5.1
parent 0ffb2b06db
commit a13f5e44a6
+6 -3
View File
@@ -43,8 +43,11 @@ document.addEventListener('alpine:init', () => {
this.compact = query.matches
query.addEventListener('change', (event) => (this.compact = event.matches))
this.observer = new MutationObserver(() => this.countLater())
this.observer.observe(this.$refs.view, { childList: true, subtree: true, characterData: true })
// Alpine registers x-ref as it walks the children, which is after this runs.
this.$nextTick(() => {
this.observer = new MutationObserver(() => this.countLater())
this.observer.observe(this.$refs.view, { childList: true, subtree: true, characterData: true })
})
this.$watch('open', () => this.countLater())
},
@@ -60,7 +63,7 @@ document.addEventListener('alpine:init', () => {
},
count() {
if (! this.open) {
if (! this.open || ! this.$refs.view) {
this.announcement = ''
return