Skip to content

Instantly share code, notes, and snippets.

@oliveira-andre
Created April 11, 2025 20:43
Show Gist options
  • Save oliveira-andre/9134ad35db2d4975dabde0e117635dad to your computer and use it in GitHub Desktop.
Save oliveira-andre/9134ad35db2d4975dabde0e117635dad to your computer and use it in GitHub Desktop.
Turbo Morph compatibility
import { Controller } from "@hotwired/stimulus";
export default extends Controller {
connect() {
this.reconnect = this.reconnect.bind(this);
window.addEventListener('turbo:morph', this.reconnect);
myLibrary.create();
}
disconnect() {
window.removeEventListener('turbo:morph', this.reconnect);
}
reconnect() {
myLibrary.destroy();
myLibrary.create();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment