It seems this SDK does not work correctly. I think...
# ask-questions
g
It seems this SDK does not work correctly. I think its because in
decryptPayload
Copy code
data.features = JSON.parse(
        await decrypt(data.encryptedFeatures, decryptionKey, subtle)
      );
Is async,
f
How are you evaluating the flag? It's likely you are evaluating it before the decryption happens. https://docs.growthbook.io/lib/script-tag#using-feature-flags The example above shows how to listen for the
growthbookdata
event, which will fire every time the feature definitions or attributes change
g
I’ve used snippet visible in SDK
Copy code
<html>
<head>
    <script
            data-api-host="<http://localhost:3300>"
            data-client-key="sdk-9m8LOKhsUcWrizJQ"
            data-decryption-key="u+xDcOpJfNYiBMFdHkgdSw=="
            src="<https://cdn.jsdelivr.net/npm/@growthbook/growthbook/dist/bundles/auto.js>"
    ></script>
    <script>
        const r = window._growthbook.getFeatureValue("simple", false);
        console.log("!",r,"!")
    </script>
</head>
<body></body>
</html>
With debugger I can see it tries to decrypt twice. First w/o key, then flag is evaluated (console.log) and then with a decryption key (but lag is not reevaluated) It works for other SDK tho
f
Yes, you must wait until the SDK is ready before you evaluate a feature flag using the methods in the docs. The code you have now is subject to race conditions and will only work some of the time in ideal circumstances.