Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alter Action Cable Element to be morph-compatible #650

Merged
merged 1 commit into from
Sep 17, 2024

Conversation

seanpdoyle
Copy link
Contributor

Closes #638

Recent changes to integrate with morphing have altered the mental model for some Turbo custom elements, including the
<turbo-cable-stream-source> element.

Custom Elements' connectedCallback() and disconnectedCallback() (along with Stimulus' connect() and disconnect()) improved upon invoking code immediately, or listening for DOMContentLoaded events.

There are similar improvements to be made to integrate with morphing. First, observe attribute changes by declaring their own static observedAttributes properties along with
attributeChangedCallback(name, oldValue, newValue) callbacks. Those callbacks execute the same initialization code as their current connectedCallback() and disconnectedCallback() methods.

That'll help resolve this issue. In addition to those changes, it's important to emphasize this pattern for consumer applications moving forward. JavaScript code (whether Stimulus controller or otherwise) should be implemented in a way that' resilient to both asynchronous connection and disconnection as well as asynchronous modification of attributes.

@seanpdoyle
Copy link
Contributor Author

@jorgemanrubia @brunoprietog are either of you able to review these changes?

@seanpdoyle seanpdoyle force-pushed the issue-638 branch 6 times, most recently from 2b4b903 to e306940 Compare July 24, 2024 11:54
@Michoels
Copy link

This would be great!
Are there any plans to merge it?

@seanpdoyle seanpdoyle force-pushed the issue-638 branch 2 times, most recently from 7b12849 to 84bab74 Compare September 16, 2024 13:46
Copy link
Member

@jorgemanrubia jorgemanrubia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@jorgemanrubia
Copy link
Member

@seanpdoyle could you please solve the conflicts, I'll merge 🙏

Closes [hotwired#638][]

Recent changes to integrate with morphing have altered the mental model
for some Turbo custom elements, including the
`<turbo-cable-stream-source>` element.

Custom Elements' `connectedCallback()` and `disconnectedCallback()`
(along with Stimulus' `connect()` and `disconnect()`) improved upon
invoking code immediately, or listening for `DOMContentLoaded` events.

There are similar improvements to be made to integrate with morphing.
First, [observe attribute changes][] by declaring their own `static
observedAttributes` properties along with
`attributeChangedCallback(name, oldValue, newValue)` callbacks. Those
callbacks execute the same initialization code as their current
`connectedCallback()` and `disconnectedCallback()` methods.

That'll help resolve this issue. In addition to those changes, it's
important to emphasize this pattern for consumer applications moving
forward. JavaScript code (whether Stimulus controller or otherwise)
should be implemented in a way that' resilient to both asynchronous
connection and disconnection *as well as* asynchronous modification of
attributes.

[hotwired#638]: hotwired#638
[observe attribute changes]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Components/Using_custom_elements#responding_to_attribute_changes
@jorgemanrubia jorgemanrubia merged commit 034c632 into hotwired:main Sep 17, 2024
15 checks passed
@seanpdoyle seanpdoyle deleted the issue-638 branch September 17, 2024 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

idiomorph merges attributes on <turbo-cable-stream-source> and connectedCallback() doesn't run
3 participants