Skip to content

feat(sdk): add per-flag value-change events - #770

Open
roncohen wants to merge 12 commits into
mainfrom
feat/per-flag-updated-event
Open

roncohen wants to merge 12 commits into
mainfrom
feat/per-flag-updated-event

Conversation

@roncohen

@roncohen roncohen commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add a per-flag value-change event and use it to avoid unnecessary React rerenders and check telemetry during metadata-only flag refreshes.

  • Add flagUpdated with { key, flag }. Publish each initial flag during initialize(). Bootstrapped flags are published after applying cached overrides, without fetching or duplicate notifications. Subsequent events fire only when the effective enabled value (including local overrides), config key/payload, or flag presence changes. flag is undefined on removal.
  • Preserve flagsUpdated and its deprecated alias for raw-data and metadata subscribers. Lead the browser, React, and Vue event docs with flagUpdated, and retain flagsUpdated for metadata-only refreshes (identical raw results are still skipped).
  • Have React useFlag(key) subscribe only to changes for its own key. Keep config references stable and use current evaluation metadata when emitting check telemetry.
  • Reuse getFlags() for initial state; no additional public getter API.
  • Add documentation, runtime/type coverage, and minor changesets for the browser and React SDKs.

Review feedback fixes

  • Queue reentrant flagUpdated batches until the current batch finishes for all listeners. Cover override changes, multi-flag batches, bootstrap publication, and recovery from throwing listeners.

Unrelated fixes are split into #771 (Management SDK README) and #772 (context update types).

Validation

  • Browser SDK: 221 tests passed, excluding test/sse.test.ts.
  • React SDK: 79 tests passed.
  • Vue SDK: 13 tests passed.
  • Browser source TypeScript check and production bundles passed, with declaration generation restricted to source files.
  • React and Vue type tests and production builds passed.
  • Oxlint, formatting checks, and git diff --check passed.

Local testing limitation

The local installation uses Vitest 3.2.6, which has known constructor-mock incompatibilities in the existing SSE tests (seven failures). That file was excluded from the local browser test run; no SSE source/tests or repository test configuration were changed.

@roncohen
roncohen marked this pull request as ready for review October 15, 2026 11:19
Copilot AI balanced review requested due to automatic review settings October 15, 2026 11:19

Copilot AI 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.

🟡 Changes recommended

React config reads can misreport telemetry, and cached overrides can trigger unnecessary bootstrap rerenders.

2 open findings
What changed in this PR

Adds per-flag value-change events to the browser SDK and uses them to reduce unnecessary React updates.

Changes:

  • Publish initial and changed flag values while preserving raw-data events.
  • Subscribe React consumers by flag key and use current check metadata.
  • Add documentation, runtime/type coverage, and release notes.
File Description
packages/​vue-sdk/​README.md Document per-flag subscriptions.
packages/​react-sdk/​tsconfig.type-tests.json Include new event type tests.
packages/​react-sdk/​test/​flag-updated.test.tsx Cover subscriptions, rendering, and telemetry.
packages/​react-sdk/​test/​flag-updated-types.tsx Validate event types.
packages/​react-sdk/​src/​index.tsx Add key-specific subscriptions and current telemetry reads.
packages/​react-sdk/​README.md Explain event behavior.
packages/​browser-sdk/​test/​flagUpdated.test.ts Cover initialization, changes, and reentrant delivery.
packages/​browser-sdk/​src/​index.ts Export the event type.
packages/​browser-sdk/​src/​hooksManager.ts Register the new event.
packages/​browser-sdk/​src/​flag/​flagValueChanged.ts Compare effective flag values.
packages/​browser-sdk/​src/​flag/​flags.ts Publish and queue per-flag events.
packages/​browser-sdk/​src/​client.ts Forward events to client listeners.
packages/​browser-sdk/​README.md Document value and raw-data subscriptions.
.changeset/​quiet-flag-value-updates.md Record browser and React minor releases.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

if (
current.client !== client ||
current.key !== key ||
current.flag !== flag
Comment thread packages/react-sdk/src/index.tsx Outdated
Copilot AI balanced review requested due to automatic review settings October 15, 2026 12:30

Copilot AI 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.

🟢 Approval recommended

No unresolved issues remain, and regression coverage addresses initialization, reentrant delivery, and React snapshot consistency.

1 open finding
1 resolved since last review

🧠 Review effort: Balanced

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