Skip to content

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

@wellwind

Description

@wellwind

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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions