Skip to content

[FSSDK-12294] sync hooks impl#322

Merged
junaed-optimizely merged 6 commits intomasterfrom
junaed/fssdk-12294-sync-hook-impl-2.0
Mar 30, 2026
Merged

[FSSDK-12294] sync hooks impl#322
junaed-optimizely merged 6 commits intomasterfrom
junaed/fssdk-12294-sync-hook-impl-2.0

Conversation

@junaed-optimizely
Copy link
Copy Markdown
Contributor

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

Summary

  • Subscribe to OPTIMIZELY_CONFIG_UPDATE in the Provider so hooks automatically re-evaluate decisions when the datafile changes (e.g. polling)
  • Remove isClientReady state from ProviderStateStore — readiness is derived from userContext + client.getOptimizelyConfig(), eliminating a redundant decide() call per hook in sync datafile scenarios
  • Add useDecideForKeys hook — multi-flag sync decisions with per-key forced decision reactivity
  • Add useDecideAll hook — all-flags sync decisions with broadcast forced decision reactivity via subscribeAllForcedDecisions
  • Add subscribeAllForcedDecisions to ProviderStateStore for useDecideAll to react to any forced decision change
  • Add overloads to useStableArray so non-optional arrays return T[] (no fallback needed)

Test plan

  • Extract shared test mock factories into testUtils.tsx to reduce duplication across hook tests
  • Tests have been added / modified / removed to adjust with the changes

Issues

  • FSSDK-12294

@junaed-optimizely junaed-optimizely changed the title [FSSDK-12294] Config update listener [FSSDK-12294] sync hooks impl Mar 27, 2026
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

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_UPDATE and adds ProviderStateStore.refresh() to trigger hook re-evaluation on config updates.
  • Removes isClientReady from provider state and adds subscribeAllForcedDecisions to support all-flags forced-decision reactivity.
  • Adds new hooks useDecideForKeys and useDecideAll, 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.

Copy link
Copy Markdown
Contributor

@raju-opti raju-opti left a comment

Choose a reason for hiding this comment

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

looks good. One suggestion

@junaed-optimizely junaed-optimizely merged commit 899e2d8 into master Mar 30, 2026
9 of 10 checks passed
@junaed-optimizely junaed-optimizely deleted the junaed/fssdk-12294-sync-hook-impl-2.0 branch March 30, 2026 17:25
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.

3 participants