Skip to content

Commit c3467c7

Browse files
authored
Remove unused enabled config from server actions transforms (#72755)
The option was always set to `true` so we can safely remove it. The experimental `serverActions` flag was removed a long time ago in #57145.
1 parent b96772a commit c3467c7

File tree

5 files changed

+27
-70
lines changed

5 files changed

+27
-70
lines changed

crates/next-core/src/next_shared/transforms/server_actions.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ impl CustomTransformer for NextServerActions {
4343
&FileName::Real(ctx.file_path_str.into()),
4444
Config {
4545
is_react_server_layer: matches!(self.transform, ActionsTransform::Server),
46-
enabled: true,
4746
hash_salt: "".into(),
4847
},
4948
ctx.comments.clone(),

crates/next-custom-transforms/src/transforms/server_actions.rs

Lines changed: 27 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use swc_core::{
2626
#[serde(deny_unknown_fields, rename_all = "camelCase")]
2727
pub struct Config {
2828
pub is_react_server_layer: bool,
29-
pub enabled: bool,
3029
pub hash_salt: String,
3130
}
3231

@@ -266,7 +265,6 @@ impl<C: Comments> ServerActions<C> {
266265
&mut is_action_fn,
267266
&mut cache_type,
268267
&mut span,
269-
self.config.enabled,
270268
);
271269

272270
if !self.config.is_react_server_layer {
@@ -1303,7 +1301,6 @@ impl<C: Comments> VisitMut for ServerActions<C> {
13031301
&mut self.in_cache_file,
13041302
&mut self.has_action,
13051303
&mut self.has_cache,
1306-
self.config.enabled,
13071304
);
13081305

13091306
// If we're in a "use cache" file, collect all original IDs from export
@@ -2358,7 +2355,6 @@ fn remove_server_directive_index_in_module(
23582355
in_cache_file: &mut Option<String>,
23592356
has_action: &mut bool,
23602357
has_cache: &mut bool,
2361-
enabled: bool,
23622358
) {
23632359
let mut is_directive = true;
23642360

@@ -2372,16 +2368,6 @@ fn remove_server_directive_index_in_module(
23722368
if is_directive {
23732369
*in_action_file = true;
23742370
*has_action = true;
2375-
if !enabled {
2376-
HANDLER.with(|handler| {
2377-
handler
2378-
.struct_span_err(
2379-
*span,
2380-
"To use Server Actions, please enable the feature flag in your Next.js config. Read more: https://nextjs.org/docs/app/building-your-application/data-fetching/forms-and-mutations#convention",
2381-
)
2382-
.emit()
2383-
});
2384-
}
23852371
return false;
23862372
} else {
23872373
HANDLER.with(|handler| {
@@ -2397,16 +2383,12 @@ fn remove_server_directive_index_in_module(
23972383
// `use cache` or `use cache: foo`
23982384
if value == "use cache" || value.starts_with("use cache: ") {
23992385
if is_directive {
2400-
*in_cache_file = Some(
2401-
if value == "use cache" {
2402-
"default".into()
2403-
} else {
2404-
// Slice the value after "use cache: "
2405-
value.split_at(
2406-
"use cache: ".len(),
2407-
).1.into()
2408-
}
2409-
);
2386+
*in_cache_file = Some(if value == "use cache" {
2387+
"default".into()
2388+
} else {
2389+
// Slice the value after "use cache: "
2390+
value.split_at("use cache: ".len()).1.into()
2391+
});
24102392
*has_cache = true;
24112393
return false;
24122394
} else {
@@ -2427,8 +2409,8 @@ fn remove_server_directive_index_in_module(
24272409
.struct_span_err(
24282410
*span,
24292411
format!(
2430-
"Did you mean \"use cache\"? \"{value}\" is not a supported \
2431-
directive name."
2412+
"Did you mean \"use cache\"? \"{value}\" is not a \
2413+
supported directive name."
24322414
)
24332415
.as_str(),
24342416
)
@@ -2475,8 +2457,7 @@ fn remove_server_directive_index_in_module(
24752457
handler
24762458
.struct_span_err(
24772459
*span,
2478-
"The \"use cache\" directive cannot be wrapped in \
2479-
parentheses.",
2460+
"The \"use cache\" directive cannot be wrapped in parentheses.",
24802461
)
24812462
.emit();
24822463
})
@@ -2537,7 +2518,6 @@ fn remove_server_directive_index_in_fn(
25372518
is_action_fn: &mut bool,
25382519
cache_type: &mut Option<String>,
25392520
action_span: &mut Option<Span>,
2540-
enabled: bool,
25412521
) {
25422522
let mut is_directive = true;
25432523

@@ -2552,16 +2532,6 @@ fn remove_server_directive_index_in_fn(
25522532

25532533
if is_directive {
25542534
*is_action_fn = true;
2555-
if !enabled {
2556-
HANDLER.with(|handler| {
2557-
handler
2558-
.struct_span_err(
2559-
*span,
2560-
"To use Server Actions, please enable the feature flag in your Next.js config. Read more: https://nextjs.org/docs/app/building-your-application/data-fetching/forms-and-mutations#convention",
2561-
)
2562-
.emit()
2563-
});
2564-
}
25652535
return false;
25662536
} else {
25672537
HANDLER.with(|handler| {
@@ -2575,31 +2545,27 @@ fn remove_server_directive_index_in_fn(
25752545
});
25762546
}
25772547
} else if detect_similar_strings(value, "use server") {
2578-
// Detect typo of "use server"
2579-
HANDLER.with(|handler| {
2580-
handler
2581-
.struct_span_err(
2582-
*span,
2583-
format!(
2584-
"Did you mean \"use server\"? \"{value}\" is not a supported \
2585-
directive name."
2586-
)
2587-
.as_str(),
2548+
// Detect typo of "use server"
2549+
HANDLER.with(|handler| {
2550+
handler
2551+
.struct_span_err(
2552+
*span,
2553+
format!(
2554+
"Did you mean \"use server\"? \"{value}\" is not a supported \
2555+
directive name."
25882556
)
2589-
.emit();
2590-
});
2557+
.as_str(),
2558+
)
2559+
.emit();
2560+
});
25912561
} else if value == "use cache" || value.starts_with("use cache: ") {
25922562
if is_directive {
2593-
*cache_type = Some(
2594-
if value == "use cache" {
2595-
"default".into()
2596-
} else {
2597-
// Slice the value after "use cache: "
2598-
value.split_at(
2599-
"use cache: ".len(),
2600-
).1.into()
2601-
},
2602-
);
2563+
*cache_type = Some(if value == "use cache" {
2564+
"default".into()
2565+
} else {
2566+
// Slice the value after "use cache: "
2567+
value.split_at("use cache: ".len()).1.into()
2568+
});
26032569
return false;
26042570
} else {
26052571
HANDLER.with(|handler| {

crates/next-custom-transforms/tests/errors.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ fn react_server_actions_server_errors(input: PathBuf) {
185185
&FileName::Real("/app/item.js".into()),
186186
server_actions::Config {
187187
is_react_server_layer: true,
188-
enabled: true,
189188
hash_salt: "".into(),
190189
},
191190
tr.comments.as_ref().clone(),
@@ -224,7 +223,6 @@ fn react_server_actions_client_errors(input: PathBuf) {
224223
&FileName::Real("/app/item.js".into()),
225224
server_actions::Config {
226225
is_react_server_layer: false,
227-
enabled: true,
228226
hash_salt: "".into(),
229227
},
230228
tr.comments.as_ref().clone(),

crates/next-custom-transforms/tests/fixture.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,6 @@ fn server_actions_server_fixture(input: PathBuf) {
414414
&FileName::Real("/app/item.js".into()),
415415
server_actions::Config {
416416
is_react_server_layer: true,
417-
enabled: true,
418417
hash_salt: "".into(),
419418
},
420419
_tr.comments.as_ref().clone(),
@@ -446,7 +445,6 @@ fn next_font_with_directive_fixture(input: PathBuf) {
446445
&FileName::Real("/app/test.tsx".into()),
447446
server_actions::Config {
448447
is_react_server_layer: true,
449-
enabled: true,
450448
hash_salt: "".into(),
451449
},
452450
_tr.comments.as_ref().clone(),
@@ -471,7 +469,6 @@ fn server_actions_client_fixture(input: PathBuf) {
471469
&FileName::Real("/app/item.js".into()),
472470
server_actions::Config {
473471
is_react_server_layer: false,
474-
enabled: true,
475472
hash_salt: "".into(),
476473
},
477474
_tr.comments.as_ref().clone(),

packages/next/src/build/swc/options.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,6 @@ function getBaseSWCOptions({
208208
serverActions:
209209
isAppRouterPagesLayer && !jest
210210
? {
211-
// always enable server actions
212-
// TODO: remove this option
213-
enabled: true,
214211
isReactServerLayer,
215212
hashSalt: serverReferenceHashSalt,
216213
}

0 commit comments

Comments
 (0)