Skip to content

feat(flags): share the evaluation pipeline + SvelteKit parity (2/3)#413

Draft
dferber90 wants to merge 1 commit into
shared/extractionfrom
shared/evaluation
Draft

feat(flags): share the evaluation pipeline + SvelteKit parity (2/3)#413
dferber90 wants to merge 1 commit into
shared/extractionfrom
shared/evaluation

Conversation

@dferber90

Copy link
Copy Markdown
Collaborator

Stacked PR 2 of 3 · base: shared/extraction (#412)

Lifts the per-request evaluation pipeline into src/shared/ and points both frameworks at it, so behavior is defined once. The Next-specific isInternalNextError check becomes an injected isFrameworkError hook on applyResult.

  • shared/evaluation.ts — headers-keyed evaluationCache (+ getUsedFlags), getEntities + identify-args dedupe, and applyResult (cache → override → produce → defaultValue/error → report)
  • shared/flag-meta.tsresolveAdapter, getDecide (with adapter validation), getIdentify, getOrigin

Behavior change (version bump): SvelteKit's flag() now runs through this pipeline, reaching parity with Next. SvelteKit now:

  • falls back to defaultValue when decide throws or returns undefined
  • honors config.reportValue / adapter.config.reportValue
  • resolves adapter.origin (value or (key) => origin)
  • dedupes via the shared headers-keyed cache (replacing per-store usedFlags/identifiers); transformPageChunk reads used flags via getUsedFlags()
  • getProviderData emits defaultValue + declaredInCode

Adds defaultValue? to the SvelteKit Flag type (additive) and 9 parity tests. Next's public .d.ts is unchanged.

Verification

121/121 tests pass · type-check · biome · attw green · next.d.ts byte-identical · @flags-sdk/vercel builds.

🤖 Generated with Claude Code

Lifts the per-request evaluation pipeline into src/shared/ and points both
frameworks at it, so behavior is defined once. The Next-specific
isInternalNextError check becomes an injected `isFrameworkError` hook on
applyResult (Next passes it; SvelteKit defaults to none).

- shared/evaluation.ts: evaluationCache (+ getUsedFlags accessor), getEntities
  + identify-args dedupe, and applyResult (cache -> override -> produce ->
  defaultValue/error -> report).
- shared/flag-meta.ts: resolveAdapter, getDecide (with adapter validation),
  getIdentify, getOrigin.

SvelteKit's flag() now runs through this pipeline. This is a behavior change
that brings it to parity with Next — SvelteKit now:
- falls back to defaultValue when decide throws or returns undefined
- honors config.reportValue / adapter.config.reportValue
- resolves adapter.origin (value or (key) => origin)
- dedupes evaluation via the shared headers-keyed cache (replacing the
  per-store usedFlags/identifiers maps); createHandle's transformPageChunk
  reads used flags via getUsedFlags()
- getProviderData emits defaultValue + declaredInCode

Adds `defaultValue?` to the SvelteKit Flag type (additive) and 9 parity tests.
Next's public .d.ts is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
flags-playground Ready Ready Preview, Comment Jun 25, 2026 1:34pm
shirt-shop Ready Ready Preview, Comment Jun 25, 2026 1:34pm
shirt-shop-api Ready Ready Preview, Comment Jun 25, 2026 1:34pm

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