Repository navigation
Description
Stencil Version
5.0.0-rc.10
Current Behavior
componentShouldUpdate gets the wrong oldVal for a prop or state that was undefined or null at the last render and is assigned more than once before the next render. oldVal is then the value of the previous assignment, not the value that was rendered.
A component that compares newVal with oldVal to skip renders for equal values never renders the new value:
element.config = { label: 'b' }; // rendered value is undefined
element.config = { label: 'b' }; // a new object with the same contentcomponentShouldUpdate is called with { config: { newVal: { label: 'b' }, oldVal: { label: 'b' } } }, returns false, and the element keeps rendering undefined.
It works when the rendered value is anything but undefined or null.
Expected Behavior
oldVal is the value at the last render. ComponentInterface documents changes as "every property that changed since the last render", and that is what oldVal holds whenever the rendered value is not undefined or null. In the example it should be undefined, so the component returns true and renders { label: 'b' }.
This is what 4.45.1 does with the same component: componentShouldUpdate is called for the first assignment with oldVal: undefined, and the element renders.
System Info
System: node 24.15.0
Platform: darwin (27.0.0)
CPU Model: Apple M2 Pro (12 cpus)
Stencil: 5.0.0-rc.10 🚅
TypeScript: 6.0.3
Rolldown: 1.3.3
Terser: 5.51.4
Browsers: Chromium and WebKit (Playwright 1.63)Steps to Reproduce
- Clone https://github.com/henrijoss/stencil-v5-repros and run
npm install npm start --workspace=changes-old-valueand open http://localhost:3335- Click
set config once: the first element renders{"label":"a"} - Click
set config twice, to two objects with the same content: the second element keeps renderingundefined, and the log showsoldVal: {"label":"b"}, newVal: {"label":"b"}, update: false
Code Reproduction URL
Additional Information
The queued change keeps the first oldVal with ??, which also skips an oldVal that is undefined or null (src/runtime/set-value.ts, and the same in src/runtime/signals.ts with prevScheduleVal):
changes[propName] = {
newVal,
oldVal: changes[propName]?.oldVal ?? oldVal,
};Checking for the entry instead of its value fixes the reproduction:
oldVal: propName in changes ? changes[propName].oldVal : oldVal,I ran into this with a wrapper that assigns an object prop on every render of the application: two renders within one frame, with the prop going from undefined to an object, left the component without the prop.
I found no existing issue for this.
Related: #7038 and #7039 are also about the batched componentShouldUpdate (#6783).
Activity
fix(components): render a prop that is set twice to equal objects | h…
johnjenkins commentedon Nov 25, 2026
TYSM for trying out v5. This was fixed in 5.0.0-rc.11 🥳