next.js
next.js copied to clipboard
Stale environment variable values when accessing from middleware
Link to the code that reproduces this issue
To Reproduce
- Define an environment variable on
.env.local - Access it on
middleware.ts, log it to the console - Access it on
page.ts(must be a server component), log it to the console - Refresh page, see the logs
- Update env var on
.env.local - Refresh page, see the logs. Verify that the values aren't matching 👀
Current vs. Expected behavior
Current behavior: Environment variables get stale on the middleware side when updating env var, as the value differs from the latest that can be accessed on the application side.
Expected behavior: Values must change on both sides, both being fresh. Currently, we're facing an issue, on this PR, where the same env var value is used for encryption on the middleware runtime and decryption on the application runtime, therefore those must be in sync, especially when developing locally.
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 23.3.0: Wed Dec 20 21:30:59 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6030
Available memory (MB): 18432
Available CPU cores: 11
Binaries:
Node: 20.12.2
npm: 10.5.0
Yarn: 1.22.22
pnpm: 9.2.0
Relevant Packages:
next: 14.2.4 // Latest available version is detected (14.2.4).
eslint-config-next: 14.2.4
react: 18.3.1
react-dom: 18.3.1
typescript: 5.4.5
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Middleware, Runtime
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
No response