Open
Conversation
There was a problem hiding this comment.
Pull request overview
Implements “sync hooks” behavior so React hooks re-evaluate Optimizely decisions when the SDK config/datafile changes, and introduces new multi-flag decision hooks to improve ergonomics for bulk decision reads.
Changes:
- Subscribes the Provider to
OPTIMIZELY_CONFIG_UPDATEand addsProviderStateStore.refresh()to trigger hook re-evaluation on config updates. - Removes
isClientReadyfrom provider state and addssubscribeAllForcedDecisionsto support all-flags forced-decision reactivity. - Adds new hooks
useDecideForKeysanduseDecideAll, plus refactors tests with shared mock factories.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/provider/types.ts | Removes isClientReady from ProviderState shape. |
| src/provider/ProviderStateStore.ts | Adds refresh() and subscribeAllForcedDecisions; updates forced decision notification behavior. |
| src/provider/ProviderStateStore.spec.ts | Updates store tests for removed readiness flag and new forced-decision “all” subscription. |
| src/provider/OptimizelyProvider.tsx | Subscribes to config updates and adjusts onReady handling. |
| src/provider/OptimizelyProvider.spec.tsx | Updates Provider tests for new notification subscription and removed readiness flag assertions. |
| src/index.ts | Exports new hooks from the package entrypoint. |
| src/hooks/useStableArray.ts | Adds overloads to improve return typing for non-optional arrays. |
| src/hooks/useOptimizelyUserContext.spec.tsx | Updates test to use store.refresh() instead of readiness flag changes. |
| src/hooks/useOptimizelyClient.spec.tsx | Updates test to use setError/refresh instead of readiness changes. |
| src/hooks/useDecideForKeys.ts | Adds new multi-flag decide hook with per-key forced decision subscriptions. |
| src/hooks/useDecideForKeys.spec.tsx | Adds comprehensive unit tests for useDecideForKeys. |
| src/hooks/useDecideAll.ts | Adds all-flags decide hook with “all forced decisions” subscription. |
| src/hooks/useDecideAll.spec.tsx | Adds comprehensive unit tests for useDecideAll. |
| src/hooks/useDecide.spec.tsx | Refactors tests to shared utilities and validates config-update-driven re-evaluation. |
| src/hooks/testUtils.tsx | Adds shared mock factories and Provider wrapper utilities for hook tests. |
| src/hooks/index.ts | Re-exports new hooks/types from hooks barrel. |
| package.json | Changes prepare script behavior. |
💡 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
OPTIMIZELY_CONFIG_UPDATEin the Provider so hooks automatically re-evaluate decisions when the datafile changes (e.g. polling)isClientReadystate fromProviderStateStore— readiness is derived fromuserContext + client.getOptimizelyConfig(), eliminating a redundantdecide()call per hook in sync datafile scenariosuseDecideForKeyshook — multi-flag sync decisions with per-key forced decision reactivityuseDecideAllhook — all-flags sync decisions with broadcast forced decision reactivity viasubscribeAllForcedDecisionssubscribeAllForcedDecisionstoProviderStateStoreforuseDecideAllto react to any forced decision changeuseStableArrayso non-optional arrays returnT[](no fallback needed)Test plan
testUtils.tsxto reduce duplication across hook testsIssues