SSR related improvements for RC client SDK.#8699
Conversation
🦋 Changeset detectedLatest commit: bb99031 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Size Report 1Affected Products
Test Logs |
Size Analysis Report 1This report is too large (779,027 characters) to be displayed here in a GitHub comment. Please use the below link to see the full report on Google Cloud Storage.Test Logs |
Changeset File Check ✅
|
jenh
left a comment
There was a problem hiding this comment.
A few interface links are dropping out of the devsite docs, but otherwise LGTM.
jenh
left a comment
There was a problem hiding this comment.
(Missed a few things, thanks to @egilmorez for the assist!)
DellaBitta
left a comment
There was a problem hiding this comment.
One more change from my end, then waiting on @jamesdaniels' testing for final merge approval.
|
Ok, in my testing things are working alright. I did have to construct the RemoteConfigFetchResponse myself though, did we intend to include the class in this PR? Right now it's only exported as an interface and it wasn't clear how to construct config from the public api. Here's my Angular SSR component, let me know if I misunderstood anything. import { Component, inject, makeStateKey, PendingTasks, PLATFORM_ID, TransferState } from '@angular/core';
import { getAllChanges } from '@angular/fire/remote-config';
import { traceUntilFirst } from '@angular/fire/performance';
import { from, Observable, switchMap } from 'rxjs';
import { AsyncPipe, isPlatformServer, JsonPipe } from '@angular/common';
import { FirebaseApp } from '@angular/fire/app';
import { getRemoteConfig as getAdminRemoteConfig } from "firebase-admin/remote-config";
import { FirebaseAdminApp } from '../app.config';
import { getRemoteConfig, RemoteConfig, FetchResponse } from "@firebase/remote-config";
import { AllParameters } from 'rxfire/remote-config';
@Component({
selector: 'app-remote-config',
template: `<p>Remote Config! <code>{{ config$ | async | json }}</code></p>`,
imports: [AsyncPipe, JsonPipe],
})
export class RemoteConfigComponent {
private readonly transferState = inject(TransferState);
private readonly transferStateKey = makeStateKey<FetchResponse>("remote-config-server-config");
private readonly resolveRemoteConfig: Promise<RemoteConfig>;
protected readonly config$: Observable<AllParameters>;
constructor() {
const firebaseApp = inject(FirebaseApp);
if (isPlatformServer(inject(PLATFORM_ID))) {
const serverApp = inject(FirebaseAdminApp);
const adminRemoteConfig = getAdminRemoteConfig(serverApp);
const pendingTasks = inject(PendingTasks);
this.resolveRemoteConfig = pendingTasks.run(() =>
adminRemoteConfig.getServerTemplate().then(template => {
const serverConfig = template.evaluate();
// Expect this to work
// const initialFetchResponse = new RemoteConfigFetchResponse(serverApp, serverConfig);
const initialFetchResponse = {
status: 200,
eTag: "asuidfhiouasf",
config: { yada: "baz" }, // TODO don't hardcode, need to pull these values from the serverConfig
};
this.transferState.set(this.transferStateKey, initialFetchResponse);
return getRemoteConfig(firebaseApp, {
initialFetchResponse,
});
})
);
} else {
const initialFetchResponse = this.transferState.get(this.transferStateKey, undefined);
this.resolveRemoteConfig = Promise.resolve(getRemoteConfig(firebaseApp, {
initialFetchResponse,
}));
}
this.config$ = from(this.resolveRemoteConfig).pipe(
switchMap(remoteConfig => getAllChanges(remoteConfig)),
traceUntilFirst('remote-config'),
);
}
} |
|
Ok, it seems that API is in the works over here firebase/firebase-admin-node#2829 |
jamesdaniels
left a comment
There was a problem hiding this comment.
LGTM. Nit we should update isSupported to return true on the server
SSR related improvements for RC client SDK.