Skip to content

bug: v5 forceUpdate() is lost when componentShouldUpdate turns the queued update down #7039

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

Description

@henrijoss

Stencil Version

5.0.0-rc.9

Current Behavior

A forceUpdate() does not render when a prop or state gets a value in the same cycle for which componentShouldUpdate returns false. The order doesn't matter:

  • Assign the value, then forceUpdate(): forceUpdate() does nothing, because an update is queued already, and that queued update is dropped by componentShouldUpdate.
  • forceUpdate(), then assign the value: the update forceUpdate() queued is dropped by componentShouldUpdate, because a change is queued with it.

Expected Behavior

forceUpdate() always results in a render, as documented: "Schedules a new render of the given instance or element even if no state changed." componentShouldUpdate should not be able to turn a forced update down.

This is what 4.45.1 does with the same component: the render count goes 1 → 2 → 3 → 4 for the three buttons.

System Info

      System: node 22.21.0
    Platform: darwin (27.0.0)
   CPU Model: Apple M2 Pro (12 cpus)
     Stencil: 5.0.0-rc.9 🏐
  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=force-update and open http://localhost:3334
  3. Click forceUpdate(): the render count goes from 1 to 2
  4. Click assign an equal value, then forceUpdate(): the render count stays at 2
  5. Click forceUpdate(), then assign an equal value: the render count stays at 2

Code Reproduction URL

https://github.com/henrijoss/stencil-v5-repros/tree/main/force-update

Additional Information

forceUpdate() only schedules when nothing is queued, and leaves no trace that the update is forced (packages/core/src/runtime/update-component.ts):

if (isConnected && (hostRef.$flags$ & (HOST_FLAGS.hasRendered | HOST_FLAGS.isQueuedForUpdate)) === HOST_FLAGS.hasRendered) {
  scheduleUpdate(hostRef, false);
}

dispatchHooks() then calls componentShouldUpdate with the queued changes and returns when it gives false.

In Stencil 4 componentShouldUpdate was called in setValue(). A false there only prevented scheduling a new update, it didn't cancel one that was queued, so a forced update always rendered. The change came with the batched componentShouldUpdate (#6783).

I ran into this in a component that forces an update from an event listener while an update that changed nothing was queued. It only failed in WebKit on Linux, where the queue is flushed late enough for the two to meet.

Remembering that the update is forced, and skipping the early return for it, fixes the reproduction (1 → 2 → 3 → 4):

// forceUpdate()
if (isConnected && hostRef.$flags$ & HOST_FLAGS.hasRendered) {
  hostRef.$isUpdateForced$ = true;
  if (!(hostRef.$flags$ & HOST_FLAGS.isQueuedForUpdate)) {
    scheduleUpdate(hostRef, false);
  }
}

// dispatchHooks(), update branch
const isUpdateForced = hostRef.$isUpdateForced$;
hostRef.$isUpdateForced$ = false;
// …
if (safeCall(instance, 'componentShouldUpdate', changes, elm) === false && !isUpdateForced) {

The code is the same in 5.0.0-rc.10; I only ran rc.9 (and first saw this with rc.1).

I found no existing issue for this.

Related: #7038 has the same root, the place where componentShouldUpdate is called.

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