Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement preferredRegion array in Turbopack #56743

Merged
merged 2 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/next-swc/crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ impl AppEndpoint {
.await?
.preferred_region
.clone()
.map(Regions::Single),
.map(Regions::Multiple),
matchers: vec![matchers],
..Default::default()
};
Expand Down
35 changes: 30 additions & 5 deletions packages/next-swc/crates/next-core/src/app_segment_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub struct NextSegmentConfig {
pub revalidate: Option<NextRevalidate>,
pub fetch_cache: Option<NextSegmentFetchCache>,
pub runtime: Option<NextRuntime>,
pub preferred_region: Option<String>,
pub preferred_region: Option<Vec<String>>,
}

#[turbo_tasks::value_impl]
Expand Down Expand Up @@ -358,12 +358,37 @@ fn parse_config_value(
}
"preferredRegion" => {
let value = eval_context.eval(init);
let Some(val) = value.as_str() else {
invalid_config("`preferredRegion` needs to be a static string", &value);
return;

let preferred_region = match value {
// Single value is turned into a single-element Vec.
JsValue::Constant(ConstantValue::Str(str)) => vec![str.to_string()],
// Array of strings is turned into a Vec. If one of the values in not a String it
// will error.
JsValue::Array { items, .. } => {
let mut regions = Vec::new();
for item in items {
if let JsValue::Constant(ConstantValue::Str(str)) = item {
regions.push(str.to_string());
} else {
invalid_config(
"Values of the `preferredRegion` array need to static strings",
&item,
);
return;
}
}
regions
}
_ => {
invalid_config(
"`preferredRegion` needs to be a static string or array of static strings",
&value,
);
return;
}
};

config.preferred_region = Some(val.to_string());
config.preferred_region = Some(preferred_region);
}
_ => {}
}
Expand Down
Loading