You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: ssr + zoneless + defer + inputs fails to resolve input data on first render #61038
Which @angular/* package(s) are the source of the bug?
I don't know
Is this a regression?
Yes
Description
When using incremental hydration with zoneless change detection, the prerendered html (or returned from SSR) is incorrect.
Template is incomplete in the generated HTML for components inside @defer(hydrate never).
This behavior seems to be the same no matter the hydrate trigger.
When using zone change detection, the prerendering works fine.
Please provide a link to a minimal reproduction of the bug
The regression starts with Angular 19.0.5 and seems to have been fixed in 20.0.0-next.4
I'm not sure which commit in the 20.0.0-next.4 release fixes it but it would be great to have it backported to the release 19 even though zoneless is still experimental in this version.
This actually is not just a pre-rendering issue. It also impacts SSR overall. Zoneless is currently experimental and we're still working on stabilizing it specifically with SSR cases. There's a callout in the Zoneless guide mentioning feature gaps with SSR around timing of serialization and it happening too early. This is the exact thing happening.
The interesting thing is that the incremental hydration behavior is working just fine and as intended. The issue is actually the signal input. Serialization seems to happen before that signal input task is resolved. The fix takes care of it with rendering after a macrotask. angular/angular-cli@6bd7b9b
Given that this is experimental still, I don't think we'd backport it, but it probably warrants more investigation as we need to ensure we have the right fix in place for this.
changed the title [-]Prerendering is broken when using incremental hydration with zoneless[/-][+]Bug: Signal input timing is not working across defer hydrate boundaries[/+]on Apr 28, 2025
changed the title [-]Bug: Signal input timing is not working across defer hydrate boundaries[/-][+]Bug: ssr + zoneless + defer + inputs fails to resolve input data on first render[/+]on Apr 28, 2025
So it's actually unrelated to signal inputs too. Any type of input post 19.0.4 has this problem, but only on the very very first time the page is rendered. If you hard refresh the page after that, it renders fine. So there's something up with that first render post app-build, which doesn't appear to be on the framework side. We haven't been able to replicate this in a test environment at all either. I think this may be a CLI issue. I'll move this ticket over to that repo for further diagnosis.
However, moving the removal into a .finally() block seems to resolve this race condition:
returntDetails.loadingPromise.finally(()=>{// Loading is completed, we no longer need the loading Promise// and the pending task should also be removed.tDetails.loadingPromise=null;pendingTasks.remove(taskId);});
Activity
thePunderWoman commentedon Apr 28, 2025
I was able to see the same thing with the repro. I'll look further into it to see what's going on here.
thePunderWoman commentedon Apr 28, 2025
This actually is not just a pre-rendering issue. It also impacts SSR overall. Zoneless is currently experimental and we're still working on stabilizing it specifically with SSR cases. There's a callout in the Zoneless guide mentioning feature gaps with SSR around timing of serialization and it happening too early. This is the exact thing happening.
The interesting thing is that the incremental hydration behavior is working just fine and as intended. The issue is actually the signal input. Serialization seems to happen before that signal input task is resolved. The fix takes care of it with rendering after a macrotask. angular/angular-cli@6bd7b9b
Given that this is experimental still, I don't think we'd backport it, but it probably warrants more investigation as we need to ensure we have the right fix in place for this.
[-]Prerendering is broken when using incremental hydration with zoneless[/-][+]Bug: Signal input timing is not working across defer hydrate boundaries[/+][-]Bug: Signal input timing is not working across defer hydrate boundaries[/-][+]Bug: ssr + zoneless + defer + inputs fails to resolve input data on first render[/+]thePunderWoman commentedon Apr 28, 2025
So it's actually unrelated to signal inputs too. Any type of input post 19.0.4 has this problem, but only on the very very first time the page is rendered. If you hard refresh the page after that, it renders fine. So there's something up with that first render post app-build, which doesn't appear to be on the framework side. We haven't been able to replicate this in a test environment at all either. I think this may be a CLI issue. I'll move this ticket over to that repo for further diagnosis.
jsaguet commentedon Apr 28, 2025
Thank you for the investigation @thePunderWoman
Thanks to the details you shared, I've managed to workaround the issue with the following code in the root component:
alan-agius4 commentedon Apr 29, 2025
I had a deeper look at this and I switched the code to directly call the "low-level" rendering APIs:
Even with version
19.0.4, the content still isn’t rendered correctly. Here's the resulting HTML:I added some basic
console.logstatements and noticed from the debug logs that the application is being marked as stable prematurely:Looking into the
PendingTasksclass https://github.com/angular/angular/blob/main/packages/core/src/pending_tasks.ts#L54, there doesn't appear to be logic to handle scenarios where the app becomes stable between microtask creations. Previously, inNgZone, stabilization was deferred to a microtaskangular/packages/core/src/zone/ng_zone.ts
Line 566 in 6c8faaa
While checking how pending task removal is handled for
@deferblocks, I noticed the task is removed before the microtask completesangular/packages/core/src/defer/triggering.ts
Line 250 in 2445946
.finally()block seems to resolve this race condition:10 remaining items
fix(core): properly handle app stabilization with defer blocks
fix(core): properly handle app stabilization with defer blocks (#61056)
fix(core): properly handle app stabilization with defer blocks (#61040)
fix(core): properly handle app stabilization with defer blocks (#61040)
angular-automatic-lock-bot commentedon May 31, 2025
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.