Skip to content
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

fix: ld server-side wait for init #2029

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions packages/fern-docs/bundle/src/server/ld-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ export const createLdPredicate = async ({
};
};

// this is an in-memory "singleton" of all LD clients
// TODO: there should be a way to close the clients when the server shuts down
const ldClientMap = new Map<string, ld.LDClient>();

async function fetchInitialFlags(
sdkKey: string,
context: ld.LDContext,
Expand All @@ -152,17 +148,17 @@ async function fetchInitialFlags(
hash: string | undefined;
}> {
try {
const ldClient =
ldClientMap.get(sdkKey) ??
ld.init(sdkKey, {
baseUri: options?.baseUrl,
streamUri: options?.streamUrl,
eventsUri: options?.eventsUrl,
stream: false,
sendEvents: false,
diagnosticOptOut: true,
});
ldClientMap.set(sdkKey, ldClient);
const ldClient = ld.init(sdkKey, {
baseUri: options?.baseUrl,
streamUri: options?.streamUrl,
eventsUri: options?.eventsUrl,
stream: false,
sendEvents: false,
diagnosticOptOut: true,
});

await ldClient.waitForInitialization({ timeout: 10 });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error logs show that this was needed


const flags = await ldClient.allFlagsState(context, {
clientSideOnly: true, // these flags will be passed to the client side
detailsOnlyForTrackedFlags: true,
Expand Down
Loading