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
10e487a3
Commit
10e487a3
authored
Nov 15, 2024
by
Benjamin Woodruff
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Suggested changes
parent
6230c41d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
24 deletions
+41
-24
Cargo.lock
Cargo.lock
+1
-0
next_config.rs
crates/next-core/src/next_config.rs
+4
-6
Cargo.toml
crates/next-custom-transforms/Cargo.toml
+1
-0
server_actions.rs
...s/next-custom-transforms/src/transforms/server_actions.rs
+35
-18
No files found.
Cargo.lock
View file @
10e487a3
...
...
@@ -4083,6 +4083,7 @@ dependencies = [
"swc_relay",
"testing",
"tracing",
"turbo-tasks",
"turbopack-ecmascript-plugins",
"walkdir",
]
...
...
crates/next-core/src/next_config.rs
View file @
10e487a3
...
...
@@ -41,7 +41,7 @@ struct CustomRoutes {
pub
struct
ModularizeImports
(
FxIndexMap
<
String
,
ModularizeImportPackageConfig
>
);
#[turbo_tasks
::
value(transparent)]
pub
struct
CacheKinds
(
FxHashSet
<
String
>
);
pub
struct
CacheKinds
(
FxHashSet
<
RcStr
>
);
#[turbo_tasks
::
value(serialization
=
"custom"
,
eq
=
"manual"
)]
#[derive(Clone,
Debug,
Default,
PartialEq,
Serialize,
Deserialize)]
...
...
@@ -1168,11 +1168,9 @@ impl NextConfig {
Vc
::
cell
(
self
.experimental
.cache_handlers
.clone
()
.unwrap_or_default
()
.keys
()
.cloned
()
.collect
(),
.as_ref
()
.map
(|
handlers
|
handlers
.keys
()
.map
(|
kind
|
RcStr
::
from
(
&**
kind
))
.collect
())
.unwrap_or_default
(),
)
}
...
...
crates/next-custom-transforms/Cargo.toml
View file @
10e487a3
...
...
@@ -56,6 +56,7 @@ styled_jsx = { workspace = true }
swc_emotion
=
{
workspace
=
true
}
swc_relay
=
{
workspace
=
true
}
turbopack-ecmascript-plugins
=
{
workspace
=
true
,
optional
=
true
}
turbo-tasks
=
{
workspace
=
true
}
# only needed for RcStr
react_remove_properties
=
"0.24.25"
remove_console
=
"0.25.25"
...
...
crates/next-custom-transforms/src/transforms/server_actions.rs
View file @
10e487a3
...
...
@@ -23,6 +23,7 @@ use swc_core::{
visit
::{
noop_visit_mut_type
,
visit_mut_pass
,
VisitMut
,
VisitMutWith
},
},
};
use
turbo_tasks
::
RcStr
;
#[derive(Clone,
Debug,
Deserialize)]
#[serde(deny_unknown_fields,
rename_all
=
"camelCase"
)]
...
...
@@ -30,7 +31,7 @@ pub struct Config {
pub
is_react_server_layer
:
bool
,
pub
dynamic_io_enabled
:
bool
,
pub
hash_salt
:
String
,
pub
cache_kinds
:
FxHashSet
<
String
>
,
pub
cache_kinds
:
FxHashSet
<
RcStr
>
,
}
enum
DirectiveLocation
{
...
...
@@ -69,7 +70,7 @@ enum ServerActionsErrorKind {
},
UnknownCacheKind
{
span
:
Span
,
cache_kind
:
String
,
cache_kind
:
RcStr
,
},
UseCacheWithoutDynamicIO
{
span
:
Span
,
...
...
@@ -85,6 +86,12 @@ enum ServerActionsErrorKind {
// Using BTreeMap to ensure the order of the actions is deterministic.
pub
type
ActionsMap
=
BTreeMap
<
String
,
String
>
;
// Directive-level information about a function body
struct
BodyInfo
{
is_action_fn
:
bool
,
cache_kind
:
Option
<
RcStr
>
,
}
#[tracing
::
instrument(level
=
tracing
::
Level
::
TRACE,
skip_all)]
pub
fn
server_actions
<
C
:
Comments
>
(
file_name
:
&
FileName
,
config
:
Config
,
comments
:
C
)
->
impl
Pass
{
visit_mut_pass
(
ServerActions
{
...
...
@@ -143,7 +150,7 @@ struct ServerActions<C: Comments> {
start_pos
:
BytePos
,
in_action_file
:
bool
,
file_cache_kind
:
Option
<
String
>
,
file_cache_kind
:
Option
<
RcStr
>
,
in_exported_expr
:
bool
,
in_default_export_decl
:
bool
,
in_callee
:
bool
,
...
...
@@ -302,7 +309,7 @@ impl<C: Comments> ServerActions<C> {
}
// Check if the function or arrow function is an action or cache function
fn
get_body_info
(
&
mut
self
,
maybe_body
:
Option
<&
mut
BlockStmt
>
)
->
(
bool
,
Option
<
String
>
)
{
fn
get_body_info
(
&
mut
self
,
maybe_body
:
Option
<&
mut
BlockStmt
>
)
->
BodyInfo
{
let
mut
is_action_fn
=
false
;
let
mut
cache_kind
=
None
;
...
...
@@ -346,7 +353,10 @@ impl<C: Comments> ServerActions<C> {
}
}
(
is_action_fn
,
cache_kind
)
BodyInfo
{
is_action_fn
,
cache_kind
,
}
}
fn
maybe_hoist_and_create_proxy_for_server_action_arrow_expr
(
...
...
@@ -887,7 +897,10 @@ impl<C: Comments> VisitMut for ServerActions<C> {
}
fn
visit_mut_fn_expr
(
&
mut
self
,
f
:
&
mut
FnExpr
)
{
let
(
is_action_fn
,
cache_kind
)
=
self
.get_body_info
(
f
.function.body
.as_mut
());
let
BodyInfo
{
is_action_fn
,
cache_kind
,
}
=
self
.get_body_info
(
f
.function.body
.as_mut
());
let
declared_idents_until
=
self
.declared_idents
.len
();
let
current_names
=
take
(
&
mut
self
.names
);
...
...
@@ -1002,7 +1015,10 @@ impl<C: Comments> VisitMut for ServerActions<C> {
self
.in_exported_expr
=
true
}
let
(
is_action_fn
,
cache_kind
)
=
self
.get_body_info
(
f
.function.body
.as_mut
());
let
BodyInfo
{
is_action_fn
,
cache_kind
,
}
=
self
.get_body_info
(
f
.function.body
.as_mut
());
let
declared_idents_until
=
self
.declared_idents
.len
();
let
current_names
=
take
(
&
mut
self
.names
);
...
...
@@ -1142,12 +1158,14 @@ impl<C: Comments> VisitMut for ServerActions<C> {
fn
visit_mut_arrow_expr
(
&
mut
self
,
a
:
&
mut
ArrowExpr
)
{
// Arrow expressions need to be visited in prepass to determine if it's
// an action function or not.
let
(
is_action_fn
,
cache_kind
)
=
self
.get_body_info
(
if
let
BlockStmtOrExpr
::
BlockStmt
(
block
)
=
&
mut
*
a
.body
{
Some
(
block
)
}
else
{
None
});
let
BodyInfo
{
is_action_fn
,
cache_kind
,
}
=
self
.get_body_info
(
if
let
BlockStmtOrExpr
::
BlockStmt
(
block
)
=
&
mut
*
a
.body
{
Some
(
block
)
}
else
{
None
});
let
declared_idents_until
=
self
.declared_idents
.len
();
let
current_names
=
take
(
&
mut
self
.names
);
...
...
@@ -2352,7 +2370,7 @@ fn detect_similar_strings(a: &str, b: &str) -> bool {
fn
remove_server_directive_index_in_module
(
stmts
:
&
mut
Vec
<
ModuleItem
>
,
in_action_file
:
&
mut
bool
,
file_cache_kind
:
&
mut
Option
<
String
>
,
file_cache_kind
:
&
mut
Option
<
RcStr
>
,
has_action
:
&
mut
bool
,
has_cache
:
&
mut
bool
,
config
:
&
Config
,
...
...
@@ -2392,8 +2410,7 @@ fn remove_server_directive_index_in_module(
*
file_cache_kind
=
Some
(
"default"
.into
());
}
else
{
// Slice the value after "use cache: "
let
cache_kind_str
:
String
=
value
.split_at
(
"use cache: "
.len
())
.
1
.into
();
let
cache_kind_str
=
RcStr
::
from
(
value
.split_at
(
"use cache: "
.len
())
.
1
);
if
!
config
.cache_kinds
.contains
(
&
cache_kind_str
)
{
emit_error
(
ServerActionsErrorKind
::
UnknownCacheKind
{
...
...
@@ -2503,7 +2520,7 @@ fn has_body_directive(maybe_body: &Option<BlockStmt>) -> (bool, bool) {
fn
remove_server_directive_index_in_fn
(
stmts
:
&
mut
Vec
<
Stmt
>
,
is_action_fn
:
&
mut
bool
,
cache_kind
:
&
mut
Option
<
String
>
,
cache_kind
:
&
mut
Option
<
RcStr
>
,
action_span
:
&
mut
Option
<
Span
>
,
config
:
&
Config
,
)
{
...
...
@@ -2548,7 +2565,7 @@ fn remove_server_directive_index_in_fn(
*
cache_kind
=
Some
(
"default"
.into
());
}
else
{
// Slice the value after "use cache: "
let
cache_kind_str
:
String
=
value
.split_at
(
"use cache: "
.len
())
.
1
.into
(
);
let
cache_kind_str
=
RcStr
::
from
(
value
.split_at
(
"use cache: "
.len
())
.
1
);
if
!
config
.cache_kinds
.contains
(
&
cache_kind_str
)
{
emit_error
(
ServerActionsErrorKind
::
UnknownCacheKind
{
...
...
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