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

await has no effect on this type of expression on README example #84

Closed
kbrgl opened this issue Sep 12, 2024 · 0 comments · Fixed by #86
Closed

await has no effect on this type of expression on README example #84

kbrgl opened this issue Sep 12, 2024 · 0 comments · Fixed by #86
Assignees
Labels
bug Something isn't working

Comments

@kbrgl
Copy link

kbrgl commented Sep 12, 2024

Describe the bug

The README for this repo includes this example:

import { cookies } from "next/headers";
import { evaluateFlags, flagsClient, getDefinitions } from "@unleash/nextjs";

const getFlag = async () => {
  const cookieStore = cookies();
  const sessionId =
    cookieStore.get("unleash-session-id")?.value ||
    `${Math.floor(Math.random() * 1_000_000_000)}`;

  const definitions = await getDefinitions({
    fetchOptions: {
      next: { revalidate: 15 }, // Cache layer like Unleash Proxy!
    },
  });

  const { toggles } = await evaluateFlags(definitions, {
    sessionId,
  });
  const flags = flagsClient(toggles);

  return flags.isEnabled("nextjs-example");
};

export default async function Page() {
  const isEnabled = await getFlag();

  return (
    <p>
      Feature flag is{" "}
      <strong>
        <code>{isEnabled ? "ENABLED" : "DISABLED"}</code>
      </strong>
      .
    </p>
  );
}

However, since evaluateFlags doesn't return a Promise, awaiting it doesn't do anything. Very minor bug, but worth fixing!

Steps to reproduce the bug

Go to docs.
Paste the snippet in a project with Unleash and Next installed.
Observe TypeScript errors.

Expected behavior

N/A

Logs, error output, etc.

No response

Screenshots

Screenshot 2024-09-12 at 12 38 55 PM

Additional context

No response

Unleash version

No response

Subscription type

None

Hosting type

Hosted by Unleash

SDK information (language and version)

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants