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

Omit unnecessary cache wrapper import #73160

Merged
merged 1 commit into from
Nov 25, 2024
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
47 changes: 24 additions & 23 deletions crates/next-custom-transforms/src/transforms/server_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1316,9 +1316,6 @@ impl<C: Comments> VisitMut for ServerActions<C> {
let in_cache_file = matches!(self.file_directive, Some(Directive::UseCache { .. }));
let in_action_file = matches!(self.file_directive, Some(Directive::UseServer));

self.has_action = in_action_file;
self.has_cache = in_cache_file;

if in_cache_file {
// If we're in a "use cache" file, collect all original IDs from
// export specifiers in a pre-pass so that we know which functions
Expand Down Expand Up @@ -1697,13 +1694,34 @@ impl<C: Comments> VisitMut for ServerActions<C> {
}
}

let mut actions = self.export_actions.take();

if in_action_file || in_cache_file && !self.config.is_react_server_layer {
actions.extend(
self.exported_idents
.iter()
.map(|e| (e.1.clone(), e.2.clone())),
);

if !actions.is_empty() {
self.has_action |= in_action_file;
self.has_cache |= in_cache_file;
}
};

// Make it a hashmap of id -> name.
let actions = actions
.into_iter()
.map(|a| (a.1, a.0))
.collect::<ActionsMap>();

// If it's compiled in the client layer, each export field needs to be
// wrapped by a reference creation call.
let create_ref_ident = private_ident!("createServerReference");
let call_server_ident = private_ident!("callServer");
let find_source_map_url_ident = private_ident!("findSourceMapURL");

if should_track_exports && !self.config.is_react_server_layer {
if (self.has_action || self.has_cache) && !self.config.is_react_server_layer {
// import {
// createServerReference,
// callServer,
Expand Down Expand Up @@ -1828,7 +1846,7 @@ impl<C: Comments> VisitMut for ServerActions<C> {
//
// But it's only needed for the server layer, because on the client
// layer they're transformed into references already.
if self.config.is_react_server_layer {
if (self.has_action || self.has_cache) && self.config.is_react_server_layer {
new.append(&mut self.extra_items);

// For "use cache" files, there's no need to do extra annotations.
Expand Down Expand Up @@ -1883,23 +1901,6 @@ impl<C: Comments> VisitMut for ServerActions<C> {
}

if self.has_action || self.has_cache {
let mut actions = self.export_actions.clone();

// All exported values are considered as actions if the file is an action file.
if in_action_file || in_cache_file && !self.config.is_react_server_layer {
actions.extend(
self.exported_idents
.iter()
.map(|e| (e.1.clone(), e.2.clone())),
);
};

// Make it a hashmap of id -> name.
let actions = actions
.into_iter()
.map(|a| (a.1, a.0))
.collect::<ActionsMap>();

// Prepend a special comment to the top of the file.
self.comments.add_leading(
self.start_pos,
Expand All @@ -1911,7 +1912,7 @@ impl<C: Comments> VisitMut for ServerActions<C> {
);
}

// import { cache as $cache } from "private-next-rsc-cache-wrapper";
// import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
if self.has_cache && self.config.is_react_server_layer {
new.push(ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl {
span: DUMMY_SP,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* __next_internal_action_entry_do_not_use__ {"006a88810ecce4a4e8b59d53b8327d7e98bbf251d7":"$$RSC_SERVER_ACTION_0"} */ import { registerServerReference } from "private-next-rsc-server-reference";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_0 = async function b() {
// this is not allowed here
this.foo();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* __next_internal_action_entry_do_not_use__ {"601c36b06e398c97abe5d5d7ae8c672bfddf4e1b91":"$$RSC_SERVER_ACTION_2","609ed0cc47abc4e1c64320cf42b74ae60b58c40f00":"$$RSC_SERVER_ACTION_3","7090b5db271335765a4b0eab01f044b381b5ebd5cd":"$$RSC_SERVER_ACTION_1"} */ import { registerServerReference } from "private-next-rsc-server-reference";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
export const /*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/ $$RSC_SERVER_ACTION_1 = async function $$RSC_SERVER_ACTION_0(a, b, c) {
return <div>
{a}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* __next_internal_action_entry_do_not_use__ {} */ import { registerServerReference } from "private-next-rsc-server-reference";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper";
// No method nor function property should be considered a cache function.
export const obj = {
foo () {
Expand Down
Loading