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

fix(runtime): always call component lifecycle hooks #6167

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

johnjenkins
Copy link
Contributor

@johnjenkins johnjenkins commented Feb 19, 2025

What is the current behavior?

As per the linked issues, Stencil makes class components less easy to reason and not behave like the dynamic JS classes they are. Adding and extending class behaviour dynamically makes DX much better.

GitHub Issue Number:

#6165

What is the new behavior?

Removed the static flags / checks around lifecycle hook use - they are always called now.

Any argument around whether to always run lifecycle hooks hinges on any potential size savings won by Stencil's current optimisations.

The following is the result from a single, simple component without any lifecycle hooks (remember if any single component uses a lifecycle hook, any difference is diminished).

Before latest stencil:

dist-custom-elements core:
+--------------------------------------------------------------+
| Size | 12.71 KiB |
|--------------------------------------------------------------|
| Gzipped | 5.27 KiB |
|--------------------------------------------------------------|

dist browser core:
+--------------------------------------------------------------+
| Size | 14.97 KiB |
|--------------------------------------------------------------|
| Gzipped | 6.2 KiB |
|--------------------------------------------------------------|

dist esm core (no-minification):
+--------------------------------------------------------------+
| Size | 39.54 KiB |
|--------------------------------------------------------------|
| Gzipped | 9.99 KiB |
|--------------------------------------------------------------|

After (this branch / consistent lifecycle hooks):

dist-custom-elements core:
+--------------------------------------------------------------+
| Size | 12.92 KiB |
|--------------------------------------------------------------|
| Gzipped | 5.34 KiB |
|--------------------------------------------------------------|

dist browser core:
+--------------------------------------------------------------+
| Size | 15.38 KiB |
|--------------------------------------------------------------|
| Gzipped | 6.34 KiB |
|--------------------------------------------------------------|

dist esm core (no minification):
+--------------------------------------------------------------+
| Size | 40.68 KiB |
|--------------------------------------------------------------|
| Gzipped | 10.19 KiB |
|--------------------------------------------------------------|

^ in these, 'worst case' scenarios, stripping away the ability to dynamically use lifecycle hooks saves 0.07-.2 kb

Documentation

Does this introduce a breaking change?

  • Yes
  • No

Testing

New wdio tests

Other information

@johnjenkins johnjenkins marked this pull request as ready for review February 21, 2025 00:55
@johnjenkins johnjenkins requested a review from a team as a code owner February 21, 2025 00:55
@johnjenkins johnjenkins changed the title feat(runtime): always call component lifecycle hooks fix(runtime): always call component lifecycle hooks Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants