Repository navigation
Conversation
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>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/runtimeexportsruntime, 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 inAsyncLocalStorage, also for work that ends afternextreturns.flag(request)in the Pages Router or in middleware;onInvoke;headers()/cookies()of Next.js, orgetRequestEvent()of SvelteKit.RequestScopefor each request, keyed by itsheadersobject (as on north-star). It holds the flag-value cache, theidentifyargument, the overrides (read one time for each request) and the key ofdedupe. All three ways to get a request lead to the same scope for the same headers.createFlagsRequestnormalizes what a framework gives:HeadersorIncomingHttpHeaders, cookies from theCookieheader when the framework gives none, and the URL read only when it is used.evaluate.tsgets smaller (−290 lines). Its separate WeakMaps (evaluationCache,identifyArgsMap, the header and cookie caches) and its ownAsyncLocalStorage(bulkStore) are replaced by the scope.createHandlewrapsresolve()inruntime.onInvoke, so a flag does not needgetRequestEvent()while the hook handles the request.Not in this PR
These come with the later full runtime:
onInit/onShutdownand the provider lifecycle,setGetRequest/setRethrow, the config files, sources, OpenFeature and the context chain. TheFrameworkBindingcontract does not change.Changes in behavior
decidereceives 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 andcreateFlagsRequest. Types andattwpass.@flags-sdk/sveltekit: 16 unit tests, with a new test that a flag in the handle hook works whengetRequestEvent()throws.@flags-sdk/next: 25 unit tests.tests/next-16: Playwright 8/8.tests/sveltekit-e2e: 7/8. The failing test is the knownprecomputed"client-side navigation, new visitor", which also fails onstandard(see v5: the 'use flags' directive and the manifest of the flags #653).🤖 Generated with Claude Code