Skip to content

Commit

Permalink
Remove the modal and its backdrop before turbo cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrombez authored Jan 17, 2024
1 parent e6ed199 commit 66e4e4f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions assets/dist/modal_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ export default class extends Controller {
this.element.addEventListener('turbo:frame-render', this.turbo_onFrameRender)
this.element.addEventListener('turbo:submit-end', this.turbo_onSubmitEnd)

// Remove instantly the modal backdrop before turbo save the page snapshot into its cache.
document.addEventListener('turbo:before-cache', () => {
this.element.classList.remove('fade');
let modal = this.getModal()
modal._backdrop._config.isAnimated = false;
modal.hide();
modal.dispose();
})

console.log('Modal -> autoOpen: ' + this.autoOpenValue)

if (this.autoOpenValue) {
Expand All @@ -34,10 +43,6 @@ export default class extends Controller {
disconnect() {
this.element.removeEventListener('turbo:frame-render', this.turbo_onFrameRender)
this.element.removeEventListener('turbo:submit-end', this.turbo_onSubmitEnd)

// this.close()
// // pour ne jamais mettre en cache turbo une modal qui s'ouvrirait à la restoration du cache.
// this.autoOpenValue = false
}

getModal() {
Expand Down

0 comments on commit 66e4e4f

Please sign in to comment.