Unverified Commit 93d71d3e authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: fix duplicate module from internal ref (#78194)

A module that was referenced using a `ReferenceType::Internal` and some other non-internal reference type would lead to a duplicated module, because the internal reference always got its own module.


There are various places where we could do the check I added, but this is one of the sources:

https://github.com/vercel/next.js/blob/4509bf240a3327be168ae0035bd578752676b3ec/turbopack/crates/turbopack/src/lib.rs#L501-L504

The bug occured because of these two factors:

- `Option<Vc<Vec<...>>` is just bad at uniquely modelling state (because `None` and `Some(vec![])` really are the same thing but not according to turbo-tasks).

- And then having different two `new` constructors that aren't completely disjoint (with the None vs empty vector case above).
parent 81b96dd4
...@@ -503,7 +503,7 @@ impl EcmascriptModuleAsset { ...@@ -503,7 +503,7 @@ impl EcmascriptModuleAsset {
} }
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn new_with_inner_assets( pub async fn new_with_inner_assets(
source: ResolvedVc<Box<dyn Source>>, source: ResolvedVc<Box<dyn Source>>,
asset_context: ResolvedVc<Box<dyn AssetContext>>, asset_context: ResolvedVc<Box<dyn AssetContext>>,
ty: Value<EcmascriptModuleAssetType>, ty: Value<EcmascriptModuleAssetType>,
...@@ -511,8 +511,18 @@ impl EcmascriptModuleAsset { ...@@ -511,8 +511,18 @@ impl EcmascriptModuleAsset {
options: ResolvedVc<EcmascriptOptions>, options: ResolvedVc<EcmascriptOptions>,
compile_time_info: ResolvedVc<CompileTimeInfo>, compile_time_info: ResolvedVc<CompileTimeInfo>,
inner_assets: ResolvedVc<InnerAssets>, inner_assets: ResolvedVc<InnerAssets>,
) -> Vc<Self> { ) -> Result<Vc<Self>> {
Self::cell(EcmascriptModuleAsset { if inner_assets.await?.is_empty() {
Ok(Self::new(
*source,
*asset_context,
ty,
*transforms,
*options,
*compile_time_info,
))
} else {
Ok(Self::cell(EcmascriptModuleAsset {
source, source,
asset_context, asset_context,
ty: ty.into_value(), ty: ty.into_value(),
...@@ -521,7 +531,8 @@ impl EcmascriptModuleAsset { ...@@ -521,7 +531,8 @@ impl EcmascriptModuleAsset {
compile_time_info, compile_time_info,
inner_assets: Some(inner_assets), inner_assets: Some(inner_assets),
last_successful_parse: Default::default(), last_successful_parse: Default::default(),
}) }))
}
} }
#[turbo_tasks::function] #[turbo_tasks::function]
......
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