Skip to content

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

Closed
@dsafonov-grid

Description

@dsafonov-grid

Is there an existing issue for this?

  • 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

this.optimizely.onReady().then(({ success }) => {

because stack trace pointed to this
const readyTimeout = setTimeout(onReadyTimeout, timeoutValue);

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions