experiment(react-web-sdk): stub SDK on server#349
Closed
David Nalchevanidze (nalchevanidze) wants to merge 1 commit into
Closed
experiment(react-web-sdk): stub SDK on server#349David Nalchevanidze (nalchevanidze) wants to merge 1 commit into
David Nalchevanidze (nalchevanidze) wants to merge 1 commit into
Conversation
…e SDK is ready Adds ssrStub.ts with a full no-op OptimizationSdk shape that satisfies instanceof ContentfulOptimization checks. useOptimization returns it during the first render window (SSR + client pre-useLayoutEffect) so components can render without throwing. OptimizationProvider always renders children unless onStatesReady is set and the SDK is not yet ready. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
David Nalchevanidze (nalchevanidze)
added a commit
that referenced
this pull request
Jul 1, 2026
…t/ssr-stub The stub approach is now isolated in PR #349. fix-ssr contains only the nextjs-sdk implementation and surrounding changes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This was referenced Jul 1, 2026
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.
Approach
Adds an in-process SSR stub that satisfies
instanceof ContentfulOptimizationand is returned byuseOptimization()during the window beforeuseLayoutEffectfires (SSR + first client render). Components render without throwing; all real SDK calls happen in effects or event handlers which run after the SDK is already live.Changes
ssrStub.ts— full no-opOptimizationSdkshape withObject.setPrototypeOf(stub, ContentfulOptimization.prototype)useOptimization.ts— returnSSR_STUBinstead of throwing when SDK is not yet readyOptimizationProvider.tsx— always render children unlessonStatesReadyis set and SDK is not yet ready (allows Next.js SSR to produce HTML from server components inside the provider tree)renderedChild: trueduring SSR,liveUpdatesrenders[true, false, true, false, true, true])Trade-offs vs the other experiments
🤖 Generated with Claude Code