Skip to content

v5: one runtime for Next.js and SvelteKit - #654

Open
dferber90 wants to merge 2 commits into
use-flags-manifestfrom
v5-runtime
Open

dferber90 wants to merge 2 commits into
use-flags-manifestfrom
v5-runtime

Conversation

@dferber90

Copy link
Copy Markdown
Collaborator

Stacked on #653. This PR is the groundwork for the runtime of north-star: Next.js and SvelteKit now go through one common runtime. A later PR expands it into the full OpenFeature runtime with sources, and that diff will be smaller. The rules of Next.js do not change.

What it does

  • flags/runtime exports runtime, with the shape of north-star (Runtime, onInvoke, FlagsRequest, FlagsRequestInit).
  • runtime.onInvoke(request, next) is for frameworks with a middleware that wraps the handler. It keeps the request in AsyncLocalStorage, also for work that ends after next returns.
  • Where a flag gets its request:
    1. the request that the call passes, e.g. flag(request) in the Pages Router or in middleware;
    2. the request of onInvoke;
    3. the framework binding: headers()/cookies() of Next.js, or getRequestEvent() of SvelteKit.
  • One RequestScope for each request, keyed by its headers object (as on north-star). It holds the flag-value cache, the identify argument, the overrides (read one time for each request) and the key of dedupe. All three ways to get a request lead to the same scope for the same headers.
  • createFlagsRequest normalizes what a framework gives: Headers or IncomingHttpHeaders, cookies from the Cookie header when the framework gives none, and the URL read only when it is used.
  • evaluate.ts gets smaller (−290 lines). Its separate WeakMaps (evaluationCache, identifyArgsMap, the header and cookie caches) and its own AsyncLocalStorage (bulkStore) are replaced by the scope.
  • SvelteKit: createHandle wraps resolve() in runtime.onInvoke, so a flag does not need getRequestEvent() while the hook handles the request.

Not in this PR

These come with the later full runtime: onInit/onShutdown and the provider lifecycle, setGetRequest/setRethrow, the config files, sources, OpenFeature and the context chain. The FrameworkBinding contract does not change.

Changes in behavior

  • The overrides cookie is read one time for each request, not one time for each flag call. Its expiry is still checked.
  • When a framework gives headers but no cookies (SvelteKit, or a passed request), the headers that decide receives are now sealed (read-only).
  • getEvaluatedFlagValues(request) now also finds the values of flags that were called with a passed request. Before, those values were stored under the sealed copy of the headers, so the lookup missed them.

Tests

  • flags: 319 unit tests. The 306 existing tests pass without changes, and 13 new tests cover the runtime and createFlagsRequest. Types and attw pass.
  • @flags-sdk/sveltekit: 16 unit tests, with a new test that a flag in the handle hook works when getRequestEvent() throws.
  • @flags-sdk/next: 25 unit tests.
  • tests/next-16: Playwright 8/8.
  • tests/sveltekit-e2e: 7/8. The failing test is the known precomputed "client-side navigation, new visitor", which also fails on standard (see v5: the 'use flags' directive and the manifest of the flags #653).

🤖 Generated with Claude Code

dferber90 and others added 2 commits November 27, 2026 12:56
flags/runtime exports the runtime. runtime.onInvoke(request, next) gives
the flags of a request its state, for frameworks with a middleware which
wraps the handler. A flag gets its request from the call, then from
onInvoke, then from the framework binding.

Each request has one RequestScope, keyed by its headers object: the cache
of the flag values, the argument of identify, the overrides, and the key
of dedupe. They replace the separate WeakMaps and the AsyncLocalStorage
of evaluate(). The rules of Next.js do not change.

Co-Authored-By: Claude <noreply@anthropic.com>
…time

createHandle wraps resolve() in runtime.onInvoke, so that a flag does not
need getRequestEvent() while the hook handles the request.

Co-Authored-By: Claude <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
flags-playground Ready Ready Preview, v0 Nov 27, 2026 10:58am UTC
flags-sdk-dev Ready Ready Preview, v0 Nov 27, 2026 10:58am UTC
flags-sdk-flagsmith Ready Ready Preview, v0 Nov 27, 2026 10:58am UTC
flags-sdk-growthbook Ready Ready Preview, v0 Nov 27, 2026 10:58am UTC
flags-sdk-launchdarkly Ready Ready Preview, v0 Nov 27, 2026 10:58am UTC
flags-sdk-openfeature Ready Ready Preview, v0 Nov 27, 2026 10:58am UTC
flags-sdk-posthog Ready Ready Preview, v0 Nov 27, 2026 10:58am UTC
flags-sdk-reflag Ready Ready Preview, v0 Nov 27, 2026 10:58am UTC
flags-sdk-snippets Ready Ready Preview, v0 Nov 27, 2026 10:58am UTC
flags-sdk-statsig Ready Ready Preview, v0 Nov 27, 2026 10:58am UTC
flags-sdk-sveltekit-snippets Ready Ready Preview, v0 Nov 27, 2026 10:58am UTC
shirt-shop Ready Ready Preview, v0 Nov 27, 2026 10:58am UTC
shirt-shop-api Ready Ready Preview, v0 Nov 27, 2026 10:58am UTC

This branch was successfully deployed

14 active deployments
Preview – flags-sdk-dev — e1ef3018 Deployed Nov 27, 2026 by vercel[bot]
Preview – flags-sdk-flagsmith — e1ef3018 Deployed Nov 27, 2026 by vercel[bot]
Preview – flags-sdk-vercel — e1ef3018 Deployed Nov 27, 2026 by vercel[bot]
Preview – flags-sdk-sveltekit-snippets — e1ef3018 Deployed Nov 27, 2026 by vercel[bot]
Preview – flags-sdk-growthbook — e1ef3018 Deployed Nov 27, 2026 by vercel[bot]
Preview – flags-sdk-reflag — e1ef3018 Deployed Nov 27, 2026 by vercel[bot]
Preview – flags-sdk-launchdarkly — e1ef3018 Deployed Nov 27, 2026 by vercel[bot]
Preview – shirt-shop — e1ef3018 Deployed Nov 27, 2026 by vercel[bot]
Preview – flags-sdk-posthog — e1ef3018 Deployed Nov 27, 2026 by vercel[bot]
Preview – flags-sdk-openfeature — e1ef3018 Deployed Nov 27, 2026 by vercel[bot]
Preview – flags-sdk-statsig — e1ef3018 Deployed Nov 27, 2026 by vercel[bot]
Preview – flags-sdk-snippets — e1ef3018 Deployed Nov 27, 2026 by vercel[bot]
Preview – flags-playground — e1ef3018 Deployed Nov 27, 2026 by vercel[bot]
Preview – shirt-shop-api — e1ef3018 Deployed Nov 27, 2026 by vercel[bot]
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.

1 participant