Repository navigation
Conversation
…etEnv Next.js 16.5 drops cross-deployment durability for a "use cache" function whose module graph contains a computed process.env read. Every graph that imported @supabase/middleware had one, through std-env, which reads process.env by key when it loads. runtimeName now uses std-env's detection order inline, with no env reads, and std-env is only imported for its RuntimeName type. getEnv moves to its own module, and the build emits one file per source module, so pipeline, defineMiddleware and the built-in middleware no longer pull the computed read into a graph. getEnv keeps its signature and resolution order. Refs supabase#67 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been 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.
What changed
runtimeNameno longer importsstd-envat runtime. It runs the same checks asstd-env4.2 (Netlify,EdgeRuntime, the Workers user agent,fastly,Deno,Bun,process.versions.node, in that order) inline, with no environment reads.std-envstays a dependency for theRuntimeNametype, which is re-exported unchanged.getEnvmoves fromsrc/core/runtime.tstosrc/core/env.ts. It readsprocess.env[key]directly wherestd-env'senvproxy read it before. The signature, the resolution order (platform bindings, thenprocess.env, thenDeno.env.get) and the public exports are the same.runtime.tskeeps the captured platform object and exposes an internalgetPlatformBindingforenv.ts.tsdown.config.tssetsunbundle: true, so the build emits one file per source module and each entry file only re-exports. Theexportsmap and its paths are unchanged.src/core/README.mdand one path in the authoring guide.Why
Next.js 16.5 makes
"use cache"entries durable across deployments. Since vercel/next.js#102094, a cached function whose module graph contains a computedprocess.envread loses that durability, because Next.js can no longer list the variables the entry depends on.I confirmed the report in #67 with a Next.js 16.5.0 build and
TURBOPACK_PRINT_USE_CACHE_SUBTREE=1, using a page whose"use cache"function imports from this package:maindefineMiddlewarestd-env/dist/index.mjswith dynamic env accesspipeline,defineCompositestd-env/dist/index.mjswith dynamic env accesswithCorsfrom/corsstd-env/dist/index.mjswith dynamic env accessgetEnvstd-env/dist/index.mjswith dynamic env accessdist/core/env.mjswith dynamic env accessThe source of the read on
mainisstd-envitself: its module readsprocess.envby key at load time for CI and agent detection. MovinggetEnvalone was not enough. With the bundled output,pipelineanddefineCompositelive indist/index.mjs, which imports thegetEnvchunk, and Turbopack kept that import. With one file per module,dist/index.mjsis a pure re-export barrel, and withsideEffects: falseTurbopack leavescore/env.mjsout of any graph that does not usegetEnv.A graph that calls
getEnvstill carries a computed read. That is correct: the key is a runtime value, so Next.js cannot know which variable the entry depends on, and hiding the read would let a durable entry survive a change to that variable. The README now says so and points to reading a known variable by its literal name (process.env.SUPABASE_URL) inside durable entries, which Next.js tracks as part of the cache key. This matches the approach in supabase/server#236 forresolveEnv.Closes #67
Tests
src/core/env.test.tsloads every non-test source throughimport.meta.globand fails if any module other thanenv.tsreadsprocess.envor imports a value fromstd-env. It fails onmainforruntime.ts.pnpm typecheck,pnpm lint,pnpm format:check,pnpm test(137 tests),pnpm build,pnpm smoke,pnpm check-exports,pnpm typecheck:min,pnpm typecheck:consumer,pnpm test:bun,pnpm test:workers(reportsworkerd),pnpm docs(same 4 warnings asmain) andpnpm dlx jsr@0.14.3 publish --dry-run --allow-dirtypass locally.pnpm test:deno, because Deno is not installed here. CI covers it.Notes
require('@supabase/middleware')still loadscore/env.cjs. Next.js resolves theimportcondition for server code, which is the case above.unbundlechanges the files insidedist/(for exampledist/core/pipeline.mjsinstead of a hashed shared chunk). Nothing outside the package should import those paths, since theexportsmap does not list them.src/core/runtime.ts,src/index.tsandsrc/core/index.ts. The changes are independent, so whichever lands second needs a small rebase.@supabase/server's OAuth helpers callgetEnv, so their graphs keep a computed read until they read their variables by literal name. That belongs in supabase/server.🤖 Generated with Claude Code