Last active
September 12, 2025 17:44
-
-
Save bensheldon/c708cef377f42b2c0c06aad16f233064 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const origDefine = customElements.define; | |
| customElements.define = function(name, ctor, options) { | |
| if (name !== 'turbo-cable-stream-source') return origDefine.call(this, name, ctor, options); | |
| const proto = ctor.prototype; | |
| const origDisconnectedCallback = proto.disconnectedCallback; | |
| const origConnectedCallback = proto.connectedCallback; | |
| proto.connectedCallback = async function() { | |
| if (this.disconnecting) { | |
| this.disconnecting = false; | |
| return; | |
| } | |
| return await origConnectedCallback.apply(this); | |
| }; | |
| proto.disconnectedCallback = async function() { | |
| // defer for one tick to allow the dom node to be re-attached, if turbo-permanent | |
| this.disconnecting = true; | |
| await new Promise(resolve => setTimeout(resolve, 0)) | |
| if (!this.disconnecting) { return; } | |
| return origDisconnectedCallback.apply(this); | |
| }; | |
| return origDefine.call(this, name, ctor, options); | |
| }; | |
| // do this before importing turbo-rails |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment