Skip to content

LD double initialisation with Strict Mode set to true. #284

@matias-pinata

Description

@matias-pinata

Describe the bug
In my Next.js application and only on local environment with React Strict Mode set to true, LD makes two calls to https://app.launchdarkly.com/sdk/goals/{id}. This then opens 2 websockets on https://clientstream.launchdarkly.com/eval/ and for some reason all my flags do not update, they get stuck on default values.

To reproduce
Create a new Next.js app (any React 18 app should trigger it) and initialize App.tsx using

export default withLDProvider({
  clientSideID: process.env.NEXT_PUBLIC_LAUNCH_DARKLY_CLIENT_ID || "",
})(MyApp);

App.tsx renders twice, which initializes LD provider twice, triggering the bug.

Expected behavior
LD should be a singleton, or there should be a way to manually call the initialize (so I can avoid calling it twice).
Or it should initialize twice and handle correctly the flags updates.

SDK version
3.0.6

Language version, developer tools
Nextjs 13.4.4

OS/platform
Mac Pro M1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions