Repository navigation
[FSSDK-13487] return JS client directly and store react meta in a WeakMap - #358
Merged
Raju Ahmed (raju-opti) merged 1 commit intoNov 20, 2026
Merged
Conversation
…kMap createInstance previously returned Object.create(jsClient). Methods called on that wrapper ran with `this` bound to the wrapper, so any `this.x = ...` inside the JS SDK wrote to the wrapper instead of the real client, splitting state between the two. Return the JS SDK client instance itself and keep React-specific metadata in a module-level WeakMap, accessed via getReactClientMeta/setReactClientMeta. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Raju Ahmed (raju-opti)
requested review from
Md Junaed Hossain (junaed-optimizely)
and
a balanced review from Copilot
November 20, 2026 14:06
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified in the changes to unify SDK client state and separate React metadata.
No open issues 🎉
What changed in this PR
This PR fixes split client state by returning the underlying JavaScript SDK client directly, while keeping React-specific metadata separate without changing the public API.
Changes:
- Removes the prototype-delegating wrapper so SDK methods and internal callbacks share the same client state.
- Moves React metadata into a
WeakMapand updates internal consumers and test helpers to use accessors. - Adds regression coverage for state mutation, per-client metadata isolation, and unregistered clients.
| File | Description |
|---|---|
src/utils/UserContextManager.ts |
Reads client metadata through the new accessor. |
src/utils/UserContextManager.spec.ts |
Registers mock-client metadata through the setter. |
src/provider/OptimizelyProvider.spec.tsx |
Updates provider mocks to register metadata through the setter. |
src/logger/getReactLogger.ts |
Retrieves logger metadata through the accessor. |
src/hooks/testUtils.tsx |
Updates hook test helpers to register client metadata. |
src/client/index.ts |
Replaces the internal symbol export with metadata accessors. |
src/client/createInstance.ts |
Returns the SDK client directly and stores metadata in a WeakMap. |
src/client/client.spec.ts |
Tests shared state mutation, metadata isolation, and missing metadata. |
Review effort: Balanced
Md Junaed Hossain (junaed-optimizely)
approved these changes
Nov 20, 2026
Md Junaed Hossain (junaed-optimizely)
left a comment
Collaborator
There was a problem hiding this comment.
Good catch! Thanks for the fix
Raju Ahmed (raju-opti)
deleted the
raju/fssdk-13487-client-meta-weakmap
branch
November 20, 2026 17:47
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
createInstancenow returns the JS SDK client instance itself instead of a prototype-delegating wrapper (Object.create(jsClient)).hasOdpManager,hasVuidManager,logger) moves from a symbol property into a module-levelWeakMapkeyed by client, accessed throughgetReactClientMeta/setReactClientMeta.UserContextManager,getReactLogger, and test helpers read and write meta through the new accessors;REACT_CLIENT_METAis removed.With the wrapper, JS SDK methods ran with
thisbound to the wrapper, so anythis.x = ...inside the JS client wrote to the wrapper instead of the real instance. That split state between the two, and anything holding the real instance (internal callbacks, listeners) saw stale values.No public API change: the meta accessors,
ReactClientMeta, and the removedREACT_CLIENT_METAare not exported fromsrc/index.tsorsrc/server.ts. Behavior for clients not created via the React SDK'screateInstanceis unchanged (meta lookup returnsundefined, as before).Test plan
thison the returned client lands on the underlying JS SDK client; verified it fails against the previousObject.createimplementation.undefinedmeta for clients not created viacreateInstance.npx vitest run: 14 files, 267 tests passing.npx tsc --noEmitclean.Issues
🤖 Generated with Claude Code