Skip to content

Add lifecycle callbacks for components.#436

Merged
hayleigh-dot-dev merged 3 commits intomainfrom
hayleigh/component-lifecycle
Feb 15, 2026
Merged

Add lifecycle callbacks for components.#436
hayleigh-dot-dev merged 3 commits intomainfrom
hayleigh/component-lifecycle

Conversation

@hayleigh-dot-dev
Copy link
Collaborator

This PR introduces three new component options, two being usable in both server component and client components, and one being exclusively for client components:

  • component.on_connect
  • component.on_adopt
  • component.on_disconnect

Each option sets a message that should be dispatched to the runtime at different points in the component's lifecycle. For client components these three options correspond to the custom element lifecycle callbacks connectedCallback, adoptedCallback, and disconnectedCallback.

For server components on_connect and on_disconnect can be used to be notified when a new connection is registered or deregistered through server_component.register_subject/callback etc.


These lifecycle messages provide important hooks for components to launch effects or perform important cleanup, and addresses #320 without the need for explicit effect cleanup capabilities or a fixed shutdown/stop event.

@hayleigh-dot-dev hayleigh-dot-dev marked this pull request as ready for review February 15, 2026 22:39
Copy link
Contributor

@yoshi-monster yoshi-monster left a comment

Choose a reason for hiding this comment

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

LGTM <3

@hayleigh-dot-dev hayleigh-dot-dev linked an issue Feb 15, 2026 that may be closed by this pull request
@hayleigh-dot-dev hayleigh-dot-dev merged commit 8f788ae into main Feb 15, 2026
1 check passed
@hayleigh-dot-dev hayleigh-dot-dev deleted the hayleigh/component-lifecycle branch February 15, 2026 23:37
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.

Running cleanup function for components

2 participants