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

[BUG] Using client.createUserContext leads to setTimeout is not defined error on Akamai EdgeWorker

Open dsafonov-grid opened this issue 1 year ago • 0 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

SDK Version

5.3.0

Current Behavior

const optimizelyUserContext = optimizelyClient.createUserContext(userId, udo);

leads to

ReferenceError setTimeout is not defined ReferenceError: setTimeout is not defined%0A at e.onReady (main.js:1:84427)%0A at new e (main.js:1:28336)%0A at e.createUserContext (main.js:1:84961)%0A at main.js:1:93456%0A at Generator.next ()%0A at main.js:1:461%0A at new Promise ()%0A at a (main.js:1:206)%0A at jr (main.js:1:92339)

Expected Behavior

Works same as before

Steps To Reproduce

  1. In Akamai Edge Env
  2. Run your starter kit https://github.com/optimizely/akamai-edgeworker-starter-kit with 5.3.0

SDK Type

Edge/Lite

Node Version

No response

Browsers impacted

No response

Link

No response

Logs

No response

Severity

No response

Workaround/Solution

The cause of this behavior I think is: calling onReady https://github.com/optimizely/javascript-sdk/blob/75418da42a93dd94e63885685d3c55605fdaf6d4/lib/optimizely_user_context/index.ts#L67 because stack trace pointed to this https://github.com/optimizely/javascript-sdk/blob/75418da42a93dd94e63885685d3c55605fdaf6d4/lib/optimizely/index.ts#L1407

I can see that you pass shouldIdentifyUser as true to createUserContext all the time. And another function shouldIdentifyUser as false createInternalUserContext, is private, so for the time being is it ok to use createInternalUserContext and to suppress typescript?

This approach works fine

    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-expect-error
    const optimizelyUserContext = optimizelyClient.createInternalUserContext(userId, udo);

Recent Change

No response

Conflicts

No response

dsafonov-grid avatar Apr 26 '24 21:04 dsafonov-grid