diff --git a/crates/next-api/src/middleware.rs b/crates/next-api/src/middleware.rs index 63304b4b9d3f4..d5e75f30caf96 100644 --- a/crates/next-api/src/middleware.rs +++ b/crates/next-api/src/middleware.rs @@ -157,14 +157,14 @@ impl MiddlewareEndpoint { parse_segment_config_from_source(*self.await?.source, ParseSegmentMode::Base).await?; let runtime = config.runtime.unwrap_or(NextRuntime::Edge); - let next_config = this.project.next_config(); - let i18n = next_config.i18n().await?; - let has_i18n = i18n.is_some(); - let has_i18n_locales = i18n + let next_config = this.project.next_config().await?; + let has_i18n = next_config.i18n.is_some(); + let has_i18n_locales = next_config + .i18n .as_ref() .map(|i18n| i18n.locales.len() > 1) .unwrap_or(false); - let base_path = next_config.base_path().await?; + let base_path = next_config.base_path.as_ref(); let matchers = if let Some(matchers) = config.middleware_matcher.as_ref() { matchers @@ -202,7 +202,7 @@ impl MiddlewareEndpoint { source.insert_str(0, "/:nextData(_next/data/[^/]{1,})?"); - if let Some(base_path) = base_path.as_ref() { + if let Some(base_path) = base_path { source.insert_str(0, base_path); } diff --git a/crates/next-api/src/nft_json.rs b/crates/next-api/src/nft_json.rs index 9caa4f904faed..b156eda22d6f3 100644 --- a/crates/next-api/src/nft_json.rs +++ b/crates/next-api/src/nft_json.rs @@ -408,9 +408,7 @@ pub async fn all_assets_from_entries_filtered( Ok(( *asset, if emit_spans { - // INVALIDATION: we don't need to invalidate the list of assets when - // the span name changes - Some(asset.path_string().untracked().await?) + Some(asset.path().to_string().await?) } else { None }, @@ -500,9 +498,7 @@ async fn get_referenced_server_assets( Ok(Some(( *asset, if emit_spans { - // INVALIDATION: we don't need to invalidate the list of assets when the span - // name changes - Some(asset.path_string().untracked().await?) + Some(asset.path().to_string().await?) } else { None }, diff --git a/crates/next-api/src/project.rs b/crates/next-api/src/project.rs index 2d1328f9dcf51..d0aecf389a10f 100644 --- a/crates/next-api/src/project.rs +++ b/crates/next-api/src/project.rs @@ -479,8 +479,8 @@ impl ProjectContainer { } let dist_dir = next_config - .dist_dir() .await? + .dist_dir .as_ref() .map_or_else(|| rcstr!(".next"), |d| d.clone()); @@ -722,17 +722,13 @@ impl Project { #[turbo_tasks::function] pub async fn client_relative_path(self: Vc) -> Result> { - let next_config = self.next_config(); + let next_config = self.next_config().await?; Ok(self .client_root() .await? .join(&format!( "{}/_next", - next_config - .base_path() - .await? - .as_deref() - .unwrap_or_default(), + next_config.base_path.clone().unwrap_or_default(), ))? .cell()) } @@ -1160,38 +1156,26 @@ impl Project { *config.persistent_caching_enabled().await?, ); - emit_event( - "modularizeImports", - !config.modularize_imports().await?.is_empty(), - ); - emit_event( - "transpilePackages", - !config.transpile_packages().await?.is_empty(), - ); + let config = &config.await?; + + emit_event("modularizeImports", config.modularize_imports.is_some()); + emit_event("transpilePackages", config.transpile_packages.is_some()); emit_event("turbotrace", false); // compiler options - let compiler_options = config.compiler().await?; - let swc_relay_enabled = compiler_options.relay.is_some(); + let compiler_options = config.compiler.as_ref(); + let swc_relay_enabled = compiler_options.and_then(|c| c.relay.as_ref()).is_some(); let styled_components_enabled = compiler_options - .styled_components - .as_ref() - .map(|sc| sc.is_enabled()) + .and_then(|c| c.styled_components.as_ref().map(|sc| sc.is_enabled())) .unwrap_or_default(); let react_remove_properties_enabled = compiler_options - .react_remove_properties - .as_ref() - .map(|rc| rc.is_enabled()) + .and_then(|c| c.react_remove_properties.as_ref().map(|rc| rc.is_enabled())) .unwrap_or_default(); let remove_console_enabled = compiler_options - .remove_console - .as_ref() - .map(|rc| rc.is_enabled()) + .and_then(|c| c.remove_console.as_ref().map(|rc| rc.is_enabled())) .unwrap_or_default(); let emotion_enabled = compiler_options - .emotion - .as_ref() - .map(|e| e.is_enabled()) + .and_then(|c| c.emotion.as_ref().map(|e| e.is_enabled())) .unwrap_or_default(); emit_event("swcRelay", swc_relay_enabled); diff --git a/crates/next-core/src/emit.rs b/crates/next-core/src/emit.rs index d92a124d909e1..0e8f1b1f52190 100644 --- a/crates/next-core/src/emit.rs +++ b/crates/next-core/src/emit.rs @@ -2,7 +2,7 @@ use anyhow::Result; use tracing::{Instrument, Level, Span}; use turbo_rcstr::RcStr; use turbo_tasks::{ - FxIndexSet, ReadRef, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, Vc, + FxIndexSet, ReadRef, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, ValueToString, Vc, graph::{AdjacencyMap, GraphTraversal, Visit, VisitControlFlow}, }; use turbo_tasks_fs::{FileSystemPath, rebase}; @@ -161,9 +161,7 @@ pub async fn all_assets_from_entries(entries: Vc) -> Result "\"standalone\"", diff --git a/crates/next-core/src/next_client_reference/visit_client_reference.rs b/crates/next-core/src/next_client_reference/visit_client_reference.rs index 959c86b440f0b..f0a2862e2c2df 100644 --- a/crates/next-core/src/next_client_reference/visit_client_reference.rs +++ b/crates/next-core/src/next_client_reference/visit_client_reference.rs @@ -3,10 +3,10 @@ use std::future::Future; use anyhow::Result; use rustc_hash::FxHashSet; use serde::{Deserialize, Serialize}; -use tracing::{Instrument, Level, Span}; +use tracing::Instrument; use turbo_rcstr::RcStr; use turbo_tasks::{ - FxIndexSet, NonLocalValue, ReadRef, ResolvedVc, TryJoinIterExt, Vc, + FxIndexSet, NonLocalValue, ReadRef, ResolvedVc, TryJoinIterExt, ValueToString, Vc, debug::ValueDebugFormat, graph::{AdjacencyMap, GraphTraversal, Visit, VisitControlFlow}, trace::TraceRawVcs, @@ -121,23 +121,14 @@ pub async fn find_server_entries( include_traced: bool, ) -> Result> { async move { - let emit_spans = tracing::enabled!(Level::INFO); let graph = AdjacencyMap::new() .skip_duplicates() .visit( vec![FindServerEntriesNode::Internal( entry, - if emit_spans { - // INVALIDATION: we don't need to invalidate when the span name changes - Some(entry.ident_string().untracked().await?) - } else { - None - }, + entry.ident().to_string().await?, )], - FindServerEntries { - include_traced, - emit_spans, - }, + FindServerEntries { include_traced }, ) .await .completed()? @@ -170,7 +161,6 @@ pub async fn find_server_entries( struct FindServerEntries { /// Whether to walk ChunkingType::Traced references include_traced: bool, - emit_spans: bool, } #[derive( @@ -187,12 +177,9 @@ struct FindServerEntries { )] enum FindServerEntriesNode { ClientReference, - ServerComponentEntry( - ResolvedVc, - Option>, - ), - ServerUtilEntry(ResolvedVc, Option>), - Internal(ResolvedVc>, Option>), + ServerComponentEntry(ResolvedVc, ReadRef), + ServerUtilEntry(ResolvedVc, ReadRef), + Internal(ResolvedVc>, ReadRef), } impl Visit for FindServerEntries { @@ -221,7 +208,6 @@ impl Visit for FindServerEntries { FindServerEntriesNode::ServerUtilEntry(module, _) => Vc::upcast(**module), FindServerEntriesNode::ServerComponentEntry(module, _) => Vc::upcast(**module), }; - let emit_spans = self.emit_spans; async move { // Pass include_traced to reuse the same cached `primary_chunkable_referenced_modules` // task result, but the traced references will be filtered out again afterwards. @@ -249,13 +235,7 @@ impl Visit for FindServerEntries { { return Ok(FindServerEntriesNode::ServerComponentEntry( server_component_asset, - if emit_spans { - // INVALIDATION: we don't need to invalidate when the span name - // changes - Some(server_component_asset.ident_string().untracked().await?) - } else { - None - }, + server_component_asset.ident().to_string().await?, )); } @@ -264,24 +244,13 @@ impl Visit for FindServerEntries { { return Ok(FindServerEntriesNode::ServerUtilEntry( server_util_module, - if emit_spans { - // INVALIDATION: we don't need to invalidate when the span name - // changes - Some(module.ident_string().untracked().await?) - } else { - None - }, + module.ident().to_string().await?, )); } Ok(FindServerEntriesNode::Internal( *module, - if emit_spans { - // INVALIDATION: we don't need to invalidate when the span name changes - Some(module.ident_string().untracked().await?) - } else { - None - }, + module.ident().to_string().await?, )) }); @@ -292,21 +261,18 @@ impl Visit for FindServerEntries { } fn span(&mut self, node: &FindServerEntriesNode) -> tracing::Span { - if !self.emit_spans { - return Span::current(); - } match node { FindServerEntriesNode::ClientReference => { tracing::info_span!("client reference") } FindServerEntriesNode::Internal(_, name) => { - tracing::info_span!("module", name = display(name.as_ref().unwrap())) + tracing::info_span!("module", name = display(name)) } FindServerEntriesNode::ServerUtilEntry(_, name) => { - tracing::info_span!("server util", name = display(name.as_ref().unwrap())) + tracing::info_span!("server util", name = display(name)) } FindServerEntriesNode::ServerComponentEntry(_, name) => { - tracing::info_span!("layout segment", name = display(name.as_ref().unwrap())) + tracing::info_span!("layout segment", name = display(name)) } } } diff --git a/crates/next-core/src/next_config.rs b/crates/next-core/src/next_config.rs index 937e565c86e3e..9c102b9f6623a 100644 --- a/crates/next-core/src/next_config.rs +++ b/crates/next-core/src/next_config.rs @@ -75,40 +75,40 @@ impl Default for CacheKinds { #[derive(Clone, Debug, Default, PartialEq)] #[serde(default, rename_all = "camelCase")] pub struct NextConfig { - // IMPORTANT: all fields should be private and access should be wrapped within a turbo-tasks - // function. Otherwise changing NextConfig will lead to invalidating all tasks accessing it. - config_file: Option, - config_file_name: RcStr, + // TODO all fields should be private and access should be wrapped within a turbo-tasks function + // Otherwise changing NextConfig will lead to invalidating all tasks accessing it. + pub config_file: Option, + pub config_file_name: RcStr, /// In-memory cache size in bytes. /// /// If `cache_max_memory_size: 0` disables in-memory caching. - cache_max_memory_size: Option, + pub cache_max_memory_size: Option, /// custom path to a cache handler to use - cache_handler: Option, - - env: FxIndexMap, - experimental: ExperimentalConfig, - images: ImageConfig, - page_extensions: Vec, - react_compiler: Option, - react_production_profiling: Option, - react_strict_mode: Option, - transpile_packages: Option>, - modularize_imports: Option>, - dist_dir: Option, - deployment_id: Option, + pub cache_handler: Option, + + pub env: FxIndexMap, + pub experimental: ExperimentalConfig, + pub images: ImageConfig, + pub page_extensions: Vec, + pub react_compiler: Option, + pub react_production_profiling: Option, + pub react_strict_mode: Option, + pub transpile_packages: Option>, + pub modularize_imports: Option>, + pub dist_dir: Option, + pub deployment_id: Option, sass_options: Option, - trailing_slash: Option, - asset_prefix: Option, - base_path: Option, - skip_middleware_url_normalize: Option, - skip_trailing_slash_redirect: Option, - i18n: Option, - cross_origin: Option, - dev_indicators: Option, - output: Option, - turbopack: Option, + pub trailing_slash: Option, + pub asset_prefix: Option, + pub base_path: Option, + pub skip_middleware_url_normalize: Option, + pub skip_trailing_slash_redirect: Option, + pub i18n: Option, + pub cross_origin: Option, + pub dev_indicators: Option, + pub output: Option, + pub turbopack: Option, production_browser_source_maps: bool, output_file_tracing_includes: Option, output_file_tracing_excludes: Option, @@ -119,21 +119,21 @@ pub struct NextConfig { /// server-side bundles. /// /// [API Reference](https://nextjs.org/docs/pages/api-reference/next-config-js/bundlePagesRouterDependencies) - bundle_pages_router_dependencies: Option, + pub bundle_pages_router_dependencies: Option, /// A list of packages that should be treated as external on the server /// build. /// /// [API Reference](https://nextjs.org/docs/app/api-reference/next-config-js/serverExternalPackages) - server_external_packages: Option>, + pub server_external_packages: Option>, #[serde(rename = "_originalRedirects")] - original_redirects: Option>, + pub original_redirects: Option>, // Partially supported - compiler: Option, + pub compiler: Option, - optimize_fonts: Option, + pub optimize_fonts: Option, clean_dist_dir: bool, compress: bool, @@ -157,7 +157,7 @@ pub struct NextConfig { } #[derive( - Clone, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, + Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, )] #[serde(rename_all = "kebab-case")] pub enum CrossOriginConfig { @@ -165,9 +165,6 @@ pub enum CrossOriginConfig { UseCredentials, } -#[turbo_tasks::value(transparent)] -pub struct OptionCrossOriginConfig(Option); - #[derive( Clone, Debug, @@ -265,7 +262,7 @@ struct HttpAgentConfig { } #[derive( - Clone, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, + Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, )] #[serde(rename_all = "camelCase")] pub struct DomainLocale { @@ -276,7 +273,7 @@ pub struct DomainLocale { } #[derive( - Clone, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, + Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, )] #[serde(rename_all = "camelCase")] pub struct I18NConfig { @@ -286,11 +283,8 @@ pub struct I18NConfig { pub locales: Vec, } -#[turbo_tasks::value(transparent)] -pub struct OptionI18NConfig(Option); - #[derive( - Clone, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, + Clone, Debug, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, )] #[serde(rename_all = "kebab-case")] pub enum OutputType { @@ -298,9 +292,6 @@ pub enum OutputType { Export, } -#[turbo_tasks::value(transparent)] -pub struct OptionOutputType(Option); - #[derive( Debug, Clone, @@ -1339,11 +1330,6 @@ impl NextConfig { Vc::cell(self.output == Some(OutputType::Standalone)) } - #[turbo_tasks::function] - pub fn base_path(&self) -> Vc> { - Vc::cell(self.base_path.clone()) - } - #[turbo_tasks::function] pub fn cache_handler(&self, project_path: FileSystemPath) -> Result> { if let Some(handler) = &self.cache_handler { @@ -1545,11 +1531,6 @@ impl NextConfig { })) } - #[turbo_tasks::function] - pub fn inline_css(&self) -> Vc { - Vc::cell(self.experimental.inline_css.unwrap_or(false)) - } - #[turbo_tasks::function] pub fn mdx_rs(&self) -> Vc { let options = &self.experimental.mdx_rs; @@ -1585,11 +1566,6 @@ impl NextConfig { Vc::cell(self.modularize_imports.clone().unwrap_or_default()) } - #[turbo_tasks::function] - pub fn dist_dir(&self) -> Vc> { - Vc::cell(self.dist_dir.clone()) - } - #[turbo_tasks::function] pub fn experimental_cache_handlers( &self, @@ -1881,21 +1857,6 @@ impl NextConfig { )) } - #[turbo_tasks::function] - pub fn cross_origin(&self) -> Vc { - Vc::cell(self.cross_origin.clone()) - } - - #[turbo_tasks::function] - pub fn i18n(&self) -> Vc { - Vc::cell(self.i18n.clone()) - } - - #[turbo_tasks::function] - pub fn output(&self) -> Vc { - Vc::cell(self.output.clone()) - } - #[turbo_tasks::function] pub fn output_file_tracing_includes(&self) -> Vc { Vc::cell(self.output_file_tracing_includes.clone()) diff --git a/crates/next-core/src/next_manifests/client_reference_manifest.rs b/crates/next-core/src/next_manifests/client_reference_manifest.rs index 960ee9703dd33..532dc3af62451 100644 --- a/crates/next-core/src/next_manifests/client_reference_manifest.rs +++ b/crates/next-core/src/next_manifests/client_reference_manifest.rs @@ -175,7 +175,11 @@ async fn build_manifest( // TODO: Add `suffix` to the manifest for React to use. // entry_manifest.module_loading.prefix = prefix_path; - entry_manifest.module_loading.cross_origin = next_config.cross_origin().owned().await?; + entry_manifest.module_loading.cross_origin = next_config + .await? + .cross_origin + .as_ref() + .map(|p| p.to_owned()); let ClientReferencesChunks { client_component_client_chunks, layout_segment_client_chunks, @@ -438,7 +442,8 @@ async fn build_manifest( cached_chunk_paths(&mut client_chunk_path_cache, client_chunks.iter().copied()) .await?; // Inlining breaks HMR so it is always disabled in dev. - let inlined_css = *next_config.inline_css().await? && mode.is_production(); + let inlined_css = + next_config.await?.experimental.inline_css.unwrap_or(false) && mode.is_production(); for (chunk, chunk_path) in client_chunks_with_path { if let Some(path) = client_relative_path.get_path_to(&chunk_path) { diff --git a/turbopack/crates/turbopack-browser/src/chunking_context.rs b/turbopack/crates/turbopack-browser/src/chunking_context.rs index f8903e058525b..fb7732fd8eede 100644 --- a/turbopack/crates/turbopack-browser/src/chunking_context.rs +++ b/turbopack/crates/turbopack-browser/src/chunking_context.rs @@ -400,7 +400,7 @@ impl BrowserChunkingContext { self.minify_type.cell() } - /// Returns the chunk path information. + /// Returns the minify type. #[turbo_tasks::function] fn chunk_path_info(&self) -> Vc { ChunkPathInfo { diff --git a/turbopack/crates/turbopack-core/src/module.rs b/turbopack/crates/turbopack-core/src/module.rs index 1da1e018ea561..97db55d8ec248 100644 --- a/turbopack/crates/turbopack-core/src/module.rs +++ b/turbopack/crates/turbopack-core/src/module.rs @@ -1,5 +1,4 @@ -use turbo_rcstr::RcStr; -use turbo_tasks::{ResolvedVc, TaskInput, ValueToString, Vc}; +use turbo_tasks::{ResolvedVc, TaskInput, Vc}; use crate::{asset::Asset, ident::AssetIdent, reference::ModuleReferences}; @@ -19,13 +18,6 @@ pub trait Module: Asset { #[turbo_tasks::function] fn ident(&self) -> Vc; - /// The identifier of the [Module] as string. It's expected to be unique and capture - /// all properties of the [Module]. - #[turbo_tasks::function] - fn ident_string(self: Vc) -> Vc { - self.ident().to_string() - } - /// Other [Module]s or [OutputAsset]s referenced from this [Module]. // TODO refactor to avoid returning [OutputAsset]s here #[turbo_tasks::function] diff --git a/turbopack/crates/turbopack-core/src/module_graph/mod.rs b/turbopack/crates/turbopack-core/src/module_graph/mod.rs index 986d9fe05c509..d639a9b8df688 100644 --- a/turbopack/crates/turbopack-core/src/module_graph/mod.rs +++ b/turbopack/crates/turbopack-core/src/module_graph/mod.rs @@ -1702,8 +1702,7 @@ impl SingleModuleGraphBuilderNode { Ok(Self::Module { module, ident: if emit_spans { - // INVALIDATION: we don't need to invalidate when the span name changes - Some(ident.to_string().untracked().await?) + Some(ident.to_string().await?) } else { None }, @@ -1719,15 +1718,13 @@ impl SingleModuleGraphBuilderNode { ref_data, source, source_ident: if emit_spans { - // INVALIDATION: we don't need to invalidate when the span name changes - Some(source.ident_string().untracked().await?) + Some(source.ident().to_string().await?) } else { None }, target, target_ident: if emit_spans { - // INVALIDATION: we don't need to invalidate when the span name changes - Some(target.ident_string().untracked().await?) + Some(target.ident().to_string().await?) } else { None }, diff --git a/turbopack/crates/turbopack-core/src/output.rs b/turbopack/crates/turbopack-core/src/output.rs index 111ced479be42..540795c8ed95d 100644 --- a/turbopack/crates/turbopack-core/src/output.rs +++ b/turbopack/crates/turbopack-core/src/output.rs @@ -1,6 +1,5 @@ use anyhow::Result; -use turbo_rcstr::RcStr; -use turbo_tasks::{FxIndexSet, ResolvedVc, ValueToString, Vc}; +use turbo_tasks::{FxIndexSet, ResolvedVc, Vc}; use turbo_tasks_fs::FileSystemPath; use crate::asset::Asset; @@ -17,13 +16,6 @@ pub trait OutputAsset: Asset { #[turbo_tasks::function] fn path(&self) -> Vc; - /// The identifier of the [OutputAsset] as string. It's expected to be unique and - /// capture all properties of the [OutputAsset]. - #[turbo_tasks::function] - async fn path_string(self: Vc) -> Result> { - Ok(self.path().resolve().await?.to_string()) - } - /// Other references [OutputAsset]s from this [OutputAsset]. #[turbo_tasks::function] fn references(self: Vc) -> Vc {