Repository navigation
Description
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 bycomponentShouldUpdate. forceUpdate(), then assign the value: the updateforceUpdate()queued is dropped bycomponentShouldUpdate, 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
- Clone https://github.com/henrijoss/stencil-v5-repros and run
npm install npm start --workspace=force-updateand open http://localhost:3334- Click
forceUpdate(): the render count goes from 1 to 2 - Click
assign an equal value, then forceUpdate(): the render count stays at 2 - Click
forceUpdate(), then assign an equal value: the render count stays at 2
Code Reproduction URL
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
johnjenkins commentedon Nov 25, 2026
TYSM for trying out v5. This was fixed in 5.0.0-rc.11 🥳