Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
26cfeb85
Unverified
Commit
26cfeb85
authored
Apr 16, 2026
by
Niklas Mischkulnig
Committed by
GitHub
Apr 16, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow overriding outputHashSalt in modifyConfig (#92856)
parent
f4972228
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
83 additions
and
75 deletions
+83
-75
project.rs
crates/next-api/src/project.rs
+3
-27
project_asset_hashes_manifest.rs
crates/next-api/src/project_asset_hashes_manifest.rs
+4
-1
main.rs
crates/next-build-test/src/main.rs
+0
-1
next_config.rs
crates/next-core/src/next_config.rs
+14
-0
project.rs
crates/next-napi-bindings/src/next_api/project.rs
+0
-12
generated-native.d.ts
packages/next/src/build/swc/generated-native.d.ts
+0
-8
index.ts
packages/next/src/build/turbopack-analyze/index.ts
+0
-1
impl.ts
packages/next/src/build/turbopack-build/impl.ts
+0
-1
webpack-config.ts
packages/next/src/build/webpack-config.ts
+4
-2
index.ts
...next/src/build/webpack/loaders/next-image-loader/index.ts
+5
-4
config-shared.ts
packages/next/src/server/config-shared.ts
+0
-3
config.ts
packages/next/src/server/config.ts
+6
-4
hot-reloader-turbopack.ts
packages/next/src/server/dev/hot-reloader-turbopack.ts
+0
-1
next-rs-api.test.ts
test/development/basic/next-rs-api.test.ts
+0
-2
hash-salt.test.ts
test/production/app-dir/hash-salt/hash-salt.test.ts
+31
-8
my-adapter.mjs
test/production/app-dir/hash-salt/my-adapter.mjs
+15
-0
next.config.js
test/production/app-dir/hash-salt/next.config.js
+1
-0
No files found.
crates/next-api/src/project.rs
View file @
26cfeb85
...
@@ -370,11 +370,6 @@ pub struct ProjectOptions {
...
@@ -370,11 +370,6 @@ pub struct ProjectOptions {
/// Whether server-side HMR is enabled (disabled with --no-server-fast-refresh).
/// Whether server-side HMR is enabled (disabled with --no-server-fast-refresh).
pub
server_hmr
:
bool
,
pub
server_hmr
:
bool
,
/// A salt to mix into chunk and asset content hashes, allowing users to
/// force new filenames without changing file content. Empty string means
/// no salt.
pub
hash_salt
:
RcStr
,
}
}
#[derive(Default)]
#[derive(Default)]
...
@@ -425,9 +420,6 @@ pub struct PartialProjectOptions {
...
@@ -425,9 +420,6 @@ pub struct PartialProjectOptions {
/// Debug build paths for selective builds.
/// Debug build paths for selective builds.
/// When set, only routes matching these paths will be included in the build.
/// When set, only routes matching these paths will be included in the build.
pub
debug_build_paths
:
Option
<
DebugBuildPaths
>
,
pub
debug_build_paths
:
Option
<
DebugBuildPaths
>
,
/// An optional salt to mix into chunk and asset content hashes.
pub
hash_salt
:
Option
<
RcStr
>
,
}
}
#[derive(
#[derive(
...
@@ -687,7 +679,6 @@ impl ProjectContainer {
...
@@ -687,7 +679,6 @@ impl ProjectContainer {
no_mangling
,
no_mangling
,
write_routes_hashes_manifest
,
write_routes_hashes_manifest
,
debug_build_paths
,
debug_build_paths
,
hash_salt
,
}
=
options
;
}
=
options
;
let
mut
new_options
=
this
let
mut
new_options
=
this
...
@@ -738,9 +729,6 @@ impl ProjectContainer {
...
@@ -738,9 +729,6 @@ impl ProjectContainer {
if
let
Some
(
debug_build_paths
)
=
debug_build_paths
{
if
let
Some
(
debug_build_paths
)
=
debug_build_paths
{
new_options
.debug_build_paths
=
Some
(
debug_build_paths
);
new_options
.debug_build_paths
=
Some
(
debug_build_paths
);
}
}
if
let
Some
(
hash_salt
)
=
hash_salt
{
new_options
.hash_salt
=
hash_salt
;
}
// TODO: Handle mode switch, should prevent mode being switched.
// TODO: Handle mode switch, should prevent mode being switched.
let
watch
=
new_options
.watch
;
let
watch
=
new_options
.watch
;
...
@@ -823,7 +811,6 @@ impl ProjectContainer {
...
@@ -823,7 +811,6 @@ impl ProjectContainer {
let
deferred_entries
;
let
deferred_entries
;
let
is_persistent_caching_enabled
;
let
is_persistent_caching_enabled
;
let
server_hmr
;
let
server_hmr
;
let
hash_salt
;
{
{
let
options
=
self
.options_state
.get
();
let
options
=
self
.options_state
.get
();
let
options
=
options
let
options
=
options
...
@@ -852,7 +839,6 @@ impl ProjectContainer {
...
@@ -852,7 +839,6 @@ impl ProjectContainer {
deferred_entries
=
options
.deferred_entries
.clone
()
.unwrap_or_default
();
deferred_entries
=
options
.deferred_entries
.clone
()
.unwrap_or_default
();
is_persistent_caching_enabled
=
options
.is_persistent_caching_enabled
;
is_persistent_caching_enabled
=
options
.is_persistent_caching_enabled
;
server_hmr
=
options
.server_hmr
;
server_hmr
=
options
.server_hmr
;
hash_salt
=
options
.hash_salt
.clone
();
}
}
let
root_path
=
ResolvedVc
::
cell
(
root_path_str
);
let
root_path
=
ResolvedVc
::
cell
(
root_path_str
);
...
@@ -884,7 +870,6 @@ impl ProjectContainer {
...
@@ -884,7 +870,6 @@ impl ProjectContainer {
deferred_entries
,
deferred_entries
,
is_persistent_caching_enabled
,
is_persistent_caching_enabled
,
server_hmr
,
server_hmr
,
hash_salt
,
}
}
.cell
())
.cell
())
}
}
...
@@ -988,10 +973,6 @@ pub struct Project {
...
@@ -988,10 +973,6 @@ pub struct Project {
/// Whether server-side HMR is enabled (disabled with --no-server-fast-refresh).
/// Whether server-side HMR is enabled (disabled with --no-server-fast-refresh).
server_hmr
:
bool
,
server_hmr
:
bool
,
/// A salt to mix into chunk and asset content hashes. Empty string means
/// no salt.
hash_salt
:
RcStr
,
}
}
#[turbo_tasks
::
value]
#[turbo_tasks
::
value]
...
@@ -1249,11 +1230,6 @@ impl Project {
...
@@ -1249,11 +1230,6 @@ impl Project {
Vc
::
cell
(
self
.no_mangling
)
Vc
::
cell
(
self
.no_mangling
)
}
}
#[turbo_tasks
::
function]
pub
(
crate
)
fn
hash_salt
(
&
self
)
->
Vc
<
RcStr
>
{
Vc
::
cell
(
self
.hash_salt
.clone
())
}
#[turbo_tasks
::
function]
#[turbo_tasks
::
function]
pub
(
super
)
async
fn
execution_context
(
self
:
Vc
<
Self
>
)
->
Result
<
Vc
<
ExecutionContext
>>
{
pub
(
super
)
async
fn
execution_context
(
self
:
Vc
<
Self
>
)
->
Result
<
Vc
<
ExecutionContext
>>
{
let
node_root
=
self
.node_root
()
.owned
()
.await
?
;
let
node_root
=
self
.node_root
()
.owned
()
.await
?
;
...
@@ -1609,7 +1585,7 @@ impl Project {
...
@@ -1609,7 +1585,7 @@ impl Project {
debug_ids
:
self
.next_config
()
.turbopack_debug_ids
(),
debug_ids
:
self
.next_config
()
.turbopack_debug_ids
(),
should_use_absolute_url_references
:
self
.next_config
()
.inline_css
(),
should_use_absolute_url_references
:
self
.next_config
()
.inline_css
(),
css_url_suffix
,
css_url_suffix
,
hash_salt
:
self
.hash_salt
()
.to_resolved
()
.await
?
,
hash_salt
:
self
.
next_config
()
.output_
hash_salt
()
.to_resolved
()
.await
?
,
cross_origin
:
self
.next_config
()
.cross_origin
(),
cross_origin
:
self
.next_config
()
.cross_origin
(),
}))
}))
}
}
...
@@ -1645,7 +1621,7 @@ impl Project {
...
@@ -1645,7 +1621,7 @@ impl Project {
.await
?
,
.await
?
,
asset_prefix
:
self
.next_config
()
.computed_asset_prefix
()
.owned
()
.await
?
,
asset_prefix
:
self
.next_config
()
.computed_asset_prefix
()
.owned
()
.await
?
,
css_url_suffix
,
css_url_suffix
,
hash_salt
:
self
.hash_salt
()
.to_resolved
()
.await
?
,
hash_salt
:
self
.
next_config
()
.output_
hash_salt
()
.to_resolved
()
.await
?
,
};
};
Ok
(
if
client_assets
{
Ok
(
if
client_assets
{
get_server_chunking_context_with_client_assets
(
options
)
get_server_chunking_context_with_client_assets
(
options
)
...
@@ -1684,7 +1660,7 @@ impl Project {
...
@@ -1684,7 +1660,7 @@ impl Project {
.await
?
,
.await
?
,
asset_prefix
:
self
.next_config
()
.computed_asset_prefix
()
.owned
()
.await
?
,
asset_prefix
:
self
.next_config
()
.computed_asset_prefix
()
.owned
()
.await
?
,
css_url_suffix
,
css_url_suffix
,
hash_salt
:
self
.hash_salt
()
.to_resolved
()
.await
?
,
hash_salt
:
self
.
next_config
()
.output_
hash_salt
()
.to_resolved
()
.await
?
,
cross_origin
:
self
.next_config
()
.cross_origin
(),
cross_origin
:
self
.next_config
()
.cross_origin
(),
};
};
Ok
(
if
client_assets
{
Ok
(
if
client_assets
{
...
...
crates/next-api/src/project_asset_hashes_manifest.rs
View file @
26cfeb85
...
@@ -143,7 +143,10 @@ impl Asset for AssetHashesManifestAsset {
...
@@ -143,7 +143,10 @@ impl Asset for AssetHashesManifestAsset {
Ok
((
Ok
((
path
,
path
,
asset
asset
.content_hash
(
self
.project
.hash_salt
(),
HashAlgorithm
::
Xxh3Hash128Base38
)
.content_hash
(
self
.project
.next_config
()
.output_hash_salt
(),
HashAlgorithm
::
Xxh3Hash128Base38
,
)
.await
?
,
.await
?
,
))
))
})
})
...
...
crates/next-build-test/src/main.rs
View file @
26cfeb85
...
@@ -190,7 +190,6 @@ fn main() {
...
@@ -190,7 +190,6 @@ fn main() {
is_persistent_caching_enabled
:
false
,
is_persistent_caching_enabled
:
false
,
next_version
:
rcstr!
(
"0.0.0"
),
next_version
:
rcstr!
(
"0.0.0"
),
server_hmr
:
false
,
server_hmr
:
false
,
hash_salt
:
rcstr!
(
""
),
};
};
let
json
=
serde_json
::
to_string_pretty
(
&
options
)
.unwrap
();
let
json
=
serde_json
::
to_string_pretty
(
&
options
)
.unwrap
();
...
...
crates/next-core/src/next_config.rs
View file @
26cfeb85
...
@@ -1090,6 +1090,10 @@ pub struct ExperimentalConfig {
...
@@ -1090,6 +1090,10 @@ pub struct ExperimentalConfig {
runtime_server_deployment_id
:
Option
<
bool
>
,
runtime_server_deployment_id
:
Option
<
bool
>
,
supports_immutable_assets
:
Option
<
bool
>
,
supports_immutable_assets
:
Option
<
bool
>
,
/// A salt to mix into chunk and asset content hashes. Empty string means
/// no salt.
output_hash_salt
:
Option
<
RcStr
>
,
// ---
// ---
// UNSUPPORTED
// UNSUPPORTED
// ---
// ---
...
@@ -2349,6 +2353,16 @@ impl NextConfig {
...
@@ -2349,6 +2353,16 @@ impl NextConfig {
.collect
::
<
Result
<
Vec
<
_
>>>
()
?
;
.collect
::
<
Result
<
Vec
<
_
>>>
()
?
;
Ok
(
Vc
::
cell
(
rules
))
Ok
(
Vc
::
cell
(
rules
))
}
}
#[turbo_tasks
::
function]
pub
fn
output_hash_salt
(
&
self
)
->
Vc
<
RcStr
>
{
Vc
::
cell
(
self
.experimental
.output_hash_salt
.clone
()
.unwrap_or_default
(),
)
}
}
}
/// A subset of ts/jsconfig that next.js implicitly
/// A subset of ts/jsconfig that next.js implicitly
...
...
crates/next-napi-bindings/src/next_api/project.rs
View file @
26cfeb85
...
@@ -216,11 +216,6 @@ pub struct NapiProjectOptions {
...
@@ -216,11 +216,6 @@ pub struct NapiProjectOptions {
/// Whether server-side HMR is enabled (disabled with --no-server-fast-refresh).
/// Whether server-side HMR is enabled (disabled with --no-server-fast-refresh).
pub
server_hmr
:
Option
<
bool
>
,
pub
server_hmr
:
Option
<
bool
>
,
/// A salt to mix into chunk and asset content hashes, allowing users to
/// force new filenames without changing file content. Empty string means
/// no salt.
pub
hash_salt
:
RcStr
,
}
}
/// [NapiProjectOptions] with all fields optional.
/// [NapiProjectOptions] with all fields optional.
...
@@ -271,9 +266,6 @@ pub struct NapiPartialProjectOptions {
...
@@ -271,9 +266,6 @@ pub struct NapiPartialProjectOptions {
/// local names for variables, functions etc., which can be useful for
/// local names for variables, functions etc., which can be useful for
/// debugging/profiling purposes.
/// debugging/profiling purposes.
pub
no_mangling
:
Option
<
bool
>
,
pub
no_mangling
:
Option
<
bool
>
,
/// An optional salt to mix into chunk and asset content hashes.
pub
hash_salt
:
Option
<
RcStr
>
,
}
}
#[napi(object)]
#[napi(object)]
...
@@ -334,7 +326,6 @@ impl From<NapiProjectOptions> for ProjectOptions {
...
@@ -334,7 +326,6 @@ impl From<NapiProjectOptions> for ProjectOptions {
is_persistent_caching_enabled
,
is_persistent_caching_enabled
,
next_version
,
next_version
,
server_hmr
,
server_hmr
,
hash_salt
,
}
=
val
;
}
=
val
;
ProjectOptions
{
ProjectOptions
{
root_path
,
root_path
,
...
@@ -359,7 +350,6 @@ impl From<NapiProjectOptions> for ProjectOptions {
...
@@ -359,7 +350,6 @@ impl From<NapiProjectOptions> for ProjectOptions {
is_persistent_caching_enabled
,
is_persistent_caching_enabled
,
next_version
,
next_version
,
server_hmr
:
server_hmr
.unwrap_or
(
false
),
server_hmr
:
server_hmr
.unwrap_or
(
false
),
hash_salt
,
}
}
}
}
}
}
...
@@ -380,7 +370,6 @@ impl From<NapiPartialProjectOptions> for PartialProjectOptions {
...
@@ -380,7 +370,6 @@ impl From<NapiPartialProjectOptions> for PartialProjectOptions {
browserslist_query
,
browserslist_query
,
no_mangling
,
no_mangling
,
write_routes_hashes_manifest
,
write_routes_hashes_manifest
,
hash_salt
,
}
=
val
;
}
=
val
;
PartialProjectOptions
{
PartialProjectOptions
{
root_path
,
root_path
,
...
@@ -397,7 +386,6 @@ impl From<NapiPartialProjectOptions> for PartialProjectOptions {
...
@@ -397,7 +386,6 @@ impl From<NapiPartialProjectOptions> for PartialProjectOptions {
no_mangling
,
no_mangling
,
write_routes_hashes_manifest
,
write_routes_hashes_manifest
,
debug_build_paths
:
None
,
debug_build_paths
:
None
,
hash_salt
,
}
}
}
}
}
}
...
...
packages/next/src/build/swc/generated-native.d.ts
View file @
26cfeb85
...
@@ -258,12 +258,6 @@ export interface NapiProjectOptions {
...
@@ -258,12 +258,6 @@ export interface NapiProjectOptions {
nextVersion
:
RcStr
nextVersion
:
RcStr
/** Whether server-side HMR is enabled (disabled with --no-server-fast-refresh). */
/** Whether server-side HMR is enabled (disabled with --no-server-fast-refresh). */
serverHmr
?:
boolean
serverHmr
?:
boolean
/**
* A salt to mix into chunk and asset content hashes, allowing users to
* force new filenames without changing file content. Empty string means
* no salt.
*/
hashSalt
:
RcStr
}
}
/** [NapiProjectOptions] with all fields optional. */
/** [NapiProjectOptions] with all fields optional. */
export
interface
NapiPartialProjectOptions
{
export
interface
NapiPartialProjectOptions
{
...
@@ -308,8 +302,6 @@ export interface NapiPartialProjectOptions {
...
@@ -308,8 +302,6 @@ export interface NapiPartialProjectOptions {
* debugging/profiling purposes.
* debugging/profiling purposes.
*/
*/
noMangling
?:
boolean
noMangling
?:
boolean
/** An optional salt to mix into chunk and asset content hashes. */
hashSalt
?:
RcStr
}
}
export
interface
NapiDefineEnv
{
export
interface
NapiDefineEnv
{
client
:
Array
<
NapiOptionEnvVar
>
client
:
Array
<
NapiOptionEnvVar
>
...
...
packages/next/src/build/turbopack-analyze/index.ts
View file @
26cfeb85
...
@@ -91,7 +91,6 @@ export async function turbopackAnalyze(
...
@@ -91,7 +91,6 @@ export async function turbopackAnalyze(
currentNodeJsVersion
,
currentNodeJsVersion
,
isPersistentCachingEnabled
:
persistentCaching
,
isPersistentCachingEnabled
:
persistentCaching
,
nextVersion
:
process
.
env
.
__NEXT_VERSION
as
string
,
nextVersion
:
process
.
env
.
__NEXT_VERSION
as
string
,
hashSalt
:
config
.
hashSalt
,
},
},
{
{
memoryLimit
:
config
.
experimental
?.
turbopackMemoryLimit
,
memoryLimit
:
config
.
experimental
?.
turbopackMemoryLimit
,
...
...
packages/next/src/build/turbopack-build/impl.ts
View file @
26cfeb85
...
@@ -114,7 +114,6 @@ export async function turbopackBuild(): Promise<{
...
@@ -114,7 +114,6 @@ export async function turbopackBuild(): Promise<{
isPersistentCachingEnabled
:
persistentCaching
,
isPersistentCachingEnabled
:
persistentCaching
,
deferredEntries
:
config
.
experimental
.
deferredEntries
,
deferredEntries
:
config
.
experimental
.
deferredEntries
,
nextVersion
:
process
.
env
.
__NEXT_VERSION
as
string
,
nextVersion
:
process
.
env
.
__NEXT_VERSION
as
string
,
hashSalt
:
config
.
hashSalt
,
}
}
const
sharedTurboOptions
=
{
const
sharedTurboOptions
=
{
...
...
packages/next/src/build/webpack-config.ts
View file @
26cfeb85
...
@@ -1347,7 +1347,9 @@ export default async function getBaseWebpackConfig(
...
@@ -1347,7 +1347,9 @@ export default async function getBaseWebpackConfig(
hashDigestLength
:
16
,
hashDigestLength
:
16
,
// Webpack requires hashSalt to be a non-empty string; omit it entirely
// Webpack requires hashSalt to be a non-empty string; omit it entirely
// when no salt is configured.
// when no salt is configured.
...(
config
.
hashSalt
?
{
hashSalt
:
config
.
hashSalt
}
:
{}),
...(
config
.
experimental
?.
outputHashSalt
?
{
hashSalt
:
config
.
experimental
.
outputHashSalt
}
:
{}),
},
},
performance
:
false
,
performance
:
false
,
resolve
:
resolveConfig
,
resolve
:
resolveConfig
,
...
@@ -1799,7 +1801,7 @@ export default async function getBaseWebpackConfig(
...
@@ -1799,7 +1801,7 @@ export default async function getBaseWebpackConfig(
compilerType
,
compilerType
,
basePath
:
config
.
basePath
,
basePath
:
config
.
basePath
,
assetPrefix
:
config
.
assetPrefix
,
assetPrefix
:
config
.
assetPrefix
,
hashSalt
:
config
.
h
ashSalt
,
outputHashSalt
:
config
.
experimental
?.
outputH
ashSalt
,
},
},
},
},
]
]
...
...
packages/next/src/build/webpack/loaders/next-image-loader/index.ts
View file @
26cfeb85
...
@@ -10,21 +10,22 @@ interface Options {
...
@@ -10,21 +10,22 @@ interface Options {
isDev
:
boolean
isDev
:
boolean
assetPrefix
:
string
assetPrefix
:
string
basePath
:
string
basePath
:
string
h
ashSalt
:
string
outputH
ashSalt
:
string
}
}
function
nextImageLoader
(
this
:
any
,
content
:
Buffer
)
{
function
nextImageLoader
(
this
:
any
,
content
:
Buffer
)
{
const
imageLoaderSpan
=
this
.
currentTraceSpan
.
traceChild
(
'next-image-loader'
)
const
imageLoaderSpan
=
this
.
currentTraceSpan
.
traceChild
(
'next-image-loader'
)
return
imageLoaderSpan
.
traceAsyncFn
(
async
()
=>
{
return
imageLoaderSpan
.
traceAsyncFn
(
async
()
=>
{
const
options
:
Options
=
this
.
getOptions
()
const
options
:
Options
=
this
.
getOptions
()
const
{
compilerType
,
isDev
,
assetPrefix
,
basePath
,
hashSalt
}
=
options
const
{
compilerType
,
isDev
,
assetPrefix
,
basePath
,
outputHashSalt
}
=
options
const
context
=
this
.
rootContext
const
context
=
this
.
rootContext
// Prepend the hash salt to the content for filename hash computation, so
// Prepend the hash salt to the content for filename hash computation, so
// that NEXT_HASH_SALT causes image filenames to change (like it does for
// that NEXT_HASH_SALT causes image filenames to change (like it does for
// chunks). The actual file content is unaffected.
// chunks). The actual file content is unaffected.
const
contentForHash
=
h
ashSalt
const
contentForHash
=
outputH
ashSalt
?
Buffer
.
concat
([
Buffer
.
from
(
h
ashSalt
,
'utf8'
),
content
])
?
Buffer
.
concat
([
Buffer
.
from
(
outputH
ashSalt
,
'utf8'
),
content
])
:
content
:
content
const
opts
=
{
context
,
content
:
contentForHash
}
const
opts
=
{
context
,
content
:
contentForHash
}
const
interpolatedName
=
loaderUtils
.
interpolateName
(
const
interpolatedName
=
loaderUtils
.
interpolateName
(
...
...
packages/next/src/server/config-shared.ts
View file @
26cfeb85
...
@@ -40,9 +40,6 @@ export type NextConfigComplete = Required<Omit<NextConfig, 'configFile'>> & {
...
@@ -40,9 +40,6 @@ export type NextConfigComplete = Required<Omit<NextConfig, 'configFile'>> & {
// since development builds use `{distDir}/dev`. This is used to ensure that the bundler doesn't
// since development builds use `{distDir}/dev`. This is used to ensure that the bundler doesn't
// traverse into the output directory.
// traverse into the output directory.
distDirRoot
:
string
distDirRoot
:
string
// Pre-computed effective hash salt: experimental.outputHashSalt (from config)
// concatenated with NEXT_HASH_SALT (from env). Used by both Webpack and Turbopack.
hashSalt
:
string
}
}
export
type
I18NDomains
=
readonly
DomainLocale
[]
export
type
I18NDomains
=
readonly
DomainLocale
[]
...
...
packages/next/src/server/config.ts
View file @
26cfeb85
...
@@ -1045,6 +1045,11 @@ function assignDefaultsAndValidate(
...
@@ -1045,6 +1045,11 @@ function assignDefaultsAndValidate(
result
.
experimental
.
supportsImmutableAssets
=
true
result
.
experimental
.
supportsImmutableAssets
=
true
}
}
if
(
process
.
env
.
NEXT_HASH_SALT
)
{
result
.
experimental
.
outputHashSalt
=
(
result
.
experimental
.
outputHashSalt
??
''
)
+
process
.
env
.
NEXT_HASH_SALT
}
const
tracingRoot
=
result
?.
outputFileTracingRoot
const
tracingRoot
=
result
?.
outputFileTracingRoot
const
turbopackRoot
=
result
?.
turbopack
?.
root
const
turbopackRoot
=
result
?.
turbopack
?.
root
...
@@ -1516,10 +1521,7 @@ function assignDefaultsAndValidate(
...
@@ -1516,10 +1521,7 @@ function assignDefaultsAndValidate(
// Store the distDirRoot in the config before it is modified for development mode
// Store the distDirRoot in the config before it is modified for development mode
;(
result
as
NextConfigComplete
).
distDirRoot
=
result
.
distDir
;(
result
as
NextConfigComplete
).
distDirRoot
=
result
.
distDir
// Pre-compute the effective hash salt (used by both Webpack and Turbopack).
;(
result
as
NextConfigComplete
).
hashSalt
=
(
result
.
experimental
?.
outputHashSalt
??
''
)
+
(
process
.
env
.
NEXT_HASH_SALT
??
''
)
if
(
phase
===
PHASE_DEVELOPMENT_SERVER
)
{
if
(
phase
===
PHASE_DEVELOPMENT_SERVER
)
{
result
.
distDir
=
join
(
result
.
distDir
,
'dev'
)
result
.
distDir
=
join
(
result
.
distDir
,
'dev'
)
}
}
...
...
packages/next/src/server/dev/hot-reloader-turbopack.ts
View file @
26cfeb85
...
@@ -414,7 +414,6 @@ export async function createHotReloaderTurbopack(
...
@@ -414,7 +414,6 @@ export async function createHotReloaderTurbopack(
),
),
nextVersion
:
process
.
env
.
__NEXT_VERSION
as
string
,
nextVersion
:
process
.
env
.
__NEXT_VERSION
as
string
,
serverHmr
:
serverFastRefresh
,
serverHmr
:
serverFastRefresh
,
hashSalt
:
opts
.
nextConfig
.
hashSalt
,
},
},
{
{
memoryLimit
:
opts
.
nextConfig
.
experimental
?.
turbopackMemoryLimit
,
memoryLimit
:
opts
.
nextConfig
.
experimental
?.
turbopackMemoryLimit
,
...
...
test/development/basic/next-rs-api.test.ts
View file @
26cfeb85
...
@@ -233,7 +233,6 @@ async function main() {
...
@@ -233,7 +233,6 @@ async function main() {
currentNodeJsVersion: '18.0.0',
currentNodeJsVersion: '18.0.0',
isPersistentCachingEnabled: false,
isPersistentCachingEnabled: false,
nextVersion: '0.0.0',
nextVersion: '0.0.0',
hashSalt: '',
});
});
const entrypointsSubscription = project.entrypointsSubscribe();
const entrypointsSubscription = project.entrypointsSubscribe();
...
@@ -394,7 +393,6 @@ describe('next.rs api', () => {
...
@@ -394,7 +393,6 @@ describe('next.rs api', () => {
currentNodeJsVersion
:
'18.0.0'
,
currentNodeJsVersion
:
'18.0.0'
,
isPersistentCachingEnabled
:
false
,
isPersistentCachingEnabled
:
false
,
nextVersion
:
'0.0.0'
,
nextVersion
:
'0.0.0'
,
hashSalt
:
''
,
})
})
projectUpdateSubscription
=
filterMapAsyncIterator
(
projectUpdateSubscription
=
filterMapAsyncIterator
(
project
.
updateInfoSubscribe
(
1000
),
project
.
updateInfoSubscribe
(
1000
),
...
...
test/production/app-dir/hash-salt/hash-salt.test.ts
View file @
26cfeb85
...
@@ -83,45 +83,68 @@ describe('experimental.outputHashSalt', () => {
...
@@ -83,45 +83,68 @@ describe('experimental.outputHashSalt', () => {
async
function
buildWithSalts
(
opts
:
{
async
function
buildWithSalts
(
opts
:
{
configSalt
?:
string
configSalt
?:
string
envSalt
?:
string
envSalt
?:
string
adapterSalt
?:
string
})
{
})
{
const
env
:
Record
<
string
,
string
>
=
{}
const
env
:
Record
<
string
,
string
>
=
{}
if
(
opts
.
configSalt
)
env
.
OUTPUT_HASH_SALT_CONFIG
=
opts
.
configSalt
if
(
opts
.
configSalt
)
env
.
OUTPUT_HASH_SALT_CONFIG
=
opts
.
configSalt
if
(
opts
.
envSalt
)
env
.
NEXT_HASH_SALT
=
opts
.
envSalt
if
(
opts
.
envSalt
)
env
.
NEXT_HASH_SALT
=
opts
.
envSalt
if
(
opts
.
adapterSalt
)
env
.
ADAPTER_HASH_SALT
=
opts
.
adapterSalt
await
next
.
clean
()
await
next
.
clean
()
await
next
.
build
({
env
})
await
next
.
build
({
env
})
const
chunks
=
(
const
chunks
=
(
await
listClientChunks
(
join
(
next
.
testDir
,
next
.
distDir
))
await
listClientChunks
(
join
(
next
.
testDir
,
next
.
distDir
))
).
filter
((
f
)
=>
f
.
includes
(
'/chunks/'
)
&&
f
.
endsWith
(
'.js'
))
).
filter
((
f
)
=>
f
.
includes
(
'/chunks/'
)
&&
f
.
endsWith
(
'.js'
))
return
chunks
return
chunks
.
sort
()
}
}
let
noSaltChunks
:
string
[]
let
noSaltChunks
:
string
[]
let
configOnlyChunks
:
string
[]
let
configOnlyChunks
:
string
[]
let
envOnlyChunks
:
string
[]
let
envOnlyChunks
:
string
[]
let
bothChunks
:
string
[]
let
adapterEnvOnlyChunks
:
string
[]
let
configAndEnvChunks
:
string
[]
let
configAndAdapterEnvChunks
:
string
[]
let
envAndAdapterEnvChunks
:
string
[]
beforeAll
(
beforeAll
(
async
()
=>
{
async
()
=>
{
noSaltChunks
=
await
buildWithSalts
({})
noSaltChunks
=
await
buildWithSalts
({})
configOnlyChunks
=
await
buildWithSalts
({
configSalt
:
'config-salt'
})
configOnlyChunks
=
await
buildWithSalts
({
configSalt
:
'config-salt'
})
envOnlyChunks
=
await
buildWithSalts
({
envSalt
:
'env-salt'
})
envOnlyChunks
=
await
buildWithSalts
({
envSalt
:
'env-salt'
})
bothChunks
=
await
buildWithSalts
({
adapterEnvOnlyChunks
=
await
buildWithSalts
({
adapterSalt
:
'adapter-salt'
,
})
configAndEnvChunks
=
await
buildWithSalts
({
configSalt
:
'config-salt'
,
configSalt
:
'config-salt'
,
envSalt
:
'env-salt'
,
envSalt
:
'env-salt'
,
})
})
configAndAdapterEnvChunks
=
await
buildWithSalts
({
configSalt
:
'config-salt'
,
adapterSalt
:
'adapter-salt'
,
})
envAndAdapterEnvChunks
=
await
buildWithSalts
({
envSalt
:
'env-salt'
,
adapterSalt
:
'adapter-salt'
,
})
},
},
5
*
60
*
1000
5
*
60
*
1000
)
)
it
(
'config salt changes filenames compared to no salt'
,
()
=>
{
it
(
'config salt changes filenames compared to no salt'
,
()
=>
{
expect
(
configOnlyChunks
.
sort
()).
not
.
toEqual
(
noSaltChunks
.
sort
())
expect
(
configOnlyChunks
).
not
.
toEqual
(
noSaltChunks
)
})
it
(
'config-and-env salt differs'
,
()
=>
{
expect
(
configAndEnvChunks
).
not
.
toEqual
(
envOnlyChunks
)
expect
(
configAndEnvChunks
).
not
.
toEqual
(
configOnlyChunks
)
})
})
it
(
'combined salt differs from env-var-only salt'
,
()
=>
{
it
(
'config-and-adapter-env salt differs'
,
()
=>
{
expect
(
bothChunks
.
sort
()).
not
.
toEqual
(
envOnlyChunks
.
sort
())
expect
(
configAndAdapterEnvChunks
).
not
.
toEqual
(
configOnlyChunks
)
expect
(
configAndAdapterEnvChunks
).
not
.
toEqual
(
adapterEnvOnlyChunks
)
})
})
it
(
'combined salt differs from config-only salt'
,
()
=>
{
it
(
'env-and-adapter-env salt differs'
,
()
=>
{
expect
(
bothChunks
.
sort
()).
not
.
toEqual
(
configOnlyChunks
.
sort
())
expect
(
envAndAdapterEnvChunks
).
not
.
toEqual
(
envOnlyChunks
)
expect
(
envAndAdapterEnvChunks
).
not
.
toEqual
(
adapterEnvOnlyChunks
)
})
})
})
})
test/production/app-dir/hash-salt/my-adapter.mjs
0 → 100644
View file @
26cfeb85
// @ts-check
/** @type {import('next').NextAdapter } */
const
myAdapter
=
{
name
:
'my-custom-adapter'
,
modifyConfig
:
(
config
)
=>
{
if
(
process
.
env
.
ADAPTER_HASH_SALT
!=
null
)
{
config
.
experimental
.
outputHashSalt
=
(
config
.
experimental
.
outputHashSalt
??
''
)
+
process
.
env
.
ADAPTER_HASH_SALT
}
return
config
},
}
export
default
myAdapter
test/production/app-dir/hash-salt/next.config.js
View file @
26cfeb85
...
@@ -4,4 +4,5 @@ module.exports = {
...
@@ -4,4 +4,5 @@ module.exports = {
// Allow tests to inject outputHashSalt via env var without touching source.
// Allow tests to inject outputHashSalt via env var without touching source.
outputHashSalt
:
process
.
env
.
OUTPUT_HASH_SALT_CONFIG
||
undefined
,
outputHashSalt
:
process
.
env
.
OUTPUT_HASH_SALT_CONFIG
||
undefined
,
},
},
adapterPath
:
require
.
resolve
(
'./my-adapter.mjs'
),
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment