Skip to content

Conversation

@ricardo-devis-agullo
Copy link
Collaborator

@ricardo-devis-agullo ricardo-devis-agullo commented Jul 11, 2025

This change introduces support for Custom Elements, allowing oc-component elements to automatically manage their own lifecycle, including rendering and unmounting.

Previous Behavior

Previously, oc-component tags were inert placeholders. Developers had to manually scan the DOM and call oc.render or oc.renderNestedComponent to render them if components we added after the client loaded. There was no built-in mechanism for cleanup or unmounting when a component was removed from the DOM.

New Behavior

This PR defines a custom element for the oc-component tag.
Automatic Rendering: When an with the manage-lifecycle attribute is added to the DOM, its connectedCallback is triggered, which automatically calls oc.renderNestedComponent on itself.
Automatic Unmounting: If the component was rendered and has an unmount function (templates will start adding the unmount function on the element), its disconnectedCallback will execute the unmount function when the element is removed from the DOM.
This feature is opt-in and can be enabled globally via the manageLifecycles configuration or on a per-component basis by adding the manage-lifecycle attribute. This automates the component lifecycle, simplifying the integration of components in modern front-end frameworks.

@ricardo-devis-agullo ricardo-devis-agullo merged commit 7573776 into master Jul 11, 2025
3 checks passed
@ricardo-devis-agullo ricardo-devis-agullo deleted the custom-element branch July 11, 2025 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants