-
Notifications
You must be signed in to change notification settings - Fork 218
Open
Description
Problem
Every App Router request in vinext runs through 5-6 nested AsyncLocalStorage.run() calls, each from a different shim module:
runWithHeadersContext(headers.ts)runWithNavigationContext(navigation-state.ts)_runWithCacheState(cache.ts)runWithPrivateCache(cache-runtime.ts)runWithFetchCache(fetch-cache.ts)runWithExecutionContext(request-context.ts) — conditional, Workers only
Each ALS scope push/pop has measurable cost on Workers isolates. For simple static routes that don't use headers, cookies, or caching, all contexts are created unnecessarily.
Solution
Consolidate into a single UnifiedRequestContext backed by one ALS instance. Each shim module checks isInsideUnifiedScope() first and reads its sub-fields from the unified store, falling back to its own standalone ALS for backward compatibility (SSR environment, Pages Router).
Scope
Phase 1 (this issue)
- App Router only — main request handler + ISR background regeneration
- Dual-path migration: unified scope first, standalone ALS fallback
- No changes to per-call ALS scopes (
cacheContextStorage,_unstableCacheAls)
Phase 2 (follow-up)
- Pages Router consolidation (
router-state,head-state) - Production server (
prod-server.ts) alignment
Related
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels