Skip to content

Zoneless SSR is not supported #2329

Open
@martin-yumsto

Description

@martin-yumsto

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions