Skip to content

feat: add ability to bootstrap flags on server and populate clients#475

Merged
Swiftwork merged 63 commits intomainfrom
feat/bootstrapped-flags
Oct 2, 2025
Merged

feat: add ability to bootstrap flags on server and populate clients#475
Swiftwork merged 63 commits intomainfrom
feat/bootstrapped-flags

Conversation

@Swiftwork
Copy link
Contributor

@Swiftwork Swiftwork commented Sep 12, 2025

This pull request introduces support for bootstrapping the Reflag browser SDK with pre-fetched flag data, enabling faster initialization for server-side rendered applications. It also refactors context management for improved efficiency, adds SDK lifecycle methods, and updates documentation and tooling. The most important changes are grouped below.

Bootstrapping and SSR support:

  • Added support for initializing the SDK with bootstrappedFlags, allowing applications to avoid the initial network request for flags and improve performance in server-side rendering scenarios. This includes updates to InitOptions, Config, and initialization logic in ReflagClient. [1] [2] [3] [4] [5]
  • Updated the documentation (README.md) with clear instructions and examples for using bootstrapped flags in SSR setups.

Context and state management improvements:

  • Refactored context update methods (updateUser, updateCompany, updateOtherContext, updateContext) to use deep equality checks and avoid unnecessary updates, improving efficiency and reducing redundant network calls.
  • Added new methods to get and update context (getContext, updateContext) and to update flags directly (updateFlags). [1] [2]

SDK lifecycle management:

  • Introduced SDK state management with internal state tracking (idle, initializing, initialized, stopped) and corresponding methods (initialize, stop, getState). [1] [2]

Tooling and dependencies:

  • Added fast-equals dependency for deep equality checks and updated scripts in package.json for improved test and build workflows. [1] [2]
  • Updated .vscode/settings.json for consistent formatting and improved search excludes. [1] [2]

Examples and documentation:

  • Updated example code and HTML to demonstrate bootstrapped flag usage and improved flag visibility logic. [1] [2] [3] [4]

These changes collectively enhance SDK performance, developer experience, and maintainability.

@Swiftwork Swiftwork self-assigned this Sep 12, 2025
@Swiftwork Swiftwork added the enhancement New feature or request label Sep 12, 2025
Copy link
Contributor

@roncohen roncohen left a comment

Choose a reason for hiding this comment

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

would be nice with examples of how to use boostrapped flags in the browser, react and vue READMEs. Tip for next time: when building libraries like these it often makes sense to start with the README examples before writing the code to make sure the DX drives the implementation instead of the other way around.

@Swiftwork Swiftwork marked this pull request as ready for review September 25, 2025 11:54
@roncohen roncohen requested a review from Copilot September 26, 2025 07:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request introduces comprehensive support for bootstrapping the Reflag browser SDK with pre-fetched flag data, enabling faster initialization for server-side rendered applications. It also refactors context management for improved efficiency, adds SDK lifecycle methods, and updates documentation and tooling.

  • Adds ReflagBootstrappedProvider and ReflagClientProvider components for Vue and React SDKs
  • Implements deep equality checks to prevent unnecessary context updates and API calls
  • Introduces SDK state management with lifecycle methods (initialize, stop, getState)

Reviewed Changes

Copilot reviewed 71 out of 77 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/vue-sdk/src/ReflagBootstrappedProvider.vue New component for bootstrapping Vue apps with pre-fetched flags
packages/vue-sdk/src/ReflagClientProvider.vue New component for using pre-initialized clients in Vue apps
packages/vue-sdk/src/hooks.ts Refactored hooks with new useReflagClient and useClientEvent composables
packages/react-sdk/src/index.tsx Major refactor adding bootstrap providers and improving context handling
packages/browser-sdk/src/client.ts Enhanced client with state management, deep equality checks, and bootstrap support
packages/node-sdk/src/client.ts Added getFlagsForBootstrap method for server-side flag pre-fetching

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@Swiftwork Swiftwork added this pull request to the merge queue Oct 2, 2025
Merged via the queue into main with commit 445631d Oct 2, 2025
6 checks passed
@Swiftwork Swiftwork deleted the feat/bootstrapped-flags branch October 2, 2025 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants