Unverified Commit c4738f7f authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: don't execute action loader eagerly (#83049)

The server-reference-manifest.json contains the chunk item id of the action loader. The loader itself doesn't "register" itself in any way. So no need to execute it eagerly.
parent 69af581d
...@@ -1748,7 +1748,7 @@ impl AppEndpoint { ...@@ -1748,7 +1748,7 @@ impl AppEndpoint {
assets, assets,
availability_info, availability_info,
} = *chunking_context } = *chunking_context
.evaluated_chunk_group( .chunk_group(
server_action_manifest_loader.ident(), server_action_manifest_loader.ident(),
ChunkGroup::Entry( ChunkGroup::Entry(
[ResolvedVc::upcast(server_action_manifest_loader)] [ResolvedVc::upcast(server_action_manifest_loader)]
...@@ -1785,7 +1785,6 @@ impl AppEndpoint { ...@@ -1785,7 +1785,6 @@ impl AppEndpoint {
bail!("rsc_entry must be evaluatable"); bail!("rsc_entry must be evaluatable");
}; };
evaluatable_assets.push(server_action_manifest_loader);
evaluatable_assets.push(rsc_entry); evaluatable_assets.push(rsc_entry);
async { async {
...@@ -1864,6 +1863,25 @@ impl AppEndpoint { ...@@ -1864,6 +1863,25 @@ impl AppEndpoint {
.await?; .await?;
} }
{
let chunk_group = chunking_context
.chunk_group(
server_action_manifest_loader.ident(),
ChunkGroup::Entry(vec![ResolvedVc::upcast(
server_action_manifest_loader,
)]),
module_graph,
current_availability_info,
)
.await?;
current_chunks = current_chunks
.concatenate(*chunk_group.assets)
.resolve()
.await?;
current_availability_info = chunk_group.availability_info;
}
anyhow::Ok(Vc::cell(vec![ anyhow::Ok(Vc::cell(vec![
chunking_context chunking_context
.entry_chunk_group_asset( .entry_chunk_group_asset(
......
...@@ -19,11 +19,13 @@ use swc_core::{ ...@@ -19,11 +19,13 @@ use swc_core::{
}, },
}; };
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{FxIndexMap, ResolvedVc, TryFlatJoinIterExt, ValueToString, Vc}; use turbo_tasks::{FxIndexMap, ResolvedVc, TryFlatJoinIterExt, Vc};
use turbo_tasks_fs::{self, File, FileSystemPath, rope::RopeBuilder}; use turbo_tasks_fs::{self, File, FileSystemPath, rope::RopeBuilder};
use turbopack_core::{ use turbopack_core::{
asset::AssetContent, asset::AssetContent,
chunk::{ChunkItem, ChunkItemExt, ChunkableModule, ChunkingContext, EvaluatableAsset}, chunk::{
ChunkItem, ChunkItemExt, ChunkableModule, ChunkingContext, EvaluatableAsset, ModuleId,
},
context::AssetContext, context::AssetContext,
file_source::FileSource, file_source::FileSource,
ident::AssetIdent, ident::AssetIdent,
...@@ -168,7 +170,11 @@ async fn build_manifest( ...@@ -168,7 +170,11 @@ async fn build_manifest(
let key = format!("app{page_name}"); let key = format!("app{page_name}");
let actions_value = actions.await?; let actions_value = actions.await?;
let loader_id = chunk_item.id().to_string().await?; let loader_id = chunk_item.id().await?;
let loader_id = match &*loader_id {
ModuleId::Number(id) => ActionManifestModuleId::Number(*id),
ModuleId::String(id) => ActionManifestModuleId::String(id),
};
let mapping = match runtime { let mapping = match runtime {
NextRuntime::Edge => &mut manifest.edge, NextRuntime::Edge => &mut manifest.edge,
NextRuntime::NodeJs => &mut manifest.node, NextRuntime::NodeJs => &mut manifest.node,
...@@ -190,7 +196,7 @@ async fn build_manifest( ...@@ -190,7 +196,7 @@ async fn build_manifest(
entry.workers.insert( entry.workers.insert(
&key, &key,
ActionManifestWorkerEntry { ActionManifestWorkerEntry {
module_id: ActionManifestModuleId::String(loader_id.as_str()), module_id: loader_id.clone(),
is_async: *async_module_info.is_async(chunk_item.module()).await?, is_async: *async_module_info.is_async(chunk_item.module()).await?,
exported_name: name.as_str(), exported_name: name.as_str(),
filename: filename.as_str(), filename: filename.as_str(),
......
...@@ -329,11 +329,11 @@ pub struct ActionManifestWorkerEntry<'a> { ...@@ -329,11 +329,11 @@ pub struct ActionManifestWorkerEntry<'a> {
pub filename: &'a str, pub filename: &'a str,
} }
#[derive(Serialize, Debug)] #[derive(Serialize, Debug, Clone)]
#[serde(untagged)] #[serde(untagged)]
pub enum ActionManifestModuleId<'a> { pub enum ActionManifestModuleId<'a> {
String(&'a str), String(&'a str),
Number(f64), Number(u64),
} }
#[derive( #[derive(
......
...@@ -44,7 +44,7 @@ describe('app-dir action handling', () => { ...@@ -44,7 +44,7 @@ describe('app-dir action handling', () => {
expect(itemInfo.filename).toBeString() expect(itemInfo.filename).toBeString()
// can be outside app dir but this test suite has them all in app // can be outside app dir but this test suite has them all in app
expect(itemInfo.filename.startsWith('app/')).toBe(true) expect(itemInfo.filename).toStartWith('app/')
expect(itemInfo.exportedName).toBeString() expect(itemInfo.exportedName).toBeString()
} catch (err) { } catch (err) {
require('console').error(`Invalid action entry ${item}`, err) require('console').error(`Invalid action entry ${item}`, err)
......
...@@ -2697,8 +2697,7 @@ describe('Cache Components Errors', () => { ...@@ -2697,8 +2697,7 @@ describe('Cache Components Errors', () => {
| ^", | ^",
"stack": [ "stack": [
"{module evaluation} app/use-cache-private-in-unstable-cache/page.tsx (21:38)", "{module evaluation} app/use-cache-private-in-unstable-cache/page.tsx (21:38)",
"{module evaluation} .next-internal/server/app/use-cache-private-in-unstable-cache/page/actions.js (server actions loader) (1:1)", "<FIXME-next-dist-dir>",
"<FIXME-file-protocol>",
"<FIXME-next-dist-dir>", "<FIXME-next-dist-dir>",
], ],
} }
...@@ -2754,8 +2753,8 @@ describe('Cache Components Errors', () => { ...@@ -2754,8 +2753,8 @@ describe('Cache Components Errors', () => {
expect(output).toMatchInlineSnapshot(` expect(output).toMatchInlineSnapshot(`
"Error: "use cache: private" must not be used within \`unstable_cache()\`. "Error: "use cache: private" must not be used within \`unstable_cache()\`.
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-unstable-cache/page.tsx:21:38) at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-unstable-cache/page.tsx:21:38)
at __TURBOPACK__module__evaluation__ (bundler:///.next-internal/server/app/use-cache-private-in-unstable-cache/page/actions.js (server actions loader):1:1)
at a (<next-dist-dir>) at a (<next-dist-dir>)
at b (<next-dist-dir>)
19 | } 19 | }
20 | 20 |
> 21 | const getCachedData = unstable_cache(async () => { > 21 | const getCachedData = unstable_cache(async () => {
...@@ -2773,7 +2772,6 @@ describe('Cache Components Errors', () => { ...@@ -2773,7 +2772,6 @@ describe('Cache Components Errors', () => {
expect(output).toMatchInlineSnapshot(` expect(output).toMatchInlineSnapshot(`
"Error: "use cache: private" must not be used within \`unstable_cache()\`. "Error: "use cache: private" must not be used within \`unstable_cache()\`.
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-unstable-cache/page.tsx:21:38) at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-unstable-cache/page.tsx:21:38)
at __TURBOPACK__module__evaluation__ (bundler:///.next-internal/server/app/use-cache-private-in-unstable-cache/page/actions.js%20(server%20actions%20loader):1:1)
at a (<next-dist-dir>) at a (<next-dist-dir>)
19 | } 19 | }
20 | 20 |
...@@ -2842,8 +2840,7 @@ describe('Cache Components Errors', () => { ...@@ -2842,8 +2840,7 @@ describe('Cache Components Errors', () => {
| ^", | ^",
"stack": [ "stack": [
"{module evaluation} app/use-cache-private-in-use-cache/page.tsx (15:1)", "{module evaluation} app/use-cache-private-in-use-cache/page.tsx (15:1)",
"{module evaluation} .next-internal/server/app/use-cache-private-in-use-cache/page/actions.js (server actions loader) (1:1)", "<FIXME-next-dist-dir>",
"<FIXME-file-protocol>",
"<FIXME-next-dist-dir>", "<FIXME-next-dist-dir>",
], ],
} }
...@@ -2900,8 +2897,8 @@ describe('Cache Components Errors', () => { ...@@ -2900,8 +2897,8 @@ describe('Cache Components Errors', () => {
expect(output).toMatchInlineSnapshot(` expect(output).toMatchInlineSnapshot(`
"Error: "use cache: private" must not be used within "use cache". It can only be nested inside of another "use cache: private". "Error: "use cache: private" must not be used within "use cache". It can only be nested inside of another "use cache: private".
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:1) at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:1)
at __TURBOPACK__module__evaluation__ (bundler:///.next-internal/server/app/use-cache-private-in-use-cache/page/actions.js (server actions loader):1:1)
at a (<next-dist-dir>) at a (<next-dist-dir>)
at b (<next-dist-dir>)
13 | } 13 | }
14 | 14 |
> 15 | async function Private() { > 15 | async function Private() {
...@@ -2911,8 +2908,8 @@ describe('Cache Components Errors', () => { ...@@ -2911,8 +2908,8 @@ describe('Cache Components Errors', () => {
18 | return <p>Private</p> 18 | return <p>Private</p>
Error: "use cache: private" must not be used within "use cache". It can only be nested inside of another "use cache: private". Error: "use cache: private" must not be used within "use cache". It can only be nested inside of another "use cache: private".
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:1) at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:1)
at __TURBOPACK__module__evaluation__ (bundler:///.next-internal/server/app/use-cache-private-in-use-cache/page/actions.js (server actions loader):1:1) at c (<next-dist-dir>)
at b (<next-dist-dir>) at d (<next-dist-dir>)
13 | } 13 | }
14 | 14 |
> 15 | async function Private() { > 15 | async function Private() {
...@@ -2930,7 +2927,6 @@ describe('Cache Components Errors', () => { ...@@ -2930,7 +2927,6 @@ describe('Cache Components Errors', () => {
expect(output).toMatchInlineSnapshot(` expect(output).toMatchInlineSnapshot(`
"Error: "use cache: private" must not be used within "use cache". It can only be nested inside of another "use cache: private". "Error: "use cache: private" must not be used within "use cache". It can only be nested inside of another "use cache: private".
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:1) at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:1)
at __TURBOPACK__module__evaluation__ (bundler:///.next-internal/server/app/use-cache-private-in-use-cache/page/actions.js%20(server%20actions%20loader):1:1)
at a (<next-dist-dir>) at a (<next-dist-dir>)
13 | } 13 | }
14 | 14 |
...@@ -2941,7 +2937,6 @@ describe('Cache Components Errors', () => { ...@@ -2941,7 +2937,6 @@ describe('Cache Components Errors', () => {
18 | return <p>Private</p> 18 | return <p>Private</p>
Error: "use cache: private" must not be used within "use cache". It can only be nested inside of another "use cache: private". Error: "use cache: private" must not be used within "use cache". It can only be nested inside of another "use cache: private".
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:1) at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:1)
at __TURBOPACK__module__evaluation__ (bundler:///.next-internal/server/app/use-cache-private-in-use-cache/page/actions.js%20(server%20actions%20loader):1:1)
at b (<next-dist-dir>) at b (<next-dist-dir>)
13 | } 13 | }
14 | 14 |
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment