Skip to content

[FSSDK-12296] Async Hook implementation#324

Merged
junaed-optimizely merged 5 commits intomasterfrom
junaed/fssdk-12296-async-hook-impl
Apr 7, 2026
Merged

[FSSDK-12296] Async Hook implementation#324
junaed-optimizely merged 5 commits intomasterfrom
junaed/fssdk-12296-async-hook-impl

Conversation

@junaed-optimizely
Copy link
Copy Markdown
Collaborator

Summary

  • Add useDecideAsync, useDecideForKeysAsync, and useDecideAllAsync hooks — async counterparts to the existing sync decide hooks, required for CMAB, async UPS etc.

Test plan

  • Add tests for all 3 new async hooks covering store states, race conditions, re-evaluation triggers, forced decision reactivity, and render optimization

Issues

  • FSSDK-12296

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

Adds async counterparts to the existing “decide” React hooks so consumers can evaluate flags via the Optimizely SDK’s async decide APIs (needed for CMAB / async decisioning) while handling loading/error states, cancellation, and forced-decision reactivity.

Changes:

  • Introduces useDecideAsync, useDecideForKeysAsync, and useDecideAllAsync and exports them from the public entrypoints.
  • Adds shared useAsyncDecision state machine to manage async execution, cancellation of stale promises, and store readiness transitions.
  • Adds comprehensive Vitest coverage for the 3 new hooks and extends hook test utilities with async decide method stubs.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/index.ts Exports the new async hooks from the package entrypoint.
src/hooks/index.ts Exposes the new async hooks (and related types) from the hooks barrel.
src/hooks/useAsyncDecision.ts Adds shared async state machine used by all async decide hooks.
src/hooks/useDecideAsync.ts Implements async single-flag decision hook w/ forced decision subscription.
src/hooks/useDecideForKeysAsync.ts Implements async multi-key decision hook w/ per-key forced decision subscription.
src/hooks/useDecideAllAsync.ts Implements async all-flags decision hook w/ global forced decision subscription.
src/hooks/*.spec.tsx Adds tests covering readiness states, cancellation, re-evaluation triggers, and forced-decision reactivity.
src/hooks/testUtils.tsx Extends mock user context to support async decide APIs for testing.

💡 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.

Some small suggestions

@junaed-optimizely junaed-optimizely merged commit 9c77bfd into master Apr 7, 2026
10 checks passed
@junaed-optimizely junaed-optimizely deleted the junaed/fssdk-12296-async-hook-impl branch April 7, 2026 15:46
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