Skip to content

Commit 1486592

Browse files
authored
Change UrlBehavior.static_suffix to ResolvedVc<Option<RcStr>> (#89921)
## Summary Changes `UrlBehavior.static_suffix` from `Option<RcStr>` to `ResolvedVc<Option<RcStr>>` so that `css_url_suffix` stays as a Vc longer instead of being eagerly resolved at the call site. This improves caching behavior by keeping the value cell-based through the chunking context construction. - Updated `UrlBehavior` struct definition in `turbopack-core` - Updated default fallbacks in browser/nodejs chunking contexts - Updated CSS url reference consumer to `.await?` the `ResolvedVc` - Replaced `.owned().await?` with `.to_resolved().await?` in next-core callers
1 parent 002f519 commit 1486592

File tree

7 files changed

+13
-15
lines changed

7 files changed

+13
-15
lines changed

crates/next-core/src/next_client/context.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,6 @@ pub async fn get_client_chunking_context(
475475
should_use_absolute_url_references,
476476
css_url_suffix,
477477
} = options;
478-
let css_url_suffix = css_url_suffix.owned().await?;
479478

480479
let next_mode = mode.await?;
481480
let asset_prefix = asset_prefix.owned().await?;
@@ -510,7 +509,7 @@ pub async fn get_client_chunking_context(
510509
.worker_forwarded_globals(worker_forwarded_globals())
511510
.default_url_behavior(UrlBehavior {
512511
suffix: AssetSuffix::Inferred,
513-
static_suffix: css_url_suffix,
512+
static_suffix: css_url_suffix.to_resolved().await?,
514513
});
515514

516515
if next_mode.is_development() {

crates/next-core/src/next_edge/context.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ pub async fn get_edge_chunking_context_with_client_assets(
249249
asset_prefix,
250250
css_url_suffix,
251251
} = options;
252-
let css_url_suffix = css_url_suffix.owned().await?;
253252
let output_root = node_root.join("server/edge")?;
254253
let next_mode = mode.await?;
255254
let mut builder = BrowserChunkingContext::builder(
@@ -265,7 +264,7 @@ pub async fn get_edge_chunking_context_with_client_assets(
265264
.asset_base_path(Some(asset_prefix))
266265
.default_url_behavior(UrlBehavior {
267266
suffix: AssetSuffix::Inferred,
268-
static_suffix: css_url_suffix,
267+
static_suffix: css_url_suffix.to_resolved().await?,
269268
})
270269
.minify_type(if *turbo_minify.await? {
271270
MinifyType::Minify {
@@ -327,7 +326,7 @@ pub async fn get_edge_chunking_context(
327326
asset_prefix,
328327
css_url_suffix,
329328
} = options;
330-
let css_url_suffix = css_url_suffix.owned().await?;
329+
let css_url_suffix = css_url_suffix.to_resolved().await?;
331330
let output_root = node_root.join("server/edge")?;
332331
let next_mode = mode.await?;
333332
let mut builder = BrowserChunkingContext::builder(
@@ -347,7 +346,7 @@ pub async fn get_edge_chunking_context(
347346
rcstr!("client"),
348347
UrlBehavior {
349348
suffix: AssetSuffix::FromGlobal(rcstr!("NEXT_CLIENT_ASSET_SUFFIX")),
350-
static_suffix: css_url_suffix.clone(),
349+
static_suffix: css_url_suffix,
351350
},
352351
)
353352
.default_url_behavior(UrlBehavior {

crates/next-core/src/next_server/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ pub async fn get_server_chunking_context_with_client_assets(
10621062
asset_prefix,
10631063
css_url_suffix,
10641064
} = options;
1065-
let css_url_suffix = css_url_suffix.owned().await?;
1065+
let css_url_suffix = css_url_suffix.to_resolved().await?;
10661066

10671067
let next_mode = mode.await?;
10681068
// TODO(alexkirsz) This should return a trait that can be implemented by the
@@ -1083,7 +1083,7 @@ pub async fn get_server_chunking_context_with_client_assets(
10831083
rcstr!("client"),
10841084
UrlBehavior {
10851085
suffix: AssetSuffix::FromGlobal(rcstr!("NEXT_CLIENT_ASSET_SUFFIX")),
1086-
static_suffix: css_url_suffix.clone(),
1086+
static_suffix: css_url_suffix,
10871087
},
10881088
)
10891089
.default_url_behavior(UrlBehavior {
@@ -1160,7 +1160,7 @@ pub async fn get_server_chunking_context(
11601160
asset_prefix,
11611161
css_url_suffix,
11621162
} = options;
1163-
let css_url_suffix = css_url_suffix.owned().await?;
1163+
let css_url_suffix = css_url_suffix.to_resolved().await?;
11641164
let next_mode = mode.await?;
11651165
// TODO(alexkirsz) This should return a trait that can be implemented by the
11661166
// different server chunking contexts. OR the build chunking context should
@@ -1182,7 +1182,7 @@ pub async fn get_server_chunking_context(
11821182
rcstr!("client"),
11831183
UrlBehavior {
11841184
suffix: AssetSuffix::FromGlobal(rcstr!("NEXT_CLIENT_ASSET_SUFFIX")),
1185-
static_suffix: css_url_suffix.clone(),
1185+
static_suffix: css_url_suffix,
11861186
},
11871187
)
11881188
.default_url_behavior(UrlBehavior {

turbopack/crates/turbopack-browser/src/chunking_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ impl ChunkingContext for BrowserChunkingContext {
680680
.or_else(|| self.default_url_behavior.clone())
681681
.unwrap_or(UrlBehavior {
682682
suffix: AssetSuffix::Inferred,
683-
static_suffix: None,
683+
static_suffix: ResolvedVc::cell(None),
684684
})
685685
.cell()
686686
}

turbopack/crates/turbopack-core/src/chunk/chunking_context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub struct UrlBehavior {
100100
pub suffix: AssetSuffix,
101101
/// Static suffix for contexts that cannot use dynamic JS expressions (e.g., CSS `url()`
102102
/// references). Must be a constant string known at build time (e.g., `?dpl=<deployment_id>`).
103-
pub static_suffix: Option<RcStr>,
103+
pub static_suffix: ResolvedVc<Option<RcStr>>,
104104
}
105105

106106
#[derive(
@@ -361,7 +361,7 @@ pub trait ChunkingContext {
361361
fn url_behavior(self: Vc<Self>, _tag: Option<RcStr>) -> Vc<UrlBehavior> {
362362
UrlBehavior {
363363
suffix: AssetSuffix::Inferred,
364-
static_suffix: None,
364+
static_suffix: ResolvedVc::cell(None),
365365
}
366366
.cell()
367367
}

turbopack/crates/turbopack-css/src/references/url.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ pub async fn resolve_url_reference(
126126

127127
// Append the static suffix from UrlBehavior if configured (e.g., ?dpl=<deployment_id>).
128128
let url_behavior = chunking_context.url_behavior(None).await?;
129-
let url_with_suffix = if let Some(ref suffix) = url_behavior.static_suffix {
129+
let url_with_suffix = if let Some(ref suffix) = *url_behavior.static_suffix.await? {
130130
format!("{}{}", url_path, suffix).into()
131131
} else {
132132
url_path

turbopack/crates/turbopack-nodejs/src/chunking_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ impl ChunkingContext for NodeJsChunkingContext {
488488
.or_else(|| self.default_url_behavior.clone())
489489
.unwrap_or(UrlBehavior {
490490
suffix: AssetSuffix::Inferred,
491-
static_suffix: None,
491+
static_suffix: ResolvedVc::cell(None),
492492
})
493493
.cell()
494494
}

0 commit comments

Comments
 (0)