Skip to content

persist flag state and boot from last-known values#1193

Open
bpapillon wants to merge 1 commit into
mainfrom
feat/persist-flag-state-cache
Open

persist flag state and boot from last-known values#1193
bpapillon wants to merge 1 commit into
mainfrom
feat/persist-flag-state-cache

Conversation

@bpapillon
Copy link
Copy Markdown
Contributor

@bpapillon bpapillon commented Apr 30, 2026

Adds a persistent, context-keyed cache for flag check results (and plan) on top of the existing StoragePersister interface. For clients with a "pending" hook (e.g. schematic-react's useSchematicIsPending), the hook will resolve immediately if values are found in local storage rather than waiting for a response from the websocket connection, resulting in faster initial renders for subsequent loads.

@bpapillon bpapillon requested review from a team as code owners April 30, 2026 01:26
@bpapillon bpapillon changed the title feat(js): persist flag state and boot from last-known values persist flag state and boot from last-known values Apr 30, 2026
@bpapillon bpapillon marked this pull request as draft April 30, 2026 14:41
Comment thread js/src/index.ts Outdated
@bpapillon bpapillon marked this pull request as ready for review April 30, 2026 17:58
Comment thread js/src/index.spec.ts
});
});

describe("Persistent flag state cache", () => {
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.

We'll need to break up this test file at some point.

Comment thread js/src/index.ts Outdated
@bpapillon bpapillon force-pushed the feat/persist-flag-state-cache branch 3 times, most recently from c1ae3d5 to 77655cb Compare May 1, 2026 20:02
@bpapillon bpapillon requested a review from dontlaugh May 5, 2026 14:50
@bpapillon bpapillon force-pushed the feat/persist-flag-state-cache branch 6 times, most recently from 9a67ae5 to 2dfdc63 Compare May 5, 2026 18:32
Hydrate this.checks/planChecks from the StoragePersister at construction
and persist on every WS update so subsequent page loads can render with
cached values instead of fallbacks while the network reconciles. On
setContext, if the new context already has values in memory (e.g. just
hydrated from storage), pre-resolve isPending and notify listeners
synchronously rather than entering the pending state.

In-memory remains the source of truth for reads — storage is a hydration
source on boot and a durable mirror on writes. Resolution is still gated
on setContext/identify; nothing is exposed without a context. New
persistFlagState option (default true) opts out. LRU-capped at 10
contexts; storage failures degrade gracefully.
@bpapillon bpapillon force-pushed the feat/persist-flag-state-cache branch from 2dfdc63 to 949057e Compare May 23, 2026 14:47
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