Skip to content

feat(js): publish flag evaluations to window global for session recording#445

Open
nicklasl wants to merge 3 commits into
mainfrom
nicklasl/flag-evaluation-global
Open

feat(js): publish flag evaluations to window global for session recording#445
nicklasl wants to merge 3 commits into
mainfrom
nicklasl/flag-evaluation-global

Conversation

@nicklasl

@nicklasl nicklasl commented Jun 15, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds publishFlagEvaluation that writes to window.__confidence.flags on MATCH evaluations, enabling the session recorder to observe flag assignments and emit csr:flagEvaluation plugin events.
  • Mirrors the pattern from confidence-sdk-js#369.

Test plan

  • Unit tests for publishFlagEvaluation (SSR safety, dedup, object preservation)
  • Existing test suites pass (59 tests)
  • TypeScript type check clean
  • Verified end-to-end in a local Next.js app: evaluated hawkflag and tutorial-flag via the WASM resolver, hydrated results to window.__confidence.flags on the client, and confirmed a Proxy-based mock session recorder observed the writes as csr:flagEvaluation events. Also tested lazy mount — hid one flag behind a button to verify the global is only written when the component mounts.

🤖 Generated with Claude Code

@nicklasl nicklasl force-pushed the nicklasl/flag-evaluation-global branch from 58d0a37 to 2cbd982 Compare June 16, 2026 14:07
nicklasl and others added 2 commits June 17, 2026 14:36
…ding

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Nicklas Lundin <nicklasl@spotify.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nicklasl nicklasl marked this pull request as ready for review June 17, 2026 13:38

@andreas-karlsson andreas-karlsson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm surprised to see this approach of putting the logic on the ConfidenceServerProviderLocal? It normally won't be used in the same JS engine as the session-recorder. I think we should consider moving this functionality to the react hooks.

The server provider runs where window is undefined, making the call a
no-op. Moving it to useFlagDetails fires it in the browser when the
hook mounts, which is where the session recorder lives.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nicklasl nicklasl force-pushed the nicklasl/flag-evaluation-global branch from 2cbd982 to afea10b Compare June 23, 2026 13:21
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