Vite + React example for Split / Harness FME with OpenFeature: two named clients (anon-web, user-web) on one page.
Repository: github.com/Split-Community/react-openfeature-multiple-clients
Uses the Harness OpenFeature provider for React (@splitsoftware/openfeature-web-split-provider + @splitsoftware/splitio-browserjs).
src/main.tsx runs bootstrapOpenFeature() before createRoot(…).render so three problems do not show up on first paint:
-
Provider readiness — Until Split finishes initializing, OpenFeature can be
NOT_READYand flag hooks error.setProviderAndWaitwaits for each domain provider before the UI mounts. -
Domain context timing —
useContextMutator().setContextruns inuseEffect, which is after the first render. If you read flags immediately, OpenFeature may log “Unable to find context” foranon-web/user-weband evaluations can misbehave. Bootstrap callsOpenFeature.setContext(domain, …)up front so context exists before any hook runs. -
Split customer keys — One
OpenFeatureSplitProvidershares a single Split SDK client; changing OpenFeaturetargetingKeyalone does not switch that client forgetTreatment. This app registers one OpenFeature provider per domain, each with its ownSplitFactorycore.key(anonymousvsuser-1), so anonymous and signed-in panels actually hit Split as different users.
- Node.js (LTS) and npm
- A browser (client-side) SDK key from Harness FME / Split
git clone https://github.com/Split-Community/react-openfeature-multiple-clients.git
cd react-openfeature-multiple-clients
npm installPreferred: .env.local in the project root:
VITE_SPLIT_BROWSER_KEY=your-client-side-sdk-keyRestart npm run dev after editing env files.
Or set the fallback in src/openfeature-bootstrap.ts (authKey / <YOUR_AUTHORIZATION_KEY>).
Do not commit real keys to a public repo.
| Flag key | UI area | OpenFeature domain |
|---|---|---|
anon-flag |
Anonymous panel | anon-web |
user-flag |
Signed-in panel | user-web |
Create both in the environment that matches your browser key. String treatments work with useFlag(…, defaultString).
npm run devIn dev, bootstrap also enables OpenFeature.setLogger(console), lightweight evaluation hooks, and Split debug on the factories. Use the browser console (show verbose logs if needed).
npm run build
npm run previewFrom open-feature/js-sdk root:
npm install
npm run dev --workspace=react-openfeature-multiple-clients