Zoneless SSR is not supported
Describe the bug
Current implementation doesn't support zoneless ssr app. It lacks Pending Tasks and thanks to using angular's http client with the apollo http link, stays unstable until the response arrives, but nothing then prevents app from becoming stable between cache updates and re-rendering of the components.
To Reproduce
Minimal zoneless Angular SSR app that uses apollo-angular and in memory cache.
Expected behavior
Angular app is kept unstable for whole Apollo processing - request, cache updates and return of data to consumer
Environment:
dependencies:
@angular/core 19.0.0
@apollo/client 3.10.4
apollo-angular 8.0.0
graphql 16.9.0
devDependencies:
@angular/cli 19.0.0
typescript 5.6.3
Additional context
I overrode locally all the Apollo operations, by running them as pending tasks, example:
public query<T, V extends OperationVariables = EmptyObject>(
options: QueryOptions<V, T>,
): Observable<ApolloQueryResult<T>> {
return fromPromise<ApolloQueryResult<T>>(() => this.pendingTasks.run(() => this.ensureClient().query<T, V>({ ...options })));
}
Naturally watchQuery was bigger challenge, so I did following patch on the QueryRef level:
constructor(
private readonly obsQuery: ObservableQuery<T, V>,
ngZone: NgZone,
pendingTasks: PendingTasks,
options: WatchQueryOptions<V, T>,
) {
super(obsQuery, ngZone, options);
const task = pendingTasks.add();
const wrapped: Observable<ApolloQueryResult<T>> = from(fixObservable(this.obsQuery)).pipe(
tap({
next: result => {
if (result.loading === false && !result.partial) {
task();
}
},
error: () => {
task();
}
}),
finalize(() => task())
);
this.valueChanges = options.useInitialLoading
? wrapped.pipe(useInitialLoading(this.obsQuery))
: wrapped;
this.queryId = this.obsQuery.queryId;
}
Would be great if we can get this fixed as zoneless Angular seems to be the feature.
I'd merge a PR that fixes this, if it is covered by unit tests. But I won't be working on it myself anytime soon.
Would introducing a v19 dependency in the code be any of the concerns, making the lib unavailable to all the pre v19 consumers?
Because I believe PendingTasks were only introduced in v19 with this non experimental class name.
Indeed non-experimental PendingTasks is only available since Angular 19.0.0-next.7. However, I see that even in latest commit PendingTasks is still in developer preview. So it's probably best to wait for it to come out of preview...
But as soon as it is released as stable API, we can depend on it and update our requirements. There's nothing wrong with dropping support for old versions as long as we have a good reason to do it.
@martin-yumsto, Angular 20 was released, and PendingTasks is now public, stable API. If you are still interested in dropping support for older Angular, in order to better support Zoneless, then I'd merge your PR...