fix: widget does not load when navigating on pages with view transition [CW-3249] (#9443)
* feat: add ids to each element * feat: restore elements for apps that use view transitions * fix: remove generator check condition * feat: handle turbolinks * fix: new body handling * chore: undo debug changes
This commit is contained in:
@@ -10,14 +10,37 @@ import {
|
||||
getUserCookieName,
|
||||
hasUserKeys,
|
||||
} from '../sdk/cookieHelpers';
|
||||
import { addClasses, removeClasses } from '../sdk/DOMHelpers';
|
||||
import {
|
||||
addClasses,
|
||||
removeClasses,
|
||||
restoreWidgetInDOM,
|
||||
} from '../sdk/DOMHelpers';
|
||||
import { setCookieWithDomain } from '../sdk/cookieHelpers';
|
||||
import { SDK_SET_BUBBLE_VISIBILITY } from 'shared/constants/sharedFrameEvents';
|
||||
|
||||
const runSDK = ({ baseUrl, websiteToken }) => {
|
||||
if (window.$chatwoot) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (window.Turbo) {
|
||||
// if this is a Rails Turbo app
|
||||
document.addEventListener('turbo:before-render', event =>
|
||||
restoreWidgetInDOM(event.detail.newBody)
|
||||
);
|
||||
}
|
||||
|
||||
if (window.Turbolinks) {
|
||||
document.addEventListener('turbolinks:before-render', event => {
|
||||
restoreWidgetInDOM(event.data.newBody);
|
||||
});
|
||||
}
|
||||
|
||||
// if this is an astro app
|
||||
document.addEventListener('astro:before-swap', event =>
|
||||
restoreWidgetInDOM(event.newDocument.body)
|
||||
);
|
||||
|
||||
const chatwootSettings = window.chatwootSettings || {};
|
||||
let locale = chatwootSettings.locale;
|
||||
let baseDomain = chatwootSettings.baseDomain;
|
||||
|
||||
Reference in New Issue
Block a user