the-guild-org / the-guild-org/apollo-angular

Zoneless SSR is not supported

Open
#2,329 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1.5k
Forks
309
Avg merge
1h 45m
Merged PRs (30d)
3

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Apollo operations and QueryRef/watchQuery paths described in the report, focusing on how Angular SSR determines stability in a zoneless app. Reproduce the minimal zoneless Angular SSR app with Apollo and an in-memory cache, then verify that pending work covers the request, cache updates, and final consumer re-render before the app becomes stable.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, graphql, typescript
Domain
backend-api-design, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.