ngx-timeago
ngx-timeago copied to clipboard
TimeAgo pipe does not work with SSR
Probably due to resolving an observable, but TimeAgo only works on the browser. If implemented with SSR, SSR hangs and the page never loads.
+1
I've prepared PR for this issue. As a workaround you can create following service:
import { isPlatformBrowser } from '@angular/common';
import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
import { TimeagoDefaultClock } from 'ngx-timeago';
import { EMPTY, Observable } from 'rxjs';
@Injectable({
providedIn: 'root',
})
export class TimeagoAppClock extends TimeagoDefaultClock {
constructor(
@Inject(PLATFORM_ID) private readonly platformId: Record<string, unknown>
) {
super();
}
tick(then: number): Observable<unknown> {
return isPlatformBrowser(this.platformId) ? super.tick(then) : EMPTY;
}
}
and use it instead of default clock:
TimeagoModule.forRoot({
clock: {
provide: TimeagoClock,
useClass: TimeagoAppClock,
},
}),