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

[BUG] named context not working for web provider #820

Closed
wellwind opened this issue Feb 19, 2024 · 1 comment · Fixed by #805
Closed

[BUG] named context not working for web provider #820

wellwind opened this issue Feb 19, 2024 · 1 comment · Fixed by #805
Assignees
Labels
bug Something isn't working

Comments

@wellwind
Copy link

Observed behavior

Following is my code:

  const clientName = 'my-client';
  await OpenFeature.setContext(clientName, { user: "mike" });
  OpenFeature.setProvider(
    clientName,
    new FlagdWebProvider({
      host: "localhost",
      port: 8013,
      tls: false,
    })
  );

  const client = OpenFeature.getClient(clientName);

  client.addHandler(ProviderEvents.Ready, () => {
    const flag = client.getBooleanValue("my-flag", false);

    const flagElm = document.querySelector('#flag-value');
    if (flagElm) {
      flagElm.innerHTML = flag.toString();
    }
  });

and flags.json

{
  "$schema": "https://flagd.dev/schema/v0/flags.json",
  "flags": {
    "my-flag": {
      "state": "ENABLED",
      "variants": {
        "on": true,
        "off": false
      },
      "defaultVariant": "off",
      "targeting": {
        "if": [
          {
            "===": [
              {
                "var": "user"
              },
              "mike"
            ]
          },
          "on",
          "off"
        ]
      }
    }
  }
}

Expected Behavior

I have set the named context and provider, and created a named client, if the context is working, I should get the on variant, but I got off, after open DevTools, the context didn't pass to flagd service.

image

When I use the empty name for context, provider, and client, the context is passed to flagd service as my expectation.

image

So I guess the named context is currently not working.

Steps to reproduce

I have a reproduced repo

https://github.com/wellwind/flagd-context-demo

in src/main.ts,if I set clientName to any non empty name, the flag result will be false, when I set clientName to '', I can get the true result.

@wellwind wellwind added the bug Something isn't working label Feb 19, 2024
@beeme1mr beeme1mr self-assigned this Feb 19, 2024
@beeme1mr beeme1mr transferred this issue from open-feature/flagd Feb 19, 2024
@beeme1mr
Copy link
Member

Hey @wellwind, thanks for the detailed issue and example repo. I've opened a PR to address the problem. The fix should be released in the next few days. Thanks!

github-merge-queue bot pushed a commit that referenced this issue Feb 20, 2024
## This PR

- adds domain as a concept to the server and web SDK
- adds a deprecation warning anywhere client name was exposed to users.
- fixes an issue in the web SDK where context set on a domain before a
provider is registered was not used.

## Addresses

fixes #820
4aa9657

### Notes

This change is based on [this
spec](open-feature/spec#229) change. I tried to
make it a non-breaking change but I may have missed an untested
condition. Please carefully review to make sure I didn't miss anything.

### Follow-up Tasks

- Update the doc readme parser to support "domain".
- Update the NestJS and React SDKS. We should consider making those a
breaking change since they're sub 1.0.

---------

Signed-off-by: Michael Beemer <[email protected]>
Signed-off-by: Todd Baert <[email protected]>
Co-authored-by: Todd Baert <[email protected]>
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