Skip to content

[FSSDK-13487] return JS client directly and store react meta in a WeakMap - #358

Merged
Raju Ahmed (raju-opti) merged 1 commit into
masterfrom
raju/fssdk-13487-client-meta-weakmap
Nov 20, 2026
Merged

Raju Ahmed (raju-opti) merged 1 commit into
masterfrom
raju/fssdk-13487-client-meta-weakmap

Conversation

@raju-opti

Copy link
Copy Markdown
Contributor

Summary

  • createInstance now returns the JS SDK client instance itself instead of a prototype-delegating wrapper (Object.create(jsClient)).
  • React-specific metadata (hasOdpManager, hasVuidManager, logger) moves from a symbol property into a module-level WeakMap keyed by client, accessed through getReactClientMeta / setReactClientMeta.
  • UserContextManager, getReactLogger, and test helpers read and write meta through the new accessors; REACT_CLIENT_META is removed.

With the wrapper, JS SDK methods ran with this bound to the wrapper, so any this.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 removed REACT_CLIENT_META are not exported from src/index.ts or src/server.ts. Behavior for clients not created via the React SDK's createInstance is unchanged (meta lookup returns undefined, as before).

Test plan

  • New test asserts that state mutated via this on the returned client lands on the underlying JS SDK client; verified it fails against the previous Object.create implementation.
  • Added tests for per-client meta isolation and undefined meta for clients not created via createInstance.
  • npx vitest run: 14 files, 267 tests passing.
  • npx tsc --noEmit clean.

Issues

  • FSSDK-13487

🤖 Generated with Claude Code

…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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 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 WeakMap and 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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good catch! Thanks for the fix

@raju-opti
Raju Ahmed (raju-opti) merged commit 5e9165d into master Nov 20, 2026
12 checks passed
@raju-opti
Raju Ahmed (raju-opti) deleted the raju/fssdk-13487-client-meta-weakmap branch November 20, 2026 17:47
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