Skip to content

Commit

Permalink
fix: wait for init
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity committed Jan 16, 2025
1 parent c6e42a4 commit 8557ec2
Showing 1 changed file with 11 additions and 15 deletions.
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 });

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

0 comments on commit 8557ec2

Please sign in to comment.