feat: v5 signals#6733
Open
johnjenkins wants to merge 6 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 new behavior?
Signals land in Stencil v5 as a fully opt-in, zero-migration feature. Existing components work exactly as before - nothing breaks, and new feature usage can be added incrementally.
Enabling
One flag in
stencil.config.ts:@Propand@Statebecome signal-backed, all existing decorators, lifecycle hooks, and@Watchcallbacks continue to work and all attributes / text-content within your JSX (that's signal backed) will receive fine-grained updates; not full component re-renders.All used features are fully tree-shaken with the total cost being no more than ~2kb Gzipped
Computed values and reactive side effects
Import from the new
@stencil/core/signalssubpath:@Effect()auto-tracks dependencies, runs when they change, and cleans itself up on disconnect.computed()is lazy and cached - it only recalculates when its dependencies change.Shared state across a component library
Create a signal outside any component:
Use it in any number of components - they all update in-sync without events or context:
Write to the signal anywhere and every subscriber updates immediately.
Subscribing to a component's props from outside
getSignallets you observe any@Propreactively from outside the component, typed and null-safe:Vanilla usage / in environments where you cannot import from
@stencil/core, the same signals are accessible via a well-known symbol:vdom bypass
When a signal is used directly as a JSX child or attribute value, Stencil skips the vdom diff entirely and patches the DOM node in place:
Documentation
Does this introduce a breaking change?
Testing
Other information