Skip to content

Commit 8fbe8c1

Browse files
committed
fix issue where invalidateRootCache didn't happen when the page first loaded
1 parent 5ad621b commit 8fbe8c1

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/app/core/server-check/server-check.guard.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,18 @@ describe('ServerCheckGuard', () => {
6363
});
6464

6565
describe(`listenForRouteChanges`, () => {
66-
it(`should invalidate the root cache on every NavigationStart event`, () => {
66+
it(`should invalidate the root cache when the method is first called, and then on every NavigationStart event`, () => {
6767
testScheduler.run(() => {
6868
guard.listenForRouteChanges();
69+
expect(rootDataServiceStub.invalidateRootCache).toHaveBeenCalledTimes(1);
70+
6971
eventSubject.next(new NavigationStart(1,''));
7072
eventSubject.next(new NavigationEnd(1,'', ''));
7173
eventSubject.next(new NavigationStart(2,''));
7274
eventSubject.next(new NavigationEnd(2,'', ''));
7375
eventSubject.next(new NavigationStart(3,''));
7476
});
75-
expect(rootDataServiceStub.invalidateRootCache).toHaveBeenCalledTimes(3);
77+
expect(rootDataServiceStub.invalidateRootCache).toHaveBeenCalledTimes(4);
7678
});
7779
});
7880
});

src/app/core/server-check/server-check.guard.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ export class ServerCheckGuard implements CanActivateChild {
5252
* operation, the cached version is used.
5353
*/
5454
listenForRouteChanges(): void {
55+
// we'll always be too late for the first NavigationStart event with the router subscribe below,
56+
// so this statement is for the very first route operation
57+
this.rootDataService.invalidateRootCache();
58+
5559
this.router.events.pipe(
5660
filter(event => event instanceof NavigationStart),
5761
).subscribe(() => {

0 commit comments

Comments
 (0)