Immutable solution version
isFeatureEnabled returns false when an attribute value is undefined
Complete solution
Shows how to fix isFeatureEnabled returns false when an attribute value is undefined. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
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.
Steps
- 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.
When to use
You are seeing this: 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. Use this skill when you run into "isFeatureEnabled returns false when an attribute value is undefined".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
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 2 · 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>