fix(runtime): always call component lifecycle hooks #6167
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?
Testing
New wdio tests
Other information