Unverified Commit 8a51ebcb authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Revert "feat(turbopack): support basic next/dynamic" (#56885)

parent c1c419fd
...@@ -3440,7 +3440,6 @@ dependencies = [ ...@@ -3440,7 +3440,6 @@ dependencies = [
"either", "either",
"fxhash", "fxhash",
"hex", "hex",
"next-transform-dynamic",
"next-transform-font", "next-transform-font",
"once_cell", "once_cell",
"pathdiff", "pathdiff",
......
...@@ -15,6 +15,7 @@ either = "1" ...@@ -15,6 +15,7 @@ either = "1"
fxhash = "0.2.1" fxhash = "0.2.1"
hex = "0.4.3" hex = "0.4.3"
once_cell = { workspace = true } once_cell = { workspace = true }
next-transform-font = {workspace = true}
pathdiff = "0.2.0" pathdiff = "0.2.0"
regex = "1.5" regex = "1.5"
rustc-hash = "1" rustc-hash = "1"
...@@ -23,9 +24,6 @@ serde_json = "1" ...@@ -23,9 +24,6 @@ serde_json = "1"
sha1 = "0.10.1" sha1 = "0.10.1"
tracing = { version = "0.1.37" } tracing = { version = "0.1.37" }
next-transform-dynamic = { workspace = true }
next-transform-font = { workspace = true }
turbopack-binding = { workspace = true, features = [ turbopack-binding = { workspace = true, features = [
"__swc_core", "__swc_core",
"__swc_core_next_core", "__swc_core_next_core",
......
...@@ -37,7 +37,6 @@ use std::{cell::RefCell, path::PathBuf, rc::Rc, sync::Arc}; ...@@ -37,7 +37,6 @@ use std::{cell::RefCell, path::PathBuf, rc::Rc, sync::Arc};
use auto_cjs::contains_cjs; use auto_cjs::contains_cjs;
use either::Either; use either::Either;
use fxhash::FxHashSet; use fxhash::FxHashSet;
use next_transform_dynamic::{next_dynamic, NextDynamicMode};
use next_transform_font::next_font_loaders; use next_transform_font::next_font_loaders;
use serde::Deserialize; use serde::Deserialize;
use turbopack_binding::swc::{ use turbopack_binding::swc::{
...@@ -59,6 +58,7 @@ mod auto_cjs; ...@@ -59,6 +58,7 @@ mod auto_cjs;
pub mod cjs_optimizer; pub mod cjs_optimizer;
pub mod disallow_re_export_all_in_page; pub mod disallow_re_export_all_in_page;
pub mod named_import_transform; pub mod named_import_transform;
pub mod next_dynamic;
pub mod next_ssg; pub mod next_ssg;
pub mod optimize_barrel; pub mod optimize_barrel;
pub mod optimize_server_react; pub mod optimize_server_react;
...@@ -226,7 +226,7 @@ where ...@@ -226,7 +226,7 @@ where
!opts.disable_next_ssg !opts.disable_next_ssg
), ),
amp_attributes::amp_attributes(), amp_attributes::amp_attributes(),
next_dynamic( next_dynamic::next_dynamic(
opts.is_development, opts.is_development,
opts.is_server, opts.is_server,
match &opts.server_components { match &opts.server_components {
...@@ -238,7 +238,6 @@ where ...@@ -238,7 +238,6 @@ where
}, },
_ => false, _ => false,
}, },
NextDynamicMode::Webpack,
file.name.clone(), file.name.clone(),
opts.pages_dir.clone() opts.pages_dir.clone()
), ),
......
This diff is collapsed.
...@@ -2,13 +2,13 @@ use std::path::PathBuf; ...@@ -2,13 +2,13 @@ use std::path::PathBuf;
use next_swc::{ use next_swc::{
disallow_re_export_all_in_page::disallow_re_export_all_in_page, disallow_re_export_all_in_page::disallow_re_export_all_in_page,
next_dynamic::next_dynamic,
next_ssg::next_ssg, next_ssg::next_ssg,
react_server_components::server_components, react_server_components::server_components,
server_actions::{ server_actions::{
server_actions, {self}, server_actions, {self},
}, },
}; };
use next_transform_dynamic::{next_dynamic, NextDynamicMode};
use next_transform_font::{next_font_loaders, Config as FontLoaderConfig}; use next_transform_font::{next_font_loaders, Config as FontLoaderConfig};
use turbopack_binding::swc::{ use turbopack_binding::swc::{
core::{ core::{
...@@ -56,7 +56,6 @@ fn next_dynamic_errors(input: PathBuf) { ...@@ -56,7 +56,6 @@ fn next_dynamic_errors(input: PathBuf) {
true, true,
false, false,
false, false,
NextDynamicMode::Webpack,
FileName::Real(PathBuf::from("/some-project/src/some-file.js")), FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
Some("/some-project/src".into()), Some("/some-project/src".into()),
) )
......
...@@ -4,6 +4,7 @@ use next_swc::{ ...@@ -4,6 +4,7 @@ use next_swc::{
amp_attributes::amp_attributes, amp_attributes::amp_attributes,
cjs_optimizer::cjs_optimizer, cjs_optimizer::cjs_optimizer,
named_import_transform::named_import_transform, named_import_transform::named_import_transform,
next_dynamic::next_dynamic,
next_ssg::next_ssg, next_ssg::next_ssg,
optimize_barrel::optimize_barrel, optimize_barrel::optimize_barrel,
optimize_server_react::optimize_server_react, optimize_server_react::optimize_server_react,
...@@ -14,7 +15,6 @@ use next_swc::{ ...@@ -14,7 +15,6 @@ use next_swc::{
}, },
shake_exports::{shake_exports, Config as ShakeExportsConfig}, shake_exports::{shake_exports, Config as ShakeExportsConfig},
}; };
use next_transform_dynamic::{next_dynamic, NextDynamicMode};
use next_transform_font::{next_font_loaders, Config as FontLoaderConfig}; use next_transform_font::{next_font_loaders, Config as FontLoaderConfig};
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use turbopack_binding::swc::{ use turbopack_binding::swc::{
...@@ -64,7 +64,6 @@ fn next_dynamic_fixture(input: PathBuf) { ...@@ -64,7 +64,6 @@ fn next_dynamic_fixture(input: PathBuf) {
true, true,
false, false,
false, false,
NextDynamicMode::Webpack,
FileName::Real(PathBuf::from("/some-project/src/some-file.js")), FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
Some("/some-project/src".into()), Some("/some-project/src".into()),
) )
...@@ -80,7 +79,6 @@ fn next_dynamic_fixture(input: PathBuf) { ...@@ -80,7 +79,6 @@ fn next_dynamic_fixture(input: PathBuf) {
false, false,
false, false,
false, false,
NextDynamicMode::Webpack,
FileName::Real(PathBuf::from("/some-project/src/some-file.js")), FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
Some("/some-project/src".into()), Some("/some-project/src".into()),
) )
...@@ -96,7 +94,6 @@ fn next_dynamic_fixture(input: PathBuf) { ...@@ -96,7 +94,6 @@ fn next_dynamic_fixture(input: PathBuf) {
false, false,
true, true,
false, false,
NextDynamicMode::Webpack,
FileName::Real(PathBuf::from("/some-project/src/some-file.js")), FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
Some("/some-project/src".into()), Some("/some-project/src".into()),
) )
...@@ -119,7 +116,6 @@ fn app_dir_next_dynamic_fixture(input: PathBuf) { ...@@ -119,7 +116,6 @@ fn app_dir_next_dynamic_fixture(input: PathBuf) {
true, true,
false, false,
true, true,
NextDynamicMode::Webpack,
FileName::Real(PathBuf::from("/some-project/src/some-file.js")), FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
Some("/some-project/src".into()), Some("/some-project/src".into()),
) )
...@@ -135,7 +131,6 @@ fn app_dir_next_dynamic_fixture(input: PathBuf) { ...@@ -135,7 +131,6 @@ fn app_dir_next_dynamic_fixture(input: PathBuf) {
false, false,
false, false,
true, true,
NextDynamicMode::Webpack,
FileName::Real(PathBuf::from("/some-project/src/some-file.js")), FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
Some("/some-project/src".into()), Some("/some-project/src".into()),
) )
...@@ -151,7 +146,6 @@ fn app_dir_next_dynamic_fixture(input: PathBuf) { ...@@ -151,7 +146,6 @@ fn app_dir_next_dynamic_fixture(input: PathBuf) {
false, false,
true, true,
true, true,
NextDynamicMode::Webpack,
FileName::Real(PathBuf::from("/some-project/src/some-file.js")), FileName::Real(PathBuf::from("/some-project/src/some-file.js")),
Some("/some-project/src".into()), Some("/some-project/src".into()),
) )
......
use std::collections::HashMap;
use anyhow::{bail, Context, Result}; use anyhow::{bail, Context, Result};
use next_core::{ use next_core::{
app_structure::{ app_structure::{
...@@ -23,8 +21,7 @@ use next_core::{ ...@@ -23,8 +21,7 @@ use next_core::{
next_edge::route_regex::get_named_middleware_regex, next_edge::route_regex::get_named_middleware_regex,
next_manifests::{ next_manifests::{
AppBuildManifest, AppPathsManifest, BuildManifest, ClientReferenceManifest, AppBuildManifest, AppPathsManifest, BuildManifest, ClientReferenceManifest,
EdgeFunctionDefinition, LoadableManifest, MiddlewareMatcher, MiddlewaresManifestV2, EdgeFunctionDefinition, MiddlewareMatcher, MiddlewaresManifestV2, PagesManifest, Regions,
PagesManifest, Regions,
}, },
next_server::{ next_server::{
get_server_module_options_context, get_server_resolve_options_context, get_server_module_options_context, get_server_resolve_options_context,
...@@ -42,7 +39,7 @@ use turbopack_binding::{ ...@@ -42,7 +39,7 @@ use turbopack_binding::{
turbopack::{ turbopack::{
core::{ core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
chunk::{availability_info::AvailabilityInfo, ChunkingContext, EvaluatableAssets}, chunk::{ChunkingContext, EvaluatableAssets},
file_source::FileSource, file_source::FileSource,
module::Module, module::Module,
output::{OutputAsset, OutputAssets}, output::{OutputAsset, OutputAssets},
...@@ -56,10 +53,6 @@ use turbopack_binding::{ ...@@ -56,10 +53,6 @@ use turbopack_binding::{
}; };
use crate::{ use crate::{
dynamic_imports::{
collect_chunk_group, collect_evaluated_chunk_group, collect_next_dynamic_imports,
DynamicImportedChunks,
},
project::Project, project::Project,
route::{Endpoint, Route, Routes, WrittenEndpoint}, route::{Endpoint, Route, Routes, WrittenEndpoint},
server_actions::create_server_actions_manifest, server_actions::create_server_actions_manifest,
...@@ -686,67 +679,6 @@ impl AppEndpoint { ...@@ -686,67 +679,6 @@ impl AppEndpoint {
))) )))
} }
async fn create_react_loadable_manifest(
dynamic_import_entries: Vc<DynamicImportedChunks>,
ty: &'static str,
node_root: Vc<FileSystemPath>,
pathname: &str,
) -> Result<Vc<OutputAssets>> {
let dynamic_import_entries = &*dynamic_import_entries.await?;
let mut output = vec![];
let mut loadable_manifest: HashMap<String, LoadableManifest> = Default::default();
for (origin, dynamic_imports) in dynamic_import_entries.into_iter() {
let origin_path = &*origin.ident().path().await?;
for (import, chunk_output) in dynamic_imports {
let chunk_output = chunk_output.await?;
output.extend(chunk_output.iter().copied());
let id = format!("{} -> {}", origin_path, import);
let server_path = node_root.join("server".to_string());
let server_path_value = server_path.await?;
let files = chunk_output
.iter()
.map(move |&file| {
let server_path_value = server_path_value.clone();
async move {
Ok(server_path_value
.get_path_to(&*file.ident().path().await?)
.map(|path| path.to_string()))
}
})
.try_flat_join()
.await?;
let manifest_item = LoadableManifest {
id: id.clone(),
files,
};
loadable_manifest.insert(id, manifest_item);
}
}
let loadable_path_prefix = get_asset_prefix_from_pathname(pathname);
let loadable_manifest = Vc::upcast(VirtualOutputAsset::new(
node_root.join(format!(
"server/app{loadable_path_prefix}/{ty}/react-loadable-manifest.json",
)),
AssetContent::file(
FileContent::Content(File::from(serde_json::to_string_pretty(
&loadable_manifest,
)?))
.cell(),
),
));
output.push(loadable_manifest);
Ok(Vc::cell(output))
}
let endpoint_output = match app_entry.config.await?.runtime.unwrap_or_default() { let endpoint_output = match app_entry.config.await?.runtime.unwrap_or_default() {
NextRuntime::Edge => { NextRuntime::Edge => {
// create edge chunks // create edge chunks
...@@ -782,7 +714,7 @@ impl AppEndpoint { ...@@ -782,7 +714,7 @@ impl AppEndpoint {
let files = chunking_context.evaluated_chunk_group( let files = chunking_context.evaluated_chunk_group(
app_entry.rsc_entry.ident(), app_entry.rsc_entry.ident(),
Vc::cell(evaluatable_assets.clone()), Vc::cell(evaluatable_assets),
); );
server_assets.extend(files.await?.iter().copied()); server_assets.extend(files.await?.iter().copied());
...@@ -869,24 +801,6 @@ impl AppEndpoint { ...@@ -869,24 +801,6 @@ impl AppEndpoint {
)?; )?;
server_assets.push(app_paths_manifest_output); server_assets.push(app_paths_manifest_output);
// create react-loadable-manifest for next/dynamic
let dynamic_import_modules =
collect_next_dynamic_imports(app_entry.rsc_entry).await?;
let dynamic_import_entries = collect_evaluated_chunk_group(
chunking_context,
dynamic_import_modules,
Vc::cell(evaluatable_assets),
)
.await?;
let loadable_manifest_output = create_react_loadable_manifest(
dynamic_import_entries,
ty,
node_root,
&app_entry.pathname,
)
.await?;
server_assets.extend(loadable_manifest_output.await?.iter().copied());
AppEndpointOutput::Edge { AppEndpointOutput::Edge {
files, files,
server_assets: Vc::cell(server_assets), server_assets: Vc::cell(server_assets),
...@@ -943,25 +857,6 @@ impl AppEndpoint { ...@@ -943,25 +857,6 @@ impl AppEndpoint {
)?; )?;
server_assets.push(app_paths_manifest_output); server_assets.push(app_paths_manifest_output);
// create react-loadable-manifest for next/dynamic
let availability_info = Value::new(AvailabilityInfo::Root);
let dynamic_import_modules =
collect_next_dynamic_imports(app_entry.rsc_entry).await?;
let dynamic_import_entries = collect_chunk_group(
this.app_project.project().rsc_chunking_context(),
dynamic_import_modules,
availability_info,
)
.await?;
let loadable_manifest_output = create_react_loadable_manifest(
dynamic_import_entries,
ty,
node_root,
&app_entry.pathname,
)
.await?;
server_assets.extend(loadable_manifest_output.await?.iter().copied());
AppEndpointOutput::NodeJs { AppEndpointOutput::NodeJs {
rsc_chunk, rsc_chunk,
server_assets: Vc::cell(server_assets), server_assets: Vc::cell(server_assets),
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#![feature(async_fn_in_trait)] #![feature(async_fn_in_trait)]
mod app; mod app;
mod dynamic_imports;
mod entrypoints; mod entrypoints;
mod middleware; mod middleware;
mod pages; mod pages;
......
use std::collections::HashMap;
use anyhow::{bail, Context, Result}; use anyhow::{bail, Context, Result};
use indexmap::IndexMap; use indexmap::IndexMap;
use next_core::{ use next_core::{
...@@ -13,8 +11,8 @@ use next_core::{ ...@@ -13,8 +11,8 @@ use next_core::{
next_dynamic::NextDynamicTransition, next_dynamic::NextDynamicTransition,
next_edge::route_regex::get_named_middleware_regex, next_edge::route_regex::get_named_middleware_regex,
next_manifests::{ next_manifests::{
BuildManifest, EdgeFunctionDefinition, LoadableManifest, MiddlewareMatcher, BuildManifest, EdgeFunctionDefinition, MiddlewareMatcher, MiddlewaresManifestV2,
MiddlewaresManifestV2, PagesManifest, PagesManifest,
}, },
next_pages::create_page_ssr_entry_module, next_pages::create_page_ssr_entry_module,
next_server::{ next_server::{
...@@ -39,7 +37,7 @@ use turbopack_binding::{ ...@@ -39,7 +37,7 @@ use turbopack_binding::{
build::BuildChunkingContext, build::BuildChunkingContext,
core::{ core::{
asset::AssetContent, asset::AssetContent,
chunk::{availability_info::AvailabilityInfo, ChunkingContext, EvaluatableAssets}, chunk::{ChunkingContext, EvaluatableAssets},
context::AssetContext, context::AssetContext,
file_source::FileSource, file_source::FileSource,
issue::{IssueSeverity, OptionIssueSource}, issue::{IssueSeverity, OptionIssueSource},
...@@ -65,10 +63,6 @@ use turbopack_binding::{ ...@@ -65,10 +63,6 @@ use turbopack_binding::{
}; };
use crate::{ use crate::{
dynamic_imports::{
collect_chunk_group, collect_evaluated_chunk_group, collect_next_dynamic_imports,
DynamicImportedChunks,
},
project::Project, project::Project,
route::{Endpoint, Route, Routes, WrittenEndpoint}, route::{Endpoint, Route, Routes, WrittenEndpoint},
server_paths::all_server_paths, server_paths::all_server_paths,
...@@ -615,21 +609,9 @@ impl PageEndpoint { ...@@ -615,21 +609,9 @@ impl PageEndpoint {
evaluatable_assets.push(evaluatable); evaluatable_assets.push(evaluatable);
let edge_files = edge_chunking_context let edge_files = edge_chunking_context
.evaluated_chunk_group(ssr_module.ident(), Vc::cell(evaluatable_assets.clone())); .evaluated_chunk_group(ssr_module.ident(), Vc::cell(evaluatable_assets));
let dynamic_import_modules = collect_next_dynamic_imports(ssr_module).await?;
let dynamic_import_entries = collect_evaluated_chunk_group(
edge_chunking_context,
dynamic_import_modules,
Vc::cell(evaluatable_assets.clone()),
)
.await?;
Ok(SsrChunk::Edge { Ok(SsrChunk::Edge { files: edge_files }.cell())
files: edge_files,
dynamic_import_entries,
}
.cell())
} else { } else {
let ssr_module = create_page_ssr_entry_module( let ssr_module = create_page_ssr_entry_module(
this.pathname, this.pathname,
...@@ -651,15 +633,8 @@ impl PageEndpoint { ...@@ -651,15 +633,8 @@ impl PageEndpoint {
runtime_entries, runtime_entries,
); );
let availability_info = Value::new(AvailabilityInfo::Root);
let dynamic_import_modules = collect_next_dynamic_imports(ssr_module).await?;
let dynamic_import_entries =
collect_chunk_group(chunking_context, dynamic_import_modules, availability_info)
.await?;
Ok(SsrChunk::NodeJs { Ok(SsrChunk::NodeJs {
entry: ssr_entry_chunk, entry: ssr_entry_chunk,
dynamic_import_entries,
} }
.cell()) .cell())
} }
...@@ -753,78 +728,6 @@ impl PageEndpoint { ...@@ -753,78 +728,6 @@ impl PageEndpoint {
))) )))
} }
#[turbo_tasks::function]
async fn react_loadable_manifest(
self: Vc<Self>,
dynamic_import_entries: Vc<DynamicImportedChunks>,
) -> Result<Vc<OutputAssets>> {
let this = self.await?;
let node_root = this.pages_project.project().node_root();
let pages_dir = this.pages_project.pages_dir().await?;
let dynamic_import_entries = &*dynamic_import_entries.await?;
let mut output = vec![];
let mut loadable_manifest: HashMap<String, LoadableManifest> = Default::default();
for (origin, dynamic_imports) in dynamic_import_entries.into_iter() {
let origin_path = &*origin.ident().path().await?;
for (import, chunk_output) in dynamic_imports {
let chunk_output = chunk_output.await?;
output.extend(chunk_output.iter().copied());
// https://github.com/vercel/next.js/blob/b7c85b87787283d8fb86f705f67bdfabb6b654bb/packages/next-swc/crates/next-transform-dynamic/src/lib.rs#L230
// For the pages dir, next_dynamic transform puts relative paths to the pages
// dir for the origin import.
let id = format!(
"{} -> {}",
pages_dir
.get_path_to(origin_path)
.map_or_else(|| origin_path.to_string(), |path| path.to_string()),
import
);
let server_path = node_root.join("server".to_string());
let server_path_value = server_path.await?;
let files = chunk_output
.iter()
.map(move |file| {
let server_path_value = server_path_value.clone();
async move {
Ok(server_path_value
.get_path_to(&*file.ident().path().await?)
.map(|path| path.to_string()))
}
})
.try_flat_join()
.await?;
let manifest_item = LoadableManifest {
id: id.clone(),
files,
};
loadable_manifest.insert(id, manifest_item);
}
}
let loadable_path_prefix = get_asset_prefix_from_pathname(&this.pathname.await?);
let loadable_manifest = Vc::upcast(VirtualOutputAsset::new(
node_root.join(format!(
"server/pages{loadable_path_prefix}/react-loadable-manifest.json"
)),
AssetContent::file(
FileContent::Content(File::from(serde_json::to_string_pretty(
&loadable_manifest,
)?))
.cell(),
),
));
output.push(loadable_manifest);
Ok(Vc::cell(output))
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn build_manifest( async fn build_manifest(
self: Vc<Self>, self: Vc<Self>,
...@@ -893,27 +796,18 @@ impl PageEndpoint { ...@@ -893,27 +796,18 @@ impl PageEndpoint {
}; };
let page_output = match *ssr_chunk.await? { let page_output = match *ssr_chunk.await? {
SsrChunk::NodeJs { SsrChunk::NodeJs { entry } => {
entry,
dynamic_import_entries,
} => {
let pages_manifest = self.pages_manifest(entry); let pages_manifest = self.pages_manifest(entry);
server_assets.push(pages_manifest); server_assets.push(pages_manifest);
server_assets.push(entry); server_assets.push(entry);
let loadable_manifest_output = self.react_loadable_manifest(dynamic_import_entries);
server_assets.extend(loadable_manifest_output.await?.iter().copied());
PageEndpointOutput::NodeJs { PageEndpointOutput::NodeJs {
entry_chunk: entry, entry_chunk: entry,
server_assets: Vc::cell(server_assets), server_assets: Vc::cell(server_assets),
client_assets: Vc::cell(client_assets), client_assets: Vc::cell(client_assets),
} }
} }
SsrChunk::Edge { SsrChunk::Edge { files } => {
files,
dynamic_import_entries,
} => {
let node_root = this.pages_project.project().node_root(); let node_root = this.pages_project.project().node_root();
let files_value = files.await?; let files_value = files.await?;
if let Some(&file) = files_value.first() { if let Some(&file) = files_value.first() {
...@@ -973,9 +867,6 @@ impl PageEndpoint { ...@@ -973,9 +867,6 @@ impl PageEndpoint {
)); ));
server_assets.push(middleware_manifest_v2); server_assets.push(middleware_manifest_v2);
let loadable_manifest_output = self.react_loadable_manifest(dynamic_import_entries);
server_assets.extend(loadable_manifest_output.await?.iter().copied());
PageEndpointOutput::Edge { PageEndpointOutput::Edge {
files, files,
server_assets: Vc::cell(server_assets), server_assets: Vc::cell(server_assets),
...@@ -1110,12 +1001,6 @@ impl PageEndpointOutput { ...@@ -1110,12 +1001,6 @@ impl PageEndpointOutput {
#[turbo_tasks::value] #[turbo_tasks::value]
pub enum SsrChunk { pub enum SsrChunk {
NodeJs { NodeJs { entry: Vc<Box<dyn OutputAsset>> },
entry: Vc<Box<dyn OutputAsset>>, Edge { files: Vc<OutputAssets> },
dynamic_import_entries: Vc<DynamicImportedChunks>,
},
Edge {
files: Vc<OutputAssets>,
dynamic_import_entries: Vc<DynamicImportedChunks>,
},
} }
...@@ -145,17 +145,6 @@ pub struct AppPathsManifest { ...@@ -145,17 +145,6 @@ pub struct AppPathsManifest {
pub node_server_app_paths: PagesManifest, pub node_server_app_paths: PagesManifest,
} }
// A struct represent a single entry in react-loadable-manifest.json.
// The manifest is in a format of:
// { [`${origin} -> ${imported}`]: { id: `${origin} -> ${imported}`, files:
// string[] } }
#[derive(Serialize, Default, Debug)]
#[serde(rename_all = "camelCase")]
pub struct LoadableManifest {
pub id: String,
pub files: Vec<String>,
}
#[derive(Serialize, Default, Debug)] #[derive(Serialize, Default, Debug)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct ServerReferenceManifest { pub struct ServerReferenceManifest {
......
...@@ -65,7 +65,12 @@ impl CustomTransformer for NextJsDynamic { ...@@ -65,7 +65,12 @@ impl CustomTransformer for NextJsDynamic {
}, },
self.is_server, self.is_server,
self.is_server_components, self.is_server_components,
NextDynamicMode::Webpack, NextDynamicMode::Turbopack {
dynamic_transition_name: match self.mode {
NextMode::Development => "next-client-chunks".to_string(),
NextMode::Build => "next-dynamic".to_string(),
},
},
FileName::Real(ctx.file_path_str.into()), FileName::Real(ctx.file_path_str.into()),
self.pages_dir.clone(), self.pages_dir.clone(),
)); ));
......
...@@ -19,11 +19,6 @@ use swc_core::{ ...@@ -19,11 +19,6 @@ use swc_core::{
quote, quote,
}; };
/// Creates a SWC visitor to transform `next/dynamic` calls to have the
/// corresponding `loadableGenerated` property.
///
/// [NOTE] We do not use `NextDynamicMode::Turbopack` yet. It isn't compatible
/// with current loadable manifest, which causes hydration errors.
pub fn next_dynamic( pub fn next_dynamic(
is_development: bool, is_development: bool,
is_server: bool, is_server: bool,
...@@ -94,7 +89,6 @@ enum NextDynamicPatcherState { ...@@ -94,7 +89,6 @@ enum NextDynamicPatcherState {
Webpack, Webpack,
/// In Turbo mode, contains a list of modules that need to be imported with /// In Turbo mode, contains a list of modules that need to be imported with
/// the given transition under a particular ident. /// the given transition under a particular ident.
#[allow(unused)]
Turbopack { Turbopack {
dynamic_transition_name: String, dynamic_transition_name: String,
imports: Vec<TurbopackImport>, imports: Vec<TurbopackImport>,
......
...@@ -78,7 +78,6 @@ import { ...@@ -78,7 +78,6 @@ import {
PAGES_MANIFEST, PAGES_MANIFEST,
PHASE_DEVELOPMENT_SERVER, PHASE_DEVELOPMENT_SERVER,
SERVER_REFERENCE_MANIFEST, SERVER_REFERENCE_MANIFEST,
REACT_LOADABLE_MANIFEST,
} from '../../../shared/lib/constants' } from '../../../shared/lib/constants'
import { getMiddlewareRouteMatcher } from '../../../shared/lib/router/utils/middleware-route-matcher' import { getMiddlewareRouteMatcher } from '../../../shared/lib/router/utils/middleware-route-matcher'
...@@ -118,7 +117,6 @@ import { normalizeMetadataRoute } from '../../../lib/metadata/get-metadata-route ...@@ -118,7 +117,6 @@ import { normalizeMetadataRoute } from '../../../lib/metadata/get-metadata-route
import { clearModuleContext } from '../render-server' import { clearModuleContext } from '../render-server'
import type { ActionManifest } from '../../../build/webpack/plugins/flight-client-entry-plugin' import type { ActionManifest } from '../../../build/webpack/plugins/flight-client-entry-plugin'
import { denormalizePagePath } from '../../../shared/lib/page-path/denormalize-page-path' import { denormalizePagePath } from '../../../shared/lib/page-path/denormalize-page-path'
import type { LoadableManifest } from '../../load-components'
const wsServer = new ws.Server({ noServer: true }) const wsServer = new ws.Server({ noServer: true })
...@@ -505,7 +503,6 @@ async function startWatcher(opts: SetupOpts) { ...@@ -505,7 +503,6 @@ async function startWatcher(opts: SetupOpts) {
ws, ws,
Map<string, AsyncIterator<any>> Map<string, AsyncIterator<any>>
>() >()
const loadbleManifests = new Map<string, LoadableManifest>()
const clients = new Set<ws>() const clients = new Set<ws>()
async function loadMiddlewareManifest( async function loadMiddlewareManifest(
...@@ -563,16 +560,6 @@ async function startWatcher(opts: SetupOpts) { ...@@ -563,16 +560,6 @@ async function startWatcher(opts: SetupOpts) {
) )
} }
async function loadLoadableManifest(
pageName: string,
type: 'app' | 'pages' = 'pages'
): Promise<void> {
loadbleManifests.set(
pageName,
await loadPartialManifest(REACT_LOADABLE_MANIFEST, pageName, type)
)
}
const buildingReported = new Set<string>() const buildingReported = new Set<string>()
async function changeSubscription( async function changeSubscription(
...@@ -710,14 +697,6 @@ async function startWatcher(opts: SetupOpts) { ...@@ -710,14 +697,6 @@ async function startWatcher(opts: SetupOpts) {
return manifest return manifest
} }
function mergeLoadableManifests(manifests: Iterable<LoadableManifest>) {
const manifest: LoadableManifest = {}
for (const m of manifests) {
Object.assign(manifest, m)
}
return manifest
}
async function writeFileAtomic( async function writeFileAtomic(
filePath: string, filePath: string,
content: string content: string
...@@ -887,14 +866,13 @@ async function startWatcher(opts: SetupOpts) { ...@@ -887,14 +866,13 @@ async function startWatcher(opts: SetupOpts) {
) )
} }
async function writeLoadableManifest(): Promise<void> { async function writeOtherManifests(): Promise<void> {
const loadableManifest = mergeLoadableManifests(loadbleManifests.values()) const loadableManifestPath = path.join(
const loadableManifestPath = path.join(distDir, REACT_LOADABLE_MANIFEST) distDir,
deleteCache(loadableManifestPath) 'react-loadable-manifest.json'
await writeFileAtomic(
loadableManifestPath,
JSON.stringify(loadableManifest, null, 2)
) )
deleteCache(loadableManifestPath)
await writeFileAtomic(loadableManifestPath, JSON.stringify({}, null, 2))
} }
async function subscribeToHmrEvents(id: string, client: ws) { async function subscribeToHmrEvents(id: string, client: ws) {
...@@ -1074,8 +1052,8 @@ async function startWatcher(opts: SetupOpts) { ...@@ -1074,8 +1052,8 @@ async function startWatcher(opts: SetupOpts) {
await writeAppPathsManifest() await writeAppPathsManifest()
await writeMiddlewareManifest() await writeMiddlewareManifest()
await writeActionManifest() await writeActionManifest()
await writeOtherManifests()
await writeFontManifest() await writeFontManifest()
await writeLoadableManifest()
const turbopackHotReloader: NextJsHotReloaderInterface = { const turbopackHotReloader: NextJsHotReloaderInterface = {
turbopackProject: project, turbopackProject: project,
...@@ -1242,7 +1220,7 @@ async function startWatcher(opts: SetupOpts) { ...@@ -1242,7 +1220,7 @@ async function startWatcher(opts: SetupOpts) {
await writeFallbackBuildManifest() await writeFallbackBuildManifest()
await writePagesManifest() await writePagesManifest()
await writeMiddlewareManifest() await writeMiddlewareManifest()
await writeLoadableManifest() await writeOtherManifests()
return return
} }
...@@ -1351,13 +1329,12 @@ async function startWatcher(opts: SetupOpts) { ...@@ -1351,13 +1329,12 @@ async function startWatcher(opts: SetupOpts) {
} else { } else {
middlewareManifests.delete(page) middlewareManifests.delete(page)
} }
await loadLoadableManifest(page, 'pages')
await writeBuildManifest(opts.fsChecker.rewrites) await writeBuildManifest(opts.fsChecker.rewrites)
await writeFallbackBuildManifest() await writeFallbackBuildManifest()
await writePagesManifest() await writePagesManifest()
await writeMiddlewareManifest() await writeMiddlewareManifest()
await writeLoadableManifest() await writeOtherManifests()
processIssues(page, page, writtenEndpoint) processIssues(page, page, writtenEndpoint)
...@@ -1381,11 +1358,10 @@ async function startWatcher(opts: SetupOpts) { ...@@ -1381,11 +1358,10 @@ async function startWatcher(opts: SetupOpts) {
} else { } else {
middlewareManifests.delete(page) middlewareManifests.delete(page)
} }
await loadLoadableManifest(page, 'pages')
await writePagesManifest() await writePagesManifest()
await writeMiddlewareManifest() await writeMiddlewareManifest()
await writeLoadableManifest() await writeOtherManifests()
processIssues(page, page, writtenEndpoint) processIssues(page, page, writtenEndpoint)
...@@ -1419,7 +1395,7 @@ async function startWatcher(opts: SetupOpts) { ...@@ -1419,7 +1395,7 @@ async function startWatcher(opts: SetupOpts) {
await writeAppPathsManifest() await writeAppPathsManifest()
await writeMiddlewareManifest() await writeMiddlewareManifest()
await writeActionManifest() await writeActionManifest()
await writeLoadableManifest() await writeOtherManifests()
processIssues(page, page, writtenEndpoint, true) processIssues(page, page, writtenEndpoint, true)
...@@ -1444,7 +1420,7 @@ async function startWatcher(opts: SetupOpts) { ...@@ -1444,7 +1420,7 @@ async function startWatcher(opts: SetupOpts) {
await writeAppPathsManifest() await writeAppPathsManifest()
await writeMiddlewareManifest() await writeMiddlewareManifest()
await writeMiddlewareManifest() await writeMiddlewareManifest()
await writeLoadableManifest() await writeOtherManifests()
processIssues(page, page, writtenEndpoint, true) processIssues(page, page, writtenEndpoint, true)
......
...@@ -33,17 +33,6 @@ export type ManifestItem = { ...@@ -33,17 +33,6 @@ export type ManifestItem = {
export type ReactLoadableManifest = { [moduleId: string]: ManifestItem } export type ReactLoadableManifest = { [moduleId: string]: ManifestItem }
/**
* A manifest entry type for the react-loadable-manifest.json.
*
* The whole manifest.json is a type of `Record<pathName, LoadableManifest>`
* where pathName is a string-based key points to the path of the page contains
* each dynamic imports.
*/
export interface LoadableManifest {
[k: string]: { id: string | number; files: string[] }
}
export type LoadComponentsReturnType<NextModule = any> = { export type LoadComponentsReturnType<NextModule = any> = {
Component: NextComponentType Component: NextComponentType
pageConfig: PageConfig pageConfig: PageConfig
......
...@@ -237,35 +237,32 @@ describe.each([ ...@@ -237,35 +237,32 @@ describe.each([
}) })
} }
}) })
// Turbopack doesn't have this feature.
;(process.env.TURBOPACK ? describe.skip : describe)(
'custom chunkfilename',
() => {
it('should render the correct filename', async () => {
const $ = await get$(basePath + '/dynamic/chunkfilename')
expect($('body').text()).toMatch(/test chunkfilename/)
expect($('html').html()).toMatch(/hello-world\.js/)
})
it('should render the component on client side', async () => { describe('custom chunkfilename', () => {
let browser it('should render the correct filename', async () => {
try { const $ = await get$(basePath + '/dynamic/chunkfilename')
browser = await webdriver( expect($('body').text()).toMatch(/test chunkfilename/)
next.url, expect($('html').html()).toMatch(/hello-world\.js/)
basePath + '/dynamic/chunkfilename' })
)
await check( it('should render the component on client side', async () => {
() => browser.elementByCss('body').text(), let browser
/test chunkfilename/ try {
) browser = await webdriver(
} finally { next.url,
if (browser) { basePath + '/dynamic/chunkfilename'
await browser.close() )
} await check(
() => browser.elementByCss('body').text(),
/test chunkfilename/
)
} finally {
if (browser) {
await browser.close()
} }
}) }
} })
) })
describe('custom loading', () => { describe('custom loading', () => {
it('should render custom loading on the server side when `ssr:false` and `loading` is provided', async () => { it('should render custom loading on the server side when `ssr:false` and `loading` is provided', async () => {
...@@ -292,49 +289,45 @@ describe.each([ ...@@ -292,49 +289,45 @@ describe.each([
}) })
}) })
// TODO: Make this test work with Turbopack. Currently the test relies on `chunkFileName` which is not supported by Turbopack. describe('Multiple modules', () => {
;(process.env.TURBOPACK ? describe.skip : describe)( it('should only include the rendered module script tag', async () => {
'Multiple modules', const $ = await get$(basePath + '/dynamic/multiple-modules')
() => { const html = $('html').html()
it('should only include the rendered module script tag', async () => { expect(html).toMatch(/hello1\.js/)
const $ = await get$(basePath + '/dynamic/multiple-modules') expect(html).not.toMatch(/hello2\.js/)
const html = $('html').html() })
it('should only load the rendered module in the browser', async () => {
let browser
try {
browser = await webdriver(
next.url,
basePath + '/dynamic/multiple-modules'
)
const html = await browser.eval(
'document.documentElement.innerHTML'
)
expect(html).toMatch(/hello1\.js/) expect(html).toMatch(/hello1\.js/)
expect(html).not.toMatch(/hello2\.js/) expect(html).not.toMatch(/hello2\.js/)
}) } finally {
if (browser) {
it('should only load the rendered module in the browser', async () => { await browser.close()
let browser
try {
browser = await webdriver(
next.url,
basePath + '/dynamic/multiple-modules'
)
const html = await browser.eval(
'document.documentElement.innerHTML'
)
expect(html).toMatch(/hello1\.js/)
expect(html).not.toMatch(/hello2\.js/)
} finally {
if (browser) {
await browser.close()
}
} }
}) }
})
it('should only render one bundle if component is used multiple times', async () => { it('should only render one bundle if component is used multiple times', async () => {
const $ = await get$(basePath + '/dynamic/multiple-modules') const $ = await get$(basePath + '/dynamic/multiple-modules')
const html = $('html').html() const html = $('html').html()
try { try {
expect(html.match(/chunks[\\/]hello1\.js/g).length).toBe(1) expect(html.match(/chunks[\\/]hello1\.js/g).length).toBe(1)
expect(html).not.toMatch(/hello2\.js/) expect(html).not.toMatch(/hello2\.js/)
} catch (err) { } catch (err) {
console.error(html) console.error(html)
throw err throw err
} }
}) })
} })
)
}) })
} }
) )
......
...@@ -46,38 +46,31 @@ function runTests() { ...@@ -46,38 +46,31 @@ function runTests() {
}) })
} }
// This test is not needed for Turbopack as it relies on an experimental webpack feature. describe('next/dynamic', () => {
;(process.env.TURBOPACK ? describe.skip : describe)( describe('dev mode', () => {
'next/dynamic lazy compilation', beforeAll(async () => {
() => { appPort = await findPort()
describe('dev mode', () => { app = await launchApp(appDir, appPort)
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
}) })
;(process.env.TURBOPACK ? describe.skip : describe)( afterAll(() => killApp(app))
'production mode',
() => { runTests(true)
beforeAll(async () => { })
await runNextCommand(['build', appDir]) ;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
beforeAll(async () => {
await runNextCommand(['build', appDir])
app = nextServer({ app = nextServer({
dir: appDir, dir: appDir,
dev: false, dev: false,
quiet: true, quiet: true,
}) })
server = await startApp(app) server = await startApp(app)
appPort = server.address().port appPort = server.address().port
}) })
afterAll(() => stopApp(server)) afterAll(() => stopApp(server))
runTests() runTests()
} })
) })
}
)
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