diff --git a/src/compat/performance/performance.service.ts b/src/compat/performance/performance.service.ts index edc1861d2..5510f8087 100644 --- a/src/compat/performance/performance.service.ts +++ b/src/compat/performance/performance.service.ts @@ -2,27 +2,16 @@ import { ApplicationRef, Injectable, OnDestroy } from '@angular/core'; import { Subscription } from 'rxjs'; import { first, tap } from 'rxjs/operators'; -const IS_STABLE_START_MARK = '_isStableStart'; +const IS_STABLE_START_MARK = 'Zone'; const IS_STABLE_END_MARK = '_isStableEnd'; -function markStarts() { - if (typeof(window) !== 'undefined' && window.performance && window.performance.mark) { - window.performance.mark(IS_STABLE_START_MARK); - return true; - } else { - return false; - } -} - -const started = markStarts(); - @Injectable() export class PerformanceMonitoringService implements OnDestroy { private disposable: Subscription|undefined; constructor(appRef: ApplicationRef) { - if (started && window.performance.mark) { + if (typeof window !== 'undefined' && window.performance?.mark) { this.disposable = appRef.isStable.pipe( first(it => it), tap(() => { diff --git a/src/compat/performance/performance.ts b/src/compat/performance/performance.ts index b9b083f19..5bc217509 100644 --- a/src/compat/performance/performance.ts +++ b/src/compat/performance/performance.ts @@ -52,7 +52,7 @@ export class AngularFirePerformance { } const trace$ = (traceId: string) => { - if (typeof window !== 'undefined' && window.performance && window.performance.mark) { + if (typeof window !== 'undefined' && window.performance?.mark) { const entries = window.performance.getEntriesByName(traceId, 'measure') || []; const startMarkName = `_${traceId}Start[${entries.length}]`; const endMarkName = `_${traceId}End[${entries.length}]`; diff --git a/src/compat/storage/pipes/storageUrl.pipe.ts b/src/compat/storage/pipes/storageUrl.pipe.ts index 1aaf2caeb..5f20d2fd4 100644 --- a/src/compat/storage/pipes/storageUrl.pipe.ts +++ b/src/compat/storage/pipes/storageUrl.pipe.ts @@ -1,6 +1,8 @@ import { AsyncPipe } from '@angular/common'; -import { ChangeDetectorRef, NgModule, OnDestroy, Pipe, PipeTransform } from '@angular/core'; -import { Observable } from 'rxjs'; +import { ChangeDetectorRef, NgModule, OnDestroy, Optional, Pipe, PipeTransform } from '@angular/core'; +import { makeStateKey, TransferState } from '@angular/platform-browser'; +import { Observable, of } from 'rxjs'; +import { tap } from 'rxjs/operators'; import { AngularFireStorage } from '../storage'; /** to be used with in combination with | async */ @@ -14,14 +16,22 @@ export class GetDownloadURLPipe implements PipeTransform, OnDestroy { private path: string; private downloadUrl$: Observable; - constructor(private storage: AngularFireStorage, cdr: ChangeDetectorRef) { + constructor( + private storage: AngularFireStorage, + cdr: ChangeDetectorRef, + @Optional() private state: TransferState + ) { this.asyncPipe = new AsyncPipe(cdr); } transform(path: string) { if (path !== this.path) { this.path = path; - this.downloadUrl$ = this.storage.ref(path).getDownloadURL(); + const key = makeStateKey(`|getDownloadURL|${path}`); + const existing = this.state?.get(key, undefined); + this.downloadUrl$ = existing ? of(existing) : this.storage.ref(path).getDownloadURL().pipe( + tap(it => this.state?.set(key, it)) + ); } return this.asyncPipe.transform(this.downloadUrl$); } diff --git a/src/compat/storage/ref.ts b/src/compat/storage/ref.ts index ecb04ae04..913a0dd57 100644 --- a/src/compat/storage/ref.ts +++ b/src/compat/storage/ref.ts @@ -8,7 +8,7 @@ export interface AngularFireStorageReference { getDownloadURL(): Observable; getMetadata(): Observable; delete(): Observable; - child(path: string): any; + child(path: string): AngularFireStorageReference; updateMetadata(meta: SettableMetadata): Observable; put(data: any, metadata?: UploadMetadata | undefined): AngularFireUploadTask; putString(data: string, format?: string | undefined, metadata?: UploadMetadata | undefined): AngularFireUploadTask;