-
Notifications
You must be signed in to change notification settings - Fork 909
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
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 ✅
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems thatFetchResponse
isn't an exported type currently. It lives in src/client/remote_config_fetch_client.ts
but it should be moved to src/public_types.ts
and that should export it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few interface links are dropping out of the devsite docs, but otherwise LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Missed a few things, thanks to @egilmorez for the assist!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Nit we should update isSupported to return true on the server
SSR related improvements for RC client SDK.