fix: guard Chatwoot bubble toggle until holder is in the DOM (#485)

ChatwootWidget's visibility effect took the synchronous fast path whenever
`window.$chatwoot` was truthy. But the SDK assigns `$chatwoot` (with
`toggleBubbleVisibility`) synchronously in run(), while `.woot--bubble-holder`
is only appended later, after the widget iframe finishes loading. Calling
`toggleBubbleVisibility("show")` in that gap makes the SDK dereference
`null.classList` — an intermittent crash on navigating to /workflow that
surfaces via the React error boundary (follow-up to #483).

Gate the immediate-apply path on the bubble holder actually being in the DOM;
when it's absent, fall through to the existing `chatwoot:ready` listener, which
the SDK fires only after the holder is created.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
PK 2026-06-30 22:10:49 +05:30 committed by GitHub
parent a616b7ff98
commit a850d18767
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -99,9 +99,12 @@ export default function ChatwootWidget() {
} }
}; };
// The SDK may not be ready on first navigation; apply once it fires // Apply immediately only once the bubble holder is actually in the DOM.
// `chatwoot:ready`, otherwise apply immediately. // `window.$chatwoot` exists synchronously after run(), but `.woot--bubble-holder`
if (window.$chatwoot) { // is appended later when the widget iframe loads, and toggleBubbleVisibility()
// dereferences it with no null check. When it's absent, fall through to
// `chatwoot:ready`, which the SDK fires once the holder exists.
if (window.$chatwoot && document.querySelector(".woot--bubble-holder")) {
applyVisibility(); applyVisibility();
return; return;
} }