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
Server-side running code throws an error if the provideZoneChangeDetection is used #50801
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: serverIssues related to server-side renderingstate: has PR
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
The code which is running in the Node.js throws an error Cannot read properties of undefined (reading 'call') when the provideZoneChangeDetection is called in ApplicationConfig.providers.
This happens because the NgZone delays change detection to coalesce event tasks (happened within the same animation frame) or multiple ngZone.run calls in a row. The change detection is delayed through the native requestAnimationFrame which isn't available in the Node.js.
@JiaLiPassion@alan-agius4 what do you think about using setTimeout as a replacement for requestAnimationFrame for Node.js environment in the mentioned scenario? I think we can also consider using queueMicrotask function.
I don't think there should be any task scheduling on the Node.js side since the current implementation (with no task scheduling) has existed until now. First of all, there're no event tasks on the Node.js side until we dispatch them manually through el.dispatchEvent, compared to how event tasks are invoked in the browser (they're "classically" invoked by browsers as a reaction to user actions or also dispatched manually). This means there might be only multiple ngZone.run calls in a row which may be coalesced. Bug again, there's no reason to coalesce those calls on the Node.js side since there will be no "frame drop". Having any task scheduling on the server side may also affect the time the response comes back.
As I mentioned in one of my comments in the linked PR, we may keep provideZoneChangeDetection compatible with both environments but provide explicit zone options which default to false when the platform is server:
@arturovt thanks for the comment, I do agree that the mentioned change might be a possible solution. I think what'd be great to preserve though is the consistency of execution paths on the client and on the server, so that operations happen in the same order (otherwise it may lead to some subtle bugs in the code).
@arturovt thanks again for reporting the issue. We had a discussion with the team and the decision is to use setTimeout on the server when no requestAnimationFrame is available, as you proposed. Please let us know if you might be interested in creating a PR with the fix. Thank you.
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: serverIssues related to server-side renderingstate: has PR
Activity
AndrewKushnir commentedon Jun 21, 2023
@JiaLiPassion @alan-agius4 what do you think about using
setTimeoutas a replacement forrequestAnimationFramefor Node.js environment in the mentioned scenario? I think we can also consider usingqueueMicrotaskfunction.arturovt commentedon Jun 21, 2023
I don't think there should be any task scheduling on the Node.js side since the current implementation (with no task scheduling) has existed until now. First of all, there're no event tasks on the Node.js side until we dispatch them manually through
el.dispatchEvent, compared to how event tasks are invoked in the browser (they're "classically" invoked by browsers as a reaction to user actions or also dispatched manually). This means there might be only multiplengZone.runcalls in a row which may be coalesced. Bug again, there's no reason to coalesce those calls on the Node.js side since there will be no "frame drop". Having any task scheduling on the server side may also affect the time the response comes back.As I mentioned in one of my comments in the linked PR, we may keep
provideZoneChangeDetectioncompatible with both environments but provide explicit zone options which default tofalsewhen the platform is server:AndrewKushnir commentedon Jun 21, 2023
@arturovt thanks for the comment, I do agree that the mentioned change might be a possible solution. I think what'd be great to preserve though is the consistency of execution paths on the client and on the server, so that operations happen in the same order (otherwise it may lead to some subtle bugs in the code).
AndrewKushnir commentedon Jun 22, 2023
@arturovt thanks again for reporting the issue. We had a discussion with the team and the decision is to use
setTimeouton the server when norequestAnimationFrameis available, as you proposed. Please let us know if you might be interested in creating a PR with the fix. Thank you.arturovt commentedon Jun 22, 2023
Sure, I’ll make a PR if you don’t mind today.
AndrewKushnir commentedon Jun 22, 2023
Thank you 👍
angular-automatic-lock-bot commentedon Jul 31, 2023
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.