Skip to content

[FSSDK-10777] SSR improvements + RSC support addition#318

Open
junaed-optimizely wants to merge 10 commits into3.x.xfrom
junaed/fssdk-10777-ssr-doc-update
Open

[FSSDK-10777] SSR improvements + RSC support addition#318
junaed-optimizely wants to merge 10 commits into3.x.xfrom
junaed/fssdk-10777-ssr-doc-update

Conversation

@junaed-optimizely
Copy link
Contributor

Summary

This pull request improves the documentation and implementation of server-side rendering (SSR) and ODP segment handling in the Optimizely React SDK V3.

It clarifies SSR usage in the README, adds a comprehensive Next.js integration guide, and updates the SDK's hooks to support more accurate decision-making during partial readiness states (such as when ODP segments are still being fetched). It also enhances test coverage for these scenarios.

Documentation improvements:

  • Expanded and clarified the SSR section in README.md to explain the need for a pre-fetched datafile, updated setup instructions, and added a summary of SSR limitations. References to Next.js and React Server Components were added, and the SSR example was simplified.
  • Added a new docs/nextjs-ssr.md guide detailing integration patterns for both Next.js App Router and Pages Router, including code examples, feature flag usage, server component usage, and SSR limitations.

SDK logic and behavior changes:

  • Updated the useExperiment, useFeature, and useDecision hooks to support synchronous decisions when getOptimizelyConfig and getUserContext are available, even if the client is not fully ready (e.g., ODP segments are still loading). This enables partial decisions during SSR or while waiting for async user/segment data. [1] [2] [3]

Testing improvements:

  • Enhanced test mocks in Experiment.spec.tsx, Feature.spec.tsx, and hooks.spec.tsx to include getOptimizelyConfig and getUserContext methods, simulating partial readiness and ODP scenarios. [1] [2] [3]
  • Added and updated tests to verify that hooks and components re-render with updated decisions once ODP segment fetching completes, ensuring correct feature flag behavior during partial readiness. [1] [2] [3]

Minor documentation and formatting fixes:

  • Cleaned up code samples and formatting in README.md for clarity and consistency. [1] [2] [3] [4] [5]

These changes make SSR and ODP segment handling more robust and developer-friendly, especially for teams using Next.js or requiring partial readiness support.

Test plan

Issues

  • FSSDK-10777

Copy link
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.

few comments


- **Datafile required** — SSR requires a pre-fetched datafile. Using `sdkKey` alone falls back to a failed decision.
- **Static user only** — User `Promise` is not supported during SSR.
- **ODP segments unavailable** — ODP audience segments require async I/O and are not available during server rendering.
Copy link
Contributor

Choose a reason for hiding this comment

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

since there is a change in the hooks.ts file, I assume we need a patch update. In that case, can we consider adding the option to pass pre-fetched qualifiedSegments as props to the release?

@junaed-optimizely junaed-optimizely changed the title Junaed/fssdk 10777 ssr doc update [FSSDK-10777] SSR improvements Mar 2, 2026
@junaed-optimizely junaed-optimizely changed the title [FSSDK-10777] SSR improvements [FSSDK-10777] SSR improvements + RSC support addition Mar 2, 2026
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