Skip to content

[FSSDK-12294] hook fix#330

Closed
junaed-optimizely wants to merge 2 commits intomasterfrom
junaed/fssdk-12294-hook-fix
Closed

[FSSDK-12294] hook fix#330
junaed-optimizely wants to merge 2 commits intomasterfrom
junaed/fssdk-12294-hook-fix

Conversation

@junaed-optimizely
Copy link
Copy Markdown
Collaborator

@junaed-optimizely junaed-optimizely commented Apr 17, 2026

Summary

  • Implement stale-while-error pattern across all hooks: when a store-level error occurs (e.g., CDN datafile fetch failure) but a valid config and user context already exist, hooks now return the existing decision/userContext alongside the error instead of nulling them out. Previously, if onReady() rejected after a sync datafile was already loaded, all hooks immediately returned { decision: null, error } — discarding a perfectly usable datafile. This was overly aggressive for the common case where a sync datafile is provided and a background CDN refresh fails due to network issues.

Test plan

Tests have been added to address the change.

Issues

  • FSSDK-12294

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Optimizely React hooks to implement a stale-while-error pattern so that store-level errors don’t discard already-available userContext/decisions.

Changes:

  • Update sync hooks to return existing decisions/userContext alongside store errors when config + user context are available.
  • Update async decision state machine to surface store errors while still executing decisions when possible.
  • Add/adjust tests to validate stale-with-error behavior across hooks.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/hooks/types.ts Expands result unions to allow returning stale decisions alongside an Error.
src/hooks/useOptimizelyUserContext.ts Returns existing userContext even when state.error is set.
src/hooks/useOptimizelyUserContext.spec.tsx Adds test coverage for stale user context returned with store error.
src/hooks/useDecide.ts Returns decision even when store error exists (stale-while-error).
src/hooks/useDecide.spec.tsx Adds test for stale decision returned with store error.
src/hooks/useDecideAll.ts Returns all decisions even when store error exists (stale-while-error).
src/hooks/useDecideAll.spec.tsx Adds test for stale decisions returned with store error.
src/hooks/useDecideForKeys.ts Returns decisions-for-keys even when store error exists (stale-while-error).
src/hooks/useDecideForKeys.spec.tsx Adds test for stale decisions returned with store error.
src/hooks/useAsyncDecision.ts Adjusts async decision flow to keep executing when config + userContext exist, and propagate store error on resolve.
src/hooks/useDecideAsync.spec.tsx Adds test for stale decision returned with store error in async hook.
src/hooks/useDecideAllAsync.spec.tsx Adds test for stale decisions returned with store error in async hook.
src/hooks/useDecideForKeysAsync.spec.tsx Adds test for stale decisions returned with store error in async hook.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/hooks/useDecideAll.ts
Comment thread src/hooks/useOptimizelyUserContext.ts
Comment thread src/hooks/useAsyncDecision.ts Outdated
Comment thread src/hooks/useDecide.ts
Comment thread src/hooks/useDecideForKeys.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants