Skip to content

Commit 7c4338f

Browse files
lubieowocemmastrac
authored andcommitted
[Instant] Fix crash with search params (#89922)
In dev validation, we're disassembling a payload from a dynamic render. If the request had search params, page segments in the router state will have them attached: `__PAGE__?{"q":"123"}`. In `findNavigationsToValidate`, we do the equivalent of constructing a flightRouterState, so we need to match that, otherwise we'll name the segment `__PAGE__` instead and then can't look it up in the cache, and crash during validation.
1 parent 87f609e commit 7c4338f

File tree

79 files changed

+878
-1117
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+878
-1117
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/next-api/src/dynamic_imports.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use turbo_tasks::{
3030
debug::ValueDebugFormat, trace::TraceRawVcs,
3131
};
3232
use turbopack_core::{
33-
chunk::{ChunkableModule, ChunkingContext, availability_info::AvailabilityInfo},
33+
chunk::{ChunkingContext, availability_info::AvailabilityInfo},
3434
module::Module,
3535
module_graph::{ModuleGraph, ModuleGraphLayer},
3636
output::{OutputAssetsReference, OutputAssetsWithReferenced},
@@ -55,7 +55,7 @@ pub(crate) async fn collect_next_dynamic_chunks(
5555
let dynamic_import_chunks = dynamic_import_entries
5656
.iter()
5757
.map(|(dynamic_entry, parent_client_reference)| async move {
58-
let module = ResolvedVc::upcast::<Box<dyn ChunkableModule>>(*dynamic_entry);
58+
let module = ResolvedVc::upcast::<Box<dyn Module>>(*dynamic_entry);
5959

6060
// This is the availability info for the parent chunk group, i.e. the client reference
6161
// containing the next/dynamic imports

crates/next-api/src/pages.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -657,18 +657,28 @@ impl PageEndpoint {
657657
Vc::upcast(this.pages_project.client_module_context()),
658658
self.source(),
659659
this.pathname.clone(),
660-
);
660+
)
661+
.to_resolved()
662+
.await?;
663+
let is_chunkable = this
664+
.pages_project
665+
.project()
666+
.client_chunking_context()
667+
.chunking_configs()
668+
.await?
669+
.is_chunkable(page_loader)
670+
.await;
661671
if matches!(
662672
*this.pages_project.project().next_mode().await?,
663673
NextMode::Development
664-
) && let Some(chunkable) = ResolvedVc::try_downcast(page_loader.to_resolved().await?)
674+
) && is_chunkable
665675
{
666676
return Ok(Vc::upcast(HmrEntryModule::new(
667677
AssetIdent::from_path(this.page.await?.base_path.clone()),
668-
*chunkable,
678+
*page_loader,
669679
)));
670680
}
671-
Ok(page_loader)
681+
Ok(*page_loader)
672682
}
673683

674684
#[turbo_tasks::function]

crates/next-api/src/server_actions.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ use turbo_tasks::{
2626
use turbo_tasks_fs::{self, File, FileContent, FileSystemPath, rope::RopeBuilder};
2727
use turbopack_core::{
2828
asset::AssetContent,
29-
chunk::{
30-
ChunkItem, ChunkItemExt, ChunkableModule, ChunkingContext, EvaluatableAsset, ModuleId,
31-
},
29+
chunk::{ChunkItem, ChunkItemExt, ChunkingContext, EvaluatableAsset, ModuleId},
3230
context::AssetContext,
3331
file_source::FileSource,
3432
ident::AssetIdent,
@@ -78,7 +76,7 @@ pub(crate) async fn create_server_actions_manifest(
7876
ResolvedVc::try_sidecast::<Box<dyn EvaluatableAsset>>(loader.to_resolved().await?)
7977
.context("loader module must be evaluatable")?;
8078

81-
let chunk_item = loader.as_chunk_item(module_graph, chunking_context);
79+
let chunk_item = ChunkItem::new(Vc::upcast(loader), module_graph, chunking_context);
8280
let manifest = build_manifest(
8381
node_root,
8482
page_name,
@@ -158,7 +156,7 @@ async fn build_manifest(
158156
page_name: RcStr,
159157
runtime: NextRuntime,
160158
actions: Vc<AllActions>,
161-
chunk_item: Vc<Box<dyn ChunkItem>>,
159+
chunk_item: Vc<ChunkItem>,
162160
async_module_info: Vc<AsyncModulesInfo>,
163161
) -> Result<ResolvedVc<Box<dyn OutputAsset>>> {
164162
let manifest_path_prefix = &page_name;

crates/next-api/src/webpack_stats.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ where
2525
{
2626
let mut assets = vec![];
2727
let mut chunks = vec![];
28-
let mut chunk_items: FxIndexMap<Vc<Box<dyn ChunkItem>>, FxIndexSet<RcStr>> =
29-
FxIndexMap::default();
28+
let mut chunk_items: FxIndexMap<Vc<ChunkItem>, FxIndexSet<RcStr>> = FxIndexMap::default();
3029

3130
let entry_assets = entry_assets.into_iter().collect::<Vec<_>>();
3231

crates/next-core/src/hmr_entry.rs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use turbo_tasks_fs::{FileSystem, VirtualFileSystem, rope::RopeBuilder};
77
use turbopack_core::{
88
asset::{Asset, AssetContent},
99
chunk::{
10-
AsyncModuleInfo, ChunkItem, ChunkableModule, ChunkingContext, ChunkingType,
11-
ChunkingTypeOption, EvaluatableAsset,
10+
AsyncModuleInfo, ChunkItem, ChunkingContext, ChunkingType, ChunkingTypeOption,
11+
EvaluatableAsset,
1212
},
1313
ident::AssetIdent,
1414
module::{Module, ModuleSideEffects},
@@ -20,7 +20,7 @@ use turbopack_core::{
2020
use turbopack_ecmascript::{
2121
chunk::{
2222
EcmascriptChunkItemContent, EcmascriptChunkItemOptions, EcmascriptChunkPlaceable,
23-
EcmascriptExports, ecmascript_chunk_item,
23+
EcmascriptExports,
2424
},
2525
runtime_functions::TURBOPACK_REQUIRE,
2626
utils::StringifyJs,
@@ -41,16 +41,13 @@ async fn hmr_entry_point_base_ident() -> Result<Vc<AssetIdent>> {
4141
#[turbo_tasks::value(shared)]
4242
pub struct HmrEntryModule {
4343
pub ident: ResolvedVc<AssetIdent>,
44-
pub module: ResolvedVc<Box<dyn ChunkableModule>>,
44+
pub module: ResolvedVc<Box<dyn Module>>,
4545
}
4646

4747
#[turbo_tasks::value_impl]
4848
impl HmrEntryModule {
4949
#[turbo_tasks::function]
50-
pub fn new(
51-
ident: ResolvedVc<AssetIdent>,
52-
module: ResolvedVc<Box<dyn ChunkableModule>>,
53-
) -> Vc<Self> {
50+
pub fn new(ident: ResolvedVc<AssetIdent>, module: ResolvedVc<Box<dyn Module>>) -> Vc<Self> {
5451
Self { ident, module }.cell()
5552
}
5653
}
@@ -70,7 +67,7 @@ impl Module for HmrEntryModule {
7067
#[turbo_tasks::function]
7168
async fn references(&self) -> Result<Vc<ModuleReferences>> {
7269
Ok(Vc::cell(vec![ResolvedVc::upcast(
73-
HmrEntryModuleReference::new(Vc::upcast(*self.module))
70+
HmrEntryModuleReference::new(*self.module)
7471
.to_resolved()
7572
.await?,
7673
)]))
@@ -81,18 +78,6 @@ impl Module for HmrEntryModule {
8178
}
8279
}
8380

84-
#[turbo_tasks::value_impl]
85-
impl ChunkableModule for HmrEntryModule {
86-
#[turbo_tasks::function]
87-
fn as_chunk_item(
88-
self: ResolvedVc<Self>,
89-
module_graph: ResolvedVc<ModuleGraph>,
90-
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
91-
) -> Vc<Box<dyn ChunkItem>> {
92-
ecmascript_chunk_item(ResolvedVc::upcast(self), module_graph, chunking_context)
93-
}
94-
}
95-
9681
#[turbo_tasks::value_impl]
9782
impl Asset for HmrEntryModule {
9883
#[turbo_tasks::function]
@@ -118,7 +103,7 @@ impl EcmascriptChunkPlaceable for HmrEntryModule {
118103
) -> Result<Vc<EcmascriptChunkItemContent>> {
119104
let this = self.await?;
120105
let module = this.module;
121-
let chunk_item = module.as_chunk_item(module_graph, chunking_context);
106+
let chunk_item = ChunkItem::new(*module, module_graph, chunking_context);
122107
let id = chunking_context
123108
.chunk_item_id_strategy()
124109
.await?

crates/next-core/src/next_client_reference/ecmascript_client_reference/ecmascript_client_reference_module.rs

Lines changed: 11 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,26 @@
11
use std::{io::Write, iter::once};
22

3-
use anyhow::{Context, Result, bail};
3+
use anyhow::{Result, bail};
44
use indoc::writedoc;
55
use turbo_rcstr::{RcStr, rcstr};
66
use turbo_tasks::{IntoTraitRef, ResolvedVc, ValueToString, Vc};
77
use turbo_tasks_fs::{File, FileContent};
88
use turbopack_core::{
99
asset::AssetContent,
10-
chunk::{
11-
AsyncModuleInfo, ChunkGroupType, ChunkItem, ChunkType, ChunkableModule, ChunkingContext,
12-
ChunkingType, ChunkingTypeOption,
13-
},
10+
chunk::{AsyncModuleInfo, ChunkGroupType, ChunkingContext, ChunkingType, ChunkingTypeOption},
1411
code_builder::CodeBuilder,
1512
context::AssetContext,
1613
ident::AssetIdent,
1714
module::{Module, ModuleSideEffects},
1815
module_graph::{ModuleGraph, binding_usage_info::ModuleExportUsageInfo},
19-
output::OutputAssetsReference,
2016
reference::{ModuleReference, ModuleReferences},
2117
reference_type::ReferenceType,
2218
resolve::ModuleResolveResult,
2319
source::OptionSource,
2420
virtual_source::VirtualSource,
2521
};
2622
use turbopack_ecmascript::{
27-
chunk::{
28-
EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkPlaceable,
29-
EcmascriptChunkType, EcmascriptExports,
30-
},
23+
chunk::{EcmascriptChunkItemContent, EcmascriptChunkPlaceable, EcmascriptExports},
3124
runtime_functions::TURBOPACK_EXPORT_NAMESPACE,
3225
utils::StringifyJs,
3326
};
@@ -249,32 +242,6 @@ impl Module for EcmascriptClientReferenceModule {
249242
}
250243
}
251244

252-
#[turbo_tasks::value_impl]
253-
impl ChunkableModule for EcmascriptClientReferenceModule {
254-
#[turbo_tasks::function]
255-
async fn as_chunk_item(
256-
self: ResolvedVc<Self>,
257-
module_graph: Vc<ModuleGraph>,
258-
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
259-
) -> Result<Vc<Box<dyn ChunkItem>>> {
260-
let item = self
261-
.proxy_module()
262-
.as_chunk_item(module_graph, *chunking_context);
263-
let ecmascript_item =
264-
ResolvedVc::try_downcast::<Box<dyn EcmascriptChunkItem>>(item.to_resolved().await?)
265-
.context("EcmascriptModuleAsset must implement EcmascriptChunkItem")?;
266-
267-
Ok(Vc::upcast(
268-
EcmascriptClientReferenceProxyChunkItem {
269-
inner_module: self,
270-
inner_chunk_item: ecmascript_item,
271-
chunking_context,
272-
}
273-
.cell(),
274-
))
275-
}
276-
}
277-
278245
#[turbo_tasks::value_impl]
279246
impl EcmascriptChunkPlaceable for EcmascriptClientReferenceModule {
280247
#[turbo_tasks::function]
@@ -285,67 +252,17 @@ impl EcmascriptChunkPlaceable for EcmascriptClientReferenceModule {
285252
#[turbo_tasks::function]
286253
fn chunk_item_content(
287254
self: Vc<Self>,
288-
_chunking_context: Vc<Box<dyn ChunkingContext>>,
289-
_module_graph: Vc<ModuleGraph>,
290-
_async_module_info: Option<Vc<AsyncModuleInfo>>,
291-
_estimated: bool,
292-
) -> Result<Vc<EcmascriptChunkItemContent>> {
293-
bail!("Attempted to get chunk_item_content for EcmascriptClientReferenceModule")
294-
}
295-
}
296-
297-
/// This wrapper only exists to overwrite the `asset_ident` method of the
298-
/// wrapped [`Vc<Box<dyn EcmascriptChunkItem>>`]. Otherwise, the asset ident of
299-
/// the chunk item would not be the same as the asset ident of the
300-
/// [`Vc<EcmascriptClientReferenceModule>`].
301-
#[turbo_tasks::value]
302-
struct EcmascriptClientReferenceProxyChunkItem {
303-
inner_module: ResolvedVc<EcmascriptClientReferenceModule>,
304-
inner_chunk_item: ResolvedVc<Box<dyn EcmascriptChunkItem>>,
305-
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
306-
}
307-
308-
#[turbo_tasks::value_impl]
309-
impl OutputAssetsReference for EcmascriptClientReferenceProxyChunkItem {}
310-
311-
#[turbo_tasks::value_impl]
312-
impl ChunkItem for EcmascriptClientReferenceProxyChunkItem {
313-
#[turbo_tasks::function]
314-
fn asset_ident(&self) -> Vc<AssetIdent> {
315-
self.inner_module.ident()
316-
}
317-
318-
#[turbo_tasks::function]
319-
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
320-
*self.chunking_context
321-
}
322-
323-
#[turbo_tasks::function]
324-
fn ty(&self) -> Vc<Box<dyn ChunkType>> {
325-
Vc::upcast(Vc::<EcmascriptChunkType>::default())
326-
}
327-
328-
#[turbo_tasks::function]
329-
fn module(&self) -> Vc<Box<dyn Module>> {
330-
Vc::upcast(*self.inner_module)
331-
}
332-
}
333-
334-
#[turbo_tasks::value_impl]
335-
impl EcmascriptChunkItem for EcmascriptClientReferenceProxyChunkItem {
336-
#[turbo_tasks::function]
337-
fn content(&self) -> Vc<EcmascriptChunkItemContent> {
338-
self.inner_chunk_item.content()
339-
}
340-
341-
#[turbo_tasks::function]
342-
fn content_with_async_module_info(
343-
&self,
255+
chunking_context: Vc<Box<dyn ChunkingContext>>,
256+
module_graph: Vc<ModuleGraph>,
344257
async_module_info: Option<Vc<AsyncModuleInfo>>,
345258
estimated: bool,
346259
) -> Vc<EcmascriptChunkItemContent> {
347-
self.inner_chunk_item
348-
.content_with_async_module_info(async_module_info, estimated)
260+
self.proxy_module().chunk_item_content(
261+
chunking_context,
262+
module_graph,
263+
async_module_info,
264+
estimated,
265+
)
349266
}
350267
}
351268

crates/next-core/src/next_dynamic/dynamic_module.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use indoc::formatdoc;
55
use turbo_rcstr::{RcStr, rcstr};
66
use turbo_tasks::{ResolvedVc, Vc};
77
use turbopack_core::{
8-
chunk::{AsyncModuleInfo, ChunkableModule, ChunkingContext, ModuleChunkItemIdExt},
8+
chunk::{AsyncModuleInfo, ChunkingContext, ModuleChunkItemIdExt},
99
ident::AssetIdent,
1010
module::{Module, ModuleSideEffects},
1111
module_graph::ModuleGraph,
@@ -14,10 +14,7 @@ use turbopack_core::{
1414
source::OptionSource,
1515
};
1616
use turbopack_ecmascript::{
17-
chunk::{
18-
EcmascriptChunkItemContent, EcmascriptChunkPlaceable, EcmascriptExports,
19-
ecmascript_chunk_item,
20-
},
17+
chunk::{EcmascriptChunkItemContent, EcmascriptChunkPlaceable, EcmascriptExports},
2118
references::esm::{EsmExport, EsmExports},
2219
runtime_functions::{TURBOPACK_EXPORT_NAMESPACE, TURBOPACK_IMPORT},
2320
utils::StringifyJs,
@@ -75,18 +72,6 @@ impl Module for NextDynamicEntryModule {
7572
}
7673
}
7774

78-
#[turbo_tasks::value_impl]
79-
impl ChunkableModule for NextDynamicEntryModule {
80-
#[turbo_tasks::function]
81-
fn as_chunk_item(
82-
self: ResolvedVc<Self>,
83-
module_graph: ResolvedVc<ModuleGraph>,
84-
chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
85-
) -> Vc<Box<dyn turbopack_core::chunk::ChunkItem>> {
86-
ecmascript_chunk_item(ResolvedVc::upcast(self), module_graph, chunking_context)
87-
}
88-
}
89-
9075
#[turbo_tasks::value_impl]
9176
impl EcmascriptChunkPlaceable for NextDynamicEntryModule {
9277
#[turbo_tasks::function]

0 commit comments

Comments
 (0)