mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 19:48:08 +00:00
feat: handle rails turbo morphing (#11422)
Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
This commit is contained in:
@@ -23,12 +23,18 @@ const runSDK = ({ baseUrl, websiteToken }) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window.Turbo) {
|
// if this is a Rails Turbo app
|
||||||
// if this is a Rails Turbo app
|
document.addEventListener('turbo:before-render', event => {
|
||||||
document.addEventListener('turbo:before-render', event =>
|
// when morphing the page, this typically happens on reload like events
|
||||||
restoreWidgetInDOM(event.detail.newBody)
|
// say you update a "Customer" on a form and it reloads the page
|
||||||
);
|
// We have already added data-turbo-permananent to true. This
|
||||||
}
|
// will ensure that the widget it preserved
|
||||||
|
// Read more about morphing here: https://turbo.hotwired.dev/handbook/page_refreshes#morphing
|
||||||
|
// and peristing elements here: https://turbo.hotwired.dev/handbook/building#persisting-elements-across-page-loads
|
||||||
|
if (event.detail.renderMethod === 'morph') return;
|
||||||
|
|
||||||
|
restoreWidgetInDOM(event.detail.newBody);
|
||||||
|
});
|
||||||
|
|
||||||
if (window.Turbolinks) {
|
if (window.Turbolinks) {
|
||||||
document.addEventListener('turbolinks:before-render', event => {
|
document.addEventListener('turbolinks:before-render', event => {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ export const loadCSS = () => {
|
|||||||
const css = document.createElement('style');
|
const css = document.createElement('style');
|
||||||
css.innerHTML = `${SDK_CSS}`;
|
css.innerHTML = `${SDK_CSS}`;
|
||||||
css.id = 'cw-widget-styles';
|
css.id = 'cw-widget-styles';
|
||||||
|
css.dataset.turboPermanent = true;
|
||||||
document.body.appendChild(css);
|
document.body.appendChild(css);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ export const IFrameHelper = {
|
|||||||
|
|
||||||
addClasses(widgetHolder, holderClassName);
|
addClasses(widgetHolder, holderClassName);
|
||||||
widgetHolder.id = 'cw-widget-holder';
|
widgetHolder.id = 'cw-widget-holder';
|
||||||
|
widgetHolder.dataset.turboPermanent = true;
|
||||||
widgetHolder.appendChild(iframe);
|
widgetHolder.appendChild(iframe);
|
||||||
body.appendChild(widgetHolder);
|
body.appendChild(widgetHolder);
|
||||||
IFrameHelper.initPostMessageCommunication();
|
IFrameHelper.initPostMessageCommunication();
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ export const createBubbleHolder = hideMessageBubble => {
|
|||||||
}
|
}
|
||||||
addClasses(bubbleHolder, 'woot--bubble-holder');
|
addClasses(bubbleHolder, 'woot--bubble-holder');
|
||||||
bubbleHolder.id = 'cw-bubble-holder';
|
bubbleHolder.id = 'cw-bubble-holder';
|
||||||
|
bubbleHolder.dataset.turboPermanent = true;
|
||||||
body.appendChild(bubbleHolder);
|
body.appendChild(bubbleHolder);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user