Commit 08dc46f3 authored by Luke Sandberg's avatar Luke Sandberg

add some debugging feedback

parent d372f051
...@@ -19,15 +19,16 @@ ...@@ -19,15 +19,16 @@
//! to wait until all the dynamic components are being loaded, this ensures hydration mismatch //! to wait until all the dynamic components are being loaded, this ensures hydration mismatch
//! won't occur //! won't occur
use anyhow::{Context, Result}; use anyhow::{Result, bail};
use bincode::{Decode, Encode}; use bincode::{Decode, Encode};
use next_core::{ use next_core::{
next_app::ClientReferencesChunks, next_client_reference::EcmascriptClientReferenceModule, next_app::ClientReferencesChunks,
next_client_reference::{ClientReferenceType, EcmascriptClientReferenceModule},
next_dynamic::NextDynamicEntryModule, next_dynamic::NextDynamicEntryModule,
}; };
use turbo_tasks::{ use turbo_tasks::{
FxIndexMap, NonLocalValue, ReadRef, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, Vc, FxIndexMap, NonLocalValue, ReadRef, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt,
debug::ValueDebugFormat, trace::TraceRawVcs, ValueToString, Vc, debug::ValueDebugFormat, trace::TraceRawVcs,
}; };
use turbopack_core::{ use turbopack_core::{
chunk::{ChunkGroupResult, ChunkableModule}, chunk::{ChunkGroupResult, ChunkableModule},
...@@ -38,6 +39,19 @@ use turbopack_core::{ ...@@ -38,6 +39,19 @@ use turbopack_core::{
use crate::module_graph::DynamicImportEntriesWithImporter; use crate::module_graph::DynamicImportEntriesWithImporter;
/// Helper to get a descriptive string for a ClientReferenceType
async fn client_reference_type_to_string(ty: &ClientReferenceType) -> Result<String> {
match ty {
ClientReferenceType::EcmascriptClientReference(ecma_ref) => {
let module = ecma_ref.await?;
Ok(module.server_ident.to_string().await?.to_string())
}
ClientReferenceType::CssClientReference(css_ref) => {
Ok(css_ref.ident().to_string().await?.to_string())
}
}
}
pub(crate) enum NextDynamicChunkAvailability<'a> { pub(crate) enum NextDynamicChunkAvailability<'a> {
/// In App Router, the client references chunks contain the async loaders /// In App Router, the client references chunks contain the async loaders
ClientReferences(&'a ClientReferencesChunks), ClientReferences(&'a ClientReferencesChunks),
...@@ -67,26 +81,55 @@ pub(crate) async fn collect_next_dynamic_chunks( ...@@ -67,26 +81,55 @@ pub(crate) async fn collect_next_dynamic_chunks(
NextDynamicChunkAvailability::ClientReferences(client_reference_chunks) => { NextDynamicChunkAvailability::ClientReferences(client_reference_chunks) => {
// For App Router: look up the chunk group for the parent client reference, // For App Router: look up the chunk group for the parent client reference,
// then find the async loader for this dynamic entry // then find the async loader for this dynamic entry
let parent_ref = parent_client_reference let Some(parent_ref) = parent_client_reference else {
.context("Parent client reference not found for next/dynamic import")?; let dynamic_ident = dynamic_entry.ident().to_string().await?;
let chunk_group = client_reference_chunks bail!(
"Parent client reference not found for next/dynamic import.\nDynamic \
entry: {dynamic_ident}"
);
};
let Some(chunk_group_vc) = client_reference_chunks
.client_component_client_chunks .client_component_client_chunks
.get(&parent_ref) .get(parent_ref)
.context("Client reference chunk group not found for next/dynamic import")? else {
.await?; let dynamic_ident = dynamic_entry.ident().to_string().await?;
let parent_ident = client_reference_type_to_string(parent_ref).await?;
bail!(
"Client reference chunk group not found for next/dynamic \
import.\nDynamic entry: {dynamic_ident}\nParent client reference: \
{parent_ident}"
);
};
let chunk_group = chunk_group_vc.await?;
// Copy the ResolvedVc out of the map to avoid lifetime issues // Copy the ResolvedVc out of the map to avoid lifetime issues
*chunk_group.async_loaders_by_module.get(&module).context( let Some(loader) = chunk_group.async_loaders_by_module.get(&module) else {
"Dynamic entry not found in async loaders - this may indicate the dynamic \ let dynamic_ident = dynamic_entry.ident().to_string().await?;
import is not reachable from the client reference", let parent_ident = client_reference_type_to_string(parent_ref).await?;
)? let available_count = chunk_group.async_loaders_by_module.len();
bail!(
"Dynamic entry not found in async loaders - this may indicate the \
dynamic import is not reachable from the client reference.\nDynamic \
entry: {dynamic_ident}\nParent client reference: \
{parent_ident}\nAvailable async loaders in chunk group: \
{available_count}"
);
};
*loader
} }
NextDynamicChunkAvailability::PageChunkGroup(chunk_group) => { NextDynamicChunkAvailability::PageChunkGroup(chunk_group) => {
// For Pages Router: look up directly in the page's chunk group // For Pages Router: look up directly in the page's chunk group
// Copy the ResolvedVc out of the map to avoid lifetime issues // Copy the ResolvedVc out of the map to avoid lifetime issues
*chunk_group.async_loaders_by_module.get(&module).context( let Some(loader) = chunk_group.async_loaders_by_module.get(&module) else {
"Dynamic entry not found in async loaders - this may indicate the dynamic \ let dynamic_ident = dynamic_entry.ident().to_string().await?;
import is not reachable from the page entry", let available_count = chunk_group.async_loaders_by_module.len();
)? bail!(
"Dynamic entry not found in async loaders - this may indicate the \
dynamic import is not reachable from the page entry.\nDynamic entry: \
{dynamic_ident}\nAvailable async loaders in chunk group: \
{available_count}"
);
};
*loader
} }
}; };
......
...@@ -12,7 +12,8 @@ use swc_core::{ ...@@ -12,7 +12,8 @@ use swc_core::{
}; };
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ use turbo_tasks::{
FxIndexMap, NonLocalValue, ResolvedVc, TaskInput, TryJoinIterExt, Vc, debug::ValueDebugFormat, FxIndexMap, NonLocalValue, ResolvedVc, TaskInput, TryJoinIterExt, Vc,
debug::{ValueDebug, ValueDebugFormat},
trace::TraceRawVcs, trace::TraceRawVcs,
}; };
use turbopack_core::{ use turbopack_core::{
...@@ -372,9 +373,13 @@ async fn to_single_pattern_mapping( ...@@ -372,9 +373,13 @@ async fn to_single_pattern_mapping(
CodeGenerationIssue { CodeGenerationIssue {
severity: IssueSeverity::Bug, severity: IssueSeverity::Bug,
title: StyledString::Text(rcstr!("non-ecmascript placeable asset")).resolved_cell(), title: StyledString::Text(rcstr!("non-ecmascript placeable asset")).resolved_cell(),
message: StyledString::Text(rcstr!( message: StyledString::Text(
"asset is not placeable in ESM chunks, so it doesn't have a module id" format!(
)) "asset is not placeable in ESM chunks, so it doesn't have a module id: {}",
module.dbg_depth(2).await?
)
.into(),
)
.resolved_cell(), .resolved_cell(),
path: origin.origin_path().owned().await?, path: origin.origin_path().owned().await?,
source: None, source: None,
......
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