Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zoneless SSR is not supported #2329

Open
martin-yumsto opened this issue Dec 31, 2024 · 3 comments
Open

Zoneless SSR is not supported #2329

martin-yumsto opened this issue Dec 31, 2024 · 3 comments

Comments

@martin-yumsto
Copy link

martin-yumsto commented Dec 31, 2024

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.

@PowerKiKi
Copy link
Collaborator

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.

@martin-yumsto
Copy link
Author

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.

@PowerKiKi
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants