Skip to content

fix: prefer live environment before offline fallback - #302

Open
flcrom wants to merge 2 commits into
Flagsmith:mainfrom
flcrom:fix/offline-fallback-195
Open

flcrom wants to merge 2 commits into
Flagsmith:mainfrom
flcrom:fix/offline-fallback-195

Conversation

@flcrom

@flcrom flcrom commented Sep 30, 2026

Copy link
Copy Markdown
  • I have read the Contributing Guide.
  • I have filled in the Changes and testing sections.

Changes

Contributes to #195.

Only use the offline handler immediately in offline mode. Otherwise, prefer the live environment and fall back to the handler if fetching fails. The fallback is not cached as a live environment, so the next call can recover. A failed refresh still keeps the last good live environment.

How did you test this code?

Added tests for live environment selection, initial failure and recovery, failed refresh, and missing offline handler. The first three fail on main and pass with the fix. Existing offline-mode tests still pass.

Passed the full source/coverage suite, ESM-built suite, CJS/ESM TypeScript build and touched-file Prettier checks on Node 22. A public-package smoke also checked concurrent environment/identity fetch deduplication and offline mode making no network call.

@flcrom
flcrom requested a review from a team as a code owner September 30, 2026 15:36
@flcrom
flcrom requested review from emyller and removed request for a team September 30, 2026 15:36
@emyller

emyller commented Oct 5, 2026

Copy link
Copy Markdown

Hello @flcrom and thanks for this contribution. I'm curious: have you run into #195 yourself?

@flcrom

flcrom commented Oct 10, 2026

Copy link
Copy Markdown
Author

Thanks for looking. I found it through #195, not in production. I reproduced it against a mock server (offlineHandler set without offlineMode, server available): on main the client never contacts the server, with this change it does, and it falls back to the offline file when the server is down. The PR's tests cover the same cases.

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