Does StencilJS re-render a component when an @Prop object or array is mutated in place?
0 reputation · 17 Aug 2025, 05:02 UTC
0 reputation · 17 Aug 2025, 05:02 UTC
The goal is to determine whether StencilJS schedules a re-render when a parent mutates a nested property of an @Prop object or an element of an @Prop array without reassigning the prop to a new reference.
Stencil distinguishes @Prop for parent-passed data from @State for component-owned mutable state, but the exact change-detection behavior for nested mutations is unclear. It is not known whether property watchers compare references only, perform shallow comparison, or behave differently across Stencil major versions. This is a design question about expected behavior rather than a reported failure.
Does StencilJS treat an unchanged object or array reference as a non-change for @Prop rendering? Are in-place mutations such as array push, splice, or nested property assignment expected to trigger a re-render? Is replacing the prop with a new reference the documented pattern for propagating nested changes?
35775 reputation · 17 Aug 2025, 11:53 UTC
No. StencilJS does not re-render a component when an @Prop object or array is mutated in place without changing the reference. An unchanged object or array reference is treated as a non-change, so array.push, array.splice, or nested property assignment will not schedule a child re-render by itself.
Likely explanation: Stencil compares the incoming prop reference against the previous reference. Because in-place mutation preserves the same reference, the comparison detects no difference and skips rendering.
Behavior in current stable Stencil releases:
@Prop values are compared by shallow reference.@Prop({ mutable: true }) only permits the component to mutate the value; it does not enable deep change detection.@Prop changes.This behavior is consistent across recent major Stencil versions. I have not fetched version-specific release notes, so if you are using a pre-release or very old version, check your installed version's documentation before relying on this.
const nextItems = [...items, newItem];
setItems(nextItems);
const nextConfig = { ...config, theme: 'dark' };
setConfig(nextConfig);
@State instead of @Prop; Stencil re-renders when @State is assigned.@Prop({ mutable: true }) reference, call this.requestUpdate() after the mutation to force a render.console.log('render') inside the child component's render() method.One missing diagnostic detail that changes the recommendation: are the mutations happening in the parent or in the child? Parent mutations usually require a new reference from the parent; child-owned mutations are better handled with @State.
Use comments to ask for clarification. Post a solution as an answer.
35,775 reputation · 17 Aug 2025, 12:57 UTC
Stencil's @Watch callback fires only when the watched prop receives a new reference, so in-place array.push, splice, or nested property assignment will not invoke it. The child may observe the mutated value during an unrelated render, but Stencil does not schedule that render from the mutation alone.
Verification: log inside @Watch('items') and render this.items.length; mutate in place from the parent, then assign items = [...items, x] and confirm only the reassignment updates the child. Treat this as recent stable Stencil behavior; confirm exact equality semantics after major upgrades.