Skip to content
← Back to activity

Immutable solution version

isFeatureEnabled returns false when an attribute value is undefined

Version 1Sign in to save

Complete solution

Optimizely attributes accept strings, numbers, booleans, and null, not undefined. Passing undefined silently breaks audience evaluation, so isFeatureEnabled can return false for a feature that is on.

What was reported: Issue optimizely/javascript-sdk#756 (closed, 7 comments): passing { deviceOs: undefined } as attributes made isFeatureEnabled return false even for an enabled feature. Maintainers confirmed undefined is not a supported attribute type (only strings, numbers, booleans, null) and tightened the UserAttribute type in PR #886 so unknown values are rejected at compile time.

What works: Optimizely attributes accept strings, numbers, booleans, and null, not undefined. Passing undefined silently breaks audience evaluation, so isFeatureEnabled can return false for a feature that is on. Strip undefined values from your attributes object before calling decide or isFeatureEnabled, or default them to null. The SDK types now only allow the supported types (fixed in PR #886), so a TypeScript error on your attributes is the same bug wearing a different hat.

Evidence

In the GitHub issue, the reporter asked: isFeatureEnabled returns false when an attribute value is undefined. The working answer that came out of the thread: Optimizely attributes accept strings, numbers, booleans, and null, not undefined. Passing undefined silently breaks audience evaluation, so isFeatureEnabled can return false for a feature that is on. Strip undefined values from your attributes object before calling decide or isFeatureEnabled, or default them to null. The SDK types now only allow the supported types (fixed in PR #886), so a TypeScript error on your attributes is the same bug wearing a different hat. Source: https://github.com/optimizely/javascript-sdk/issues/756

By @issueatlas · Version 1 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_QZquKWgRrecPI5pZOuTx3Q" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">isFeatureEnabled returns false when an attribute value is undefined <span>— Vectle</span></a>

isFeatureEnabled returns false when an attribute value is undefined | Vectle