Skip to content

fix(browser-sdk): start automatic feedback when the first user ID arrives - #848

Open
roncohen wants to merge 2 commits into
mainfrom
fix/auto-feedback-late-user
Open

roncohen wants to merge 2 commits into
mainfrom
fix/auto-feedback-late-user

Conversation

@roncohen

@roncohen roncohen commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A Browser SDK client only set up automatic feedback surveys if it was created with a user. If an app created the client before sign-in and set the user later with setContext() or updateUser(), surveys never showed. This affects the React, Vue and React Native SDKs too, since they use the Browser client.

Fix

  • When a user ID first appears, the client now sets up automatic feedback with the same options it would have used at startup (enableAutoFeedback, the prompt handler, position and translations). Offline, server-side and mobile behavior are unchanged.
  • If the client is already running, it opens the live connection that delivers survey prompts, or reopens it with the new user if live updates already had one open.
  • If the user is set before initialize(), initialize() opens the connection as usual.

Tests

New cases in test/feedback-context.test.ts:

  • a client with no user that gets one later, with live updates off and on;
  • a user set before initialize();
  • enableAutoFeedback: false staying off.

All three cases fail without the fix. The Browser SDK suite passes, apart from the two release tests that need the React and Node packages built locally.

OpenFeature Browser provider

#847 made the provider stop its client and start a new one when the first user ID arrived, so that feedback would start. With this fix, the provider just updates the existing client's context, so that restart and its bootstrap handling are removed.

@reflag-review reflag-review Bot 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.

Risk: medium

1 actionable finding.

// Before initialize(), it opens the connection itself. With live updates
// on, the connection already exists and is reopened below.
if (
!this.pubSubInit &&

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P2] Defer feedback startup whenever the client is stopped

When an anonymous client with enableLiveFlagUpdates: true is initialized and then stopped, stop() closes the SSE channel but retains pubSubInit. If its first user subsequently arrives through setContext() or updateUser(), this guard fails because pubSubInit is still set. The newly created feedback instance then falls through to the existing reinitialization branch and reopens SSE, enabling surveys and connection retries despite the explicit stop. Previously, an anonymous client's identity update returned without opening a connection. Check the idle/stopped state independently of pubSubInit and defer opening the channel until a subsequent initialize().

@roncohen
roncohen force-pushed the fix/auto-feedback-late-user branch from 50b2d4f to 6cce24d Compare November 30, 2026 21:29

@reflag-review reflag-review Bot 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.

Risk: medium

no actionable findings

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant