Skip to content

Commit 4b567eb

Browse files
authored
Use deterministic env for public env vars (#82859)
### What? For persistent caching the order of defined variables need to be deterministic.
1 parent 3fffe60 commit 4b567eb

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

packages/next/src/lib/static-env.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@ function errorIfEnvConflicted(config: NextConfigComplete, key: string) {
1515
* Collects all environment variables that are using the `NEXT_PUBLIC_` prefix.
1616
*/
1717
export function getNextPublicEnvironmentVariables() {
18-
const defineEnv: Record<string, string | undefined> = {}
18+
const defineEnv: [string, string | undefined][] = []
1919
for (const key in process.env) {
2020
if (key.startsWith('NEXT_PUBLIC_')) {
2121
const value = process.env[key]
2222
if (value != null) {
23-
defineEnv[`process.env.${key}`] = value
23+
defineEnv.push([`process.env.${key}`, value])
2424
}
2525
}
2626
}
27-
return defineEnv
27+
defineEnv.sort((a, b) => a[0].localeCompare(b[0]))
28+
return Object.fromEntries(defineEnv)
2829
}
2930

3031
/**

0 commit comments

Comments
 (0)