Closed
Conversation
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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