Repository navigation
Description
Prerequisites
- I have read the Contributing Guidelines.
- I agree to follow the Code of Conduct.
- I have searched for existing issues that already report this problem, without success.
Stencil Version
=4.36.0
Current Behavior
Since Stencil 4.36.0, an initial prop value can be undetected on a dynamically set Angular component.
For example, I use the following code to emulate the dynamic first prop value:
<my-component [first]="'issue'"></my-component>I have the following logs:
@Prop() first!: string;
@Watch('first')
firstChanged() {
console.log('CHANGE', this.first);
}
connectedCallback() {
console.log('connectedCallback', this.first);
}
componentWillLoad() {
console.log('componentWillLoad', this.first);
}
componentDidLoad() {
console.log('componentDidLoad', this.first);
}
render() {
console.log('render', this.first);
...
}In runtime:
The value comes only at the second rendering, the prop has not been initialized before componentWillLoad and the Watch() method has not been called.
The prop update seems to be undetected but fire a rerender.
Note: I reproduced this issue only when the component is on a child routing page and when the app is loaded on this page (See reproduction steps).
Expected Behavior
The prop is available on componentWillLoad OR the Watch() method is called.
System Info
System: node 20.18.3
Platform: darwin (24.6.0)
CPU Model: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz (12 cpus)
Compiler: /stencil-demo/packages/elements/node_modules/@stencil/core/compiler/stencil.js
Build: 1752598220
Stencil: 4.36.0 🎊
TypeScript: 5.5.4
Rollup: 4.34.9
Parse5: 7.2.1
jQuery: 4.0.0-pre
Terser: 5.37.0Steps to Reproduce
- Clone the
angular-issuebranch from https://github.com/mamillastre/stencil-demo/tree/angular-issue - In the root folder
npm inpm run angular- Open the running Angular app
- Open the dev console to see the logs
- Click on the "TEST" link
- Here the
Watch()method is called
- Refresh the page (on the test page)
- The
Watch()method is not called
If the stencil component is in the Angular root component (projects/angular-app/src/app/app.component.html), the prop is initialized on componentWillLoad.
Code Reproduction URL
Additional Information
The issue seems to come from Stencil v3.36.0.
Workaround: stay on the v3.35.3
I didn't try to reproduce on Vue or React.
Activity
johnjenkins commentedon Aug 22, 2025
@danielleroux I'm pretty sure this is due to #6331 < do you have any insights?
(@mamillastre I believe this stems from Stencil components now rendering much faster - perhaps Angular sets properties too slowly)
danielleroux commentedon Aug 22, 2025
@johnjenkins cannot reproduce the issue on our setup:
Also tested with v4.36.2 and angular 20
@mamillastre Maybe you can try to reproduce it based on the output-target repo.
ben-hamida commentedon Aug 22, 2025
We're having a similar issue where in one particular place in our app
componentWillLoadis called before the angular input has been set. We have other places with almost identical code using the same stencil component where it doesn't happen.mamillastre commentedon Aug 25, 2025
It can be the issue. But in this case, the
@Watch()method should be called when the Angular value is initialized.Do you reproduce on my repo ? https://github.com/mamillastre/stencil-demo/tree/angular-issue
danielleroux commentedon Aug 25, 2025
No there is to much stuff in there, I do not install any repo without knowing which dependencies in there. I would suggest use stencil/output-target fork to make a repo to show the issue.
johnjenkins commentedon Aug 25, 2025
It does seem to be an issue; Ionic users have also reported it: ionic-team/ionic-framework#30613
mamillastre commentedon Aug 25, 2025
@danielleroux, I forked the
output-targetrepo and reproduced this issue in theissue-angular-prop-initbranch: https://github.com/mamillastre/output-targets/tree/issue-angular-prop-initHere is the commit detail: mamillastre/output-targets@358112c
danielleroux commentedon Aug 25, 2025
@johnjenkins Do we have any angular dev's here who have some insights into change detection etc? The regular task queue uses requestAnimationFrame which works like desired.
The issue only happens with queueMicrotask. Same as providing
taskQueue: 'immediate',inside the stencil.config.ts even without the changes of the queueMicrotask.//Edit
Maybe a possible fix would be to put the lifecycle calls back into the event loop of the repaint frames.
//Edit 2
It looks promising If I put the lifecycle calls back into the repaint loop, but keep the initial rendering inside the microtask-loop.
johnjenkins commentedon Sep 5, 2025
@gratzl-dev maybe?
danielleroux commentedon Sep 5, 2025
I dont have a solution right now. My current assumption is:
Actual issue:

valueA = undefined==> render dependent lifecycle functions will be execute before angular performs the binding
Putting lifecycle calls into requestAnimationFrame will not solve the issue:

==> Problem
componentWillRenderandcomponentWillLoadhas the following featureA promise can be returned, that can be used to wait for the upcoming render.This does not work for the initial rendering attempt.Solutions what I have in mind is, but not sure about:
@Component-decorator or event a runtime flag. Stencil developers can decide If they need the "faster-initial-rendering" or "controlled-rendering" behaviour.johnjenkins commentedon Sep 5, 2025
@danielleroux did you try adjusting the taskQueue option before your PR?
It is (or was?) async, perhaps you just wanted
immediateand we can revert? idk - haven't looked much into itjohnjenkins commentedon Sep 5, 2025
@danielleroux / @mamillastre - I've just noticed this hidden in Stencil's docs too ...
sounds relevant ... can someone experiment?
danielleroux commentedon Sep 8, 2025
I dont think so because applying updates makes totally sense to do that only depending on the refresh rate and the initial render before the browser frame is shown.
If you look at the
if-branch of theinitializeNextTickthere are two closed angular tickets.7 remaining items
johnjenkins commentedon Sep 11, 2025
awesome - thanks for the investigation @kristilw
mamillastre commentedon Sep 23, 2025
Hi @johnjenkins, the commit has been reverted on 4.37.1
Does fix issue is still fixed ?
johnjenkins commentedon Sep 23, 2025
yep @mamillastre - re-opened
johnjenkins commentedon Sep 23, 2025
however - this particular issue / repro is fixed or rather has consistent workarounds now.
per component:
or globally, via
extras.initializeNextTickmamillastre commentedon Sep 23, 2025
Even with the workarounds, I think that this is still a breaking change between the 4.35 and 4.36 versions.
The per component solution does not feel right since we have to remember to add this piece of code. The issue happens in particular cases, so it's easy to forget.
I am not familiar with the initializeNextTick extras configuration. I do not find it in the documentation. What is the impact of using this option?
You quote this documentation that concerns me: settings their initial state, leading to double renders and unnecessary event dispatches.
Does the Ionic framework will not be impacted by this issue?
Thank you
johnjenkins commentedon Sep 23, 2025
The change between those versions is Stencil got much faster in initialising it's components - esp in the
dist-custom-elementsoutput - due to @danielleroux work.Angular has an issue in that it attaches your components to the DOM then binds it's dynamic properties (
e.g. yourElemen.prop1 = boundProp) < Stencil has already done it's first render - this is the reason for this new behaviour.There is no documentation for it (I guess as it's a hack for a niche, Angular-only buggy behaviour) - here's the declaration description in context - https://github.com/stenciljs/core/blob/main/src/declarations/stencil-public-compiler.ts#L369
Turning it to
truewill essentially recreate the old behaviour; throttling a components' initial render so Angular has had time to attach it's bound property. No more 'double renders' / watchers firing when the initial property is added.This new behaviour won't be rolled back as I think the best default is for components to render ASAP.
We will be looking at watcher attaching though to make it more consistent.
Hope that all makes sense!
mamillastre commentedon Sep 23, 2025
Thank you very much @johnjenkins for the explanations.
I will use the workarounds for now, waiting for the watcher fix 👍
pfteter commentedon Oct 20, 2025
preactswitched back torequestAnimationFramefromqueueMicrotaskbecause of stability issues, there is a whole section in angular core about it why they still userequestAnimationFrame.Did you try to switch from queueMicrotask back to requestAnimationFrame in stencil to see if the issue still happens ?
pfteter commentedon Oct 20, 2025
https://github.com/angular/angular/blob/c60ab336c9e862f6fc3b16cab4a8b2dd910712cf/packages/core/src/util/callback_scheduler.ts#L13
what angular is saying about it:
johnjenkins commentedon Oct 20, 2025
Experimentation / PRs most welcome!
RAF is still used for the majority of updating (if
taskQueueis not set toimmediate);queueMicrotaskis only used for the first, initial render.Cliffback commentedon Nov 20, 2025
setting
extras.initializeNextTickdidn't work for us, while wrapping in a RAF promise did the job. Would have preferred to use theinitializeNextTickoption thoughCliffback commentedon Nov 24, 2025
For tests that expects to throw, the suggested solution didn't work, so had to add a reject.
and change the test from this:
to this:
Also wrote a TS AST Transformer to automate this. Hope it can save someone else time.
It can be run with
find path/to/look/for/components -name '*.tsx' | xargs -n 1 npx tsx path/to/script/transform-component WillLoad.tstransform-componentWillLoad.ts