Skip to content

bug: v5 componentShouldUpdate gets the wrong oldVal when a prop that was undefined or null is set twice #7042

Done
porsche-design-system/porsche-design-system
#4875

Description

@henrijoss

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 content

componentShouldUpdate 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

  1. Clone https://github.com/henrijoss/stencil-v5-repros and run npm install
  2. npm start --workspace=changes-old-value and open http://localhost:3335
  3. Click set config once: the first element renders {"label":"a"}
  4. Click set config twice, to two objects with the same content: the second element keeps rendering undefined, and the log shows oldVal: {"label":"b"}, newVal: {"label":"b"}, update: false

Code Reproduction URL

https://github.com/henrijoss/stencil-v5-repros/tree/main/changes-old-value

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

  1. johnjenkins commented on Nov 25, 2026

    @johnjenkins
    Contributor

    TYSM for trying out v5. This was fixed in 5.0.0-rc.11 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions