Skip to content

Excessive API call to the api.flagsmith.com #299

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

Open
jazarja opened this issue Mar 26, 2025 · 1 comment
Open

Excessive API call to the api.flagsmith.com #299

jazarja opened this issue Mar 26, 2025 · 1 comment
Assignees

Comments

@jazarja
Copy link

jazarja commented Mar 26, 2025

In my Next.js application, I'm attempting to make a single call to Flagsmith using the following implementation:

useEffect(() => {
  console.log("Loading flagsmith...");
  const init = async () => {
    await flagsmith.init({
      environmentID: process.env.NEXT_PUBLIC_FLAGSMITH_ENV_ID,
    });
    setFlagSmithState(flagsmith.getState());
    setFeatureFlags(flagsmith.getState().flags);
  };
  init();
}, []);

From the browser console, everything appears to work as expected—only one "Loading flagsmith..." message is logged.

However, upon inspecting the browser’s network tab, I noticed that there are a total of four calls made to https://edge.api.flagsmith.com/api/v1/flags/. It seems that only one of these requests is triggered by my code, while the remaining three appear to originate from the Flagsmith library itself (possibly from react.mjs).

I'm unsure why these additional calls are being made and would appreciate any insight into whether this is expected behavior or if there’s a recommended way to prevent these redundant requests.

@kyle-ssg
Copy link
Member

Hey @jazarja, are you able to provide a minimal replication of this?

The only file that triggers network calls is flagsmith-core.js. It could be down to how NextJS is loading the application however I'd have to see an example to confirm that.

We have a few NextJS examples here which may help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants