js-sdk icon indicating copy to clipboard operation
js-sdk copied to clipboard

[BUG] Multi Provider: hookContexts.get(context) fails, but works with context.context

Open laszlorostas opened this issue 2 months ago • 2 comments

Hi, I ran into an issue when using the Multi Provider. These two lines don’t work for me as-is (link):

const hookContext = this.hookContexts.get(context);
const hookHints = this.hookHints.get(context);

But when I change them to this, it works:

const hookContext = this.hookContexts.get(context.context);
const hookHints = this.hookHints.get(context.context);

Has anyone else experienced this? I’m using FlagdProvider and the EnvVarProvider provider. Thanks!

laszlorostas avatar Oct 23 '25 10:10 laszlorostas

Slack thread: https://cloud-native.slack.com/archives/C0344AANLA1/p1762349668823959

beeme1mr avatar Nov 06 '25 14:11 beeme1mr

Minimal reproduction: https://github.com/laszlorostas/openfeature-multi-test

beeme1mr avatar Nov 06 '25 14:11 beeme1mr

I will add on to this my example repo using only the InMemoryProvider. I provided ESM and CJS versions to be extra sure it wasn't something crazy happening with that either. https://github.com/mdkitzman/openfeature-multiprovider-esm-test

mdkitzman avatar Nov 12 '25 22:11 mdkitzman

There does appear to be some issue with the context information lookup due to the fact that Map key lookup for objects is done by reference.

In my example it looks like after hook execution in the OpenFeature sdk, a copy of the context is made (and frozen) so when the evaluation phase is executed, and the MultiProvider attempts to do a lookup that context in the hook map, it cannot be found, even though the contents of the contexts are the same, they aren't the same reference.

mdkitzman avatar Nov 13 '25 14:11 mdkitzman