Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Results of investigation into make
zonewrap
zoneless-compatibleIt seems like the current
zonewrap
API is not really compatible with Angular's SSR in general (either with or without zones). The problem is that at its core it relies on saving off injected services onto a global variable. However in SSR, each request has its own separate instances of these services, meaning that zonewrap is consulting the wrong instance of these services for every request other than the first one.This seems to have gone unnoticed because zones kind of naturally keep everything unstable anyways. Ironically it seems that the only reason this works at all in zone applications with SSR is because after the first request, zonewrap inadvertently runs everything outside of the
NgZone
(by running it in the wrong instance ofNgZone
). I've noticed that with zones enabled, the first request seems to hang indefinitely due to the zone never stabilizing. It is only on subsequent requests (where zonewrap is running things in the wrong zone) that the application stabilizes and allows the server to respond.In attempting to implement zoneless, the opposite happened where I was able to add the appropriate pending tasks to keep the application unstable for the first request, but on subsequent requests zonewrap had the wrong instance of
ExperimentalPendingTasks
and was therefore unable to stop the application from immediately becoming stable and returning a blank page.Unfortunately I don't think there's an easy fix for this, other than to redesign the API to be compatible with the fact that each request is running a separate instance of the app. (i.e. we can't just wrap the function globally on import, it needs to somehow account for the context of the current application).
Using the APIs in zoneless apps with manual task management
The good news is that as of f283d1a usages of all Zones APIs that are strictly incompatible with zoneless applications have been removed. This means that the library can now be used in zoneless apps, though users won't be able to rely on auto-magic wrapping behavior, and will have to instead manage tasks themselves to keep the application unstable until the appropriate time during SSR.
Examples from the samples/advanced app:
To make this work in zoneless, it can be modified to manually keep a task open until a value arrives: