diff --git a/packages/fern-docs/bundle/src/server/ld-adapter.ts b/packages/fern-docs/bundle/src/server/ld-adapter.ts index ca087f3d01..8c36802c7d 100644 --- a/packages/fern-docs/bundle/src/server/ld-adapter.ts +++ b/packages/fern-docs/bundle/src/server/ld-adapter.ts @@ -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(); - async function fetchInitialFlags( sdkKey: string, context: ld.LDContext, @@ -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,