Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turbopack: EcmascriptChunkItemContent: add react refresh parameter based on module #8133

Merged
merged 7 commits into from
May 15, 2024
10 changes: 1 addition & 9 deletions crates/turbopack-browser/src/chunking_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use turbopack_core::{
};
use turbopack_ecmascript::{
async_chunk::module::AsyncLoaderModule,
chunk::{EcmascriptChunk, EcmascriptChunkingContext},
chunk::EcmascriptChunk,
manifest::{chunk_asset::ManifestAsyncModule, loader_item::ManifestLoaderChunkItem},
};
use turbopack_ecmascript_runtime::RuntimeType;
Expand Down Expand Up @@ -493,11 +493,3 @@ impl ChunkingContext for BrowserChunkingContext {
})
}
}

#[turbo_tasks::value_impl]
impl EcmascriptChunkingContext for BrowserChunkingContext {
#[turbo_tasks::function]
fn has_react_refresh(&self) -> Vc<bool> {
Vc::cell(true)
}
}
6 changes: 3 additions & 3 deletions crates/turbopack-browser/src/ecmascript/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use turbopack_core::{
};
use turbopack_ecmascript::chunk::{
EcmascriptChunk, EcmascriptChunkPlaceables, EcmascriptChunkRuntime,
EcmascriptChunkRuntimeContent, EcmascriptChunkingContext,
EcmascriptChunkRuntimeContent, ChunkingContext,
};

use crate::ecmascript::content::EcmascriptDevChunkContent;
Expand All @@ -16,7 +16,7 @@ use crate::ecmascript::content::EcmascriptDevChunkContent;
#[turbo_tasks::value(shared)]
pub(crate) struct EcmascriptDevChunkRuntime {
/// The chunking context that created this runtime.
chunking_context: Vc<Box<dyn EcmascriptChunkingContext>>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
/// All chunks of this chunk group need to be ready for execution to start.
/// When None, it will use a chunk group created from the current chunk.
chunk_group: Option<Vc<ChunkGroup>>,
Expand All @@ -31,7 +31,7 @@ impl EcmascriptDevChunkRuntime {
/// Creates a new [`Vc<EcmascriptDevChunkRuntime>`].
#[turbo_tasks::function]
pub fn new(
chunking_context: Vc<Box<dyn EcmascriptChunkingContext>>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
evaluated_entries: Option<Vc<EcmascriptChunkPlaceables>>,
) -> Vc<Self> {
EcmascriptDevChunkRuntime {
Expand Down
12 changes: 3 additions & 9 deletions crates/turbopack-css/src/module_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use turbopack_core::{
use turbopack_ecmascript::{
chunk::{
EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkPlaceable,
EcmascriptChunkType, EcmascriptChunkingContext, EcmascriptExports,
EcmascriptChunkType, EcmascriptExports,
},
utils::StringifyJs,
ParseResultSourceMap,
Expand Down Expand Up @@ -237,12 +237,6 @@ impl ChunkableModule for ModuleCssAsset {
self: Vc<Self>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Result<Vc<Box<dyn turbopack_core::chunk::ChunkItem>>> {
let chunking_context =
Vc::try_resolve_downcast::<Box<dyn EcmascriptChunkingContext>>(chunking_context)
.await?
.context(
"chunking context must impl EcmascriptChunkingContext to use ModuleCssAsset",
)?;
Ok(Vc::upcast(
ModuleChunkItem {
chunking_context,
Expand Down Expand Up @@ -277,7 +271,7 @@ impl ResolveOrigin for ModuleCssAsset {
#[turbo_tasks::value]
struct ModuleChunkItem {
module: Vc<ModuleCssAsset>,
chunking_context: Vc<Box<dyn EcmascriptChunkingContext>>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
}

#[turbo_tasks::value_impl]
Expand Down Expand Up @@ -313,7 +307,7 @@ impl ChunkItem for ModuleChunkItem {
#[turbo_tasks::value_impl]
impl EcmascriptChunkItem for ModuleChunkItem {
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn EcmascriptChunkingContext>> {
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
self.chunking_context
}

Expand Down
6 changes: 3 additions & 3 deletions crates/turbopack-ecmascript/src/async_chunk/chunk_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ use crate::{
async_chunk::module::AsyncLoaderModule,
chunk::{
data::EcmascriptChunkData, EcmascriptChunkItem, EcmascriptChunkItemContent,
EcmascriptChunkPlaceable, EcmascriptChunkType, EcmascriptChunkingContext,
EcmascriptChunkPlaceable, EcmascriptChunkType,
},
utils::StringifyJs,
};

#[turbo_tasks::value(shared)]
pub struct AsyncLoaderChunkItem {
pub module: Vc<AsyncLoaderModule>,
pub chunking_context: Vc<Box<dyn EcmascriptChunkingContext>>,
pub chunking_context: Vc<Box<dyn ChunkingContext>>,
}

#[turbo_tasks::value_impl]
Expand Down Expand Up @@ -67,7 +67,7 @@ impl AsyncLoaderChunkItem {
#[turbo_tasks::value_impl]
impl EcmascriptChunkItem for AsyncLoaderChunkItem {
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn EcmascriptChunkingContext>> {
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
self.chunking_context
}

Expand Down
14 changes: 4 additions & 10 deletions crates/turbopack-ecmascript/src/async_chunk/module.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{Context, Result};
use anyhow::Result;
use turbo_tasks::{Value, Vc};
use turbopack_core::{
asset::{Asset, AssetContent},
Expand All @@ -8,7 +8,7 @@ use turbopack_core::{
reference::{ModuleReferences, SingleModuleReference},
};

use crate::{async_chunk::chunk_item::AsyncLoaderChunkItem, EcmascriptChunkingContext};
use crate::async_chunk::chunk_item::AsyncLoaderChunkItem;

#[turbo_tasks::function]
fn modifier() -> Vc<String> {
Expand All @@ -20,7 +20,7 @@ fn modifier() -> Vc<String> {
#[turbo_tasks::value]
pub struct AsyncLoaderModule {
pub inner: Vc<Box<dyn ChunkableModule>>,
pub chunking_context: Vc<Box<dyn EcmascriptChunkingContext>>,
pub chunking_context: Vc<Box<dyn ChunkingContext>>,
pub availability_info: AvailabilityInfo,
}

Expand All @@ -29,7 +29,7 @@ impl AsyncLoaderModule {
#[turbo_tasks::function]
pub fn new(
module: Vc<Box<dyn ChunkableModule>>,
chunking_context: Vc<Box<dyn EcmascriptChunkingContext>>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
availability_info: Value<AvailabilityInfo>,
) -> Vc<Self> {
Self::cell(AsyncLoaderModule {
Expand Down Expand Up @@ -81,12 +81,6 @@ impl ChunkableModule for AsyncLoaderModule {
self: Vc<Self>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Result<Vc<Box<dyn turbopack_core::chunk::ChunkItem>>> {
let chunking_context =
Vc::try_resolve_downcast::<Box<dyn EcmascriptChunkingContext>>(chunking_context)
.await?
.context(
"chunking context must impl EcmascriptChunkingContext to use AsyncLoaderModule",
)?;
Ok(Vc::upcast(
AsyncLoaderChunkItem {
chunking_context,
Expand Down
7 changes: 2 additions & 5 deletions crates/turbopack-ecmascript/src/chunk/chunk_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use turbopack_core::{
output::OutputAssets,
};

use super::{
EcmascriptChunk, EcmascriptChunkContent, EcmascriptChunkItem, EcmascriptChunkingContext,
};
use super::{EcmascriptChunk, EcmascriptChunkContent, EcmascriptChunkItem};

#[derive(Default)]
#[turbo_tasks::value]
Expand All @@ -33,8 +31,7 @@ impl ChunkType for EcmascriptChunkType {
referenced_output_assets: Vc<OutputAssets>,
) -> Result<Vc<Box<dyn Chunk>>> {
let Some(chunking_context) =
Vc::try_resolve_downcast::<Box<dyn EcmascriptChunkingContext>>(chunking_context)
.await?
Vc::try_resolve_downcast::<Box<dyn ChunkingContext>>(chunking_context).await?
else {
bail!("Ecmascript chunking context not found");
};
Expand Down
13 changes: 0 additions & 13 deletions crates/turbopack-ecmascript/src/chunk/context.rs

This file was deleted.

10 changes: 5 additions & 5 deletions crates/turbopack-ecmascript/src/chunk/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ use turbopack_core::{
source_map::GenerateSourceMap,
};

use super::EcmascriptChunkingContext;
use crate::{
references::async_module::{AsyncModuleOptions, OptionAsyncModuleOptions},
utils::FormatIter,
EcmascriptModuleContent,
EcmascriptModuleContent, EcmascriptOptions,
};

#[turbo_tasks::value(shared)]
Expand All @@ -33,10 +32,11 @@ impl EcmascriptChunkItemContent {
#[turbo_tasks::function]
pub async fn new(
content: Vc<EcmascriptModuleContent>,
chunking_context: Vc<Box<dyn EcmascriptChunkingContext>>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
options: Vc<EcmascriptOptions>,
async_module_options: Vc<OptionAsyncModuleOptions>,
) -> Result<Vc<Self>> {
let refresh = *chunking_context.has_react_refresh().await?;
let refresh = options.await?.refresh;
let externals = *chunking_context
.environment()
.supports_commonjs_externals()
Expand Down Expand Up @@ -197,7 +197,7 @@ pub trait EcmascriptChunkItem: ChunkItem {
) -> Vc<EcmascriptChunkItemContent> {
self.content()
}
fn chunking_context(self: Vc<Self>) -> Vc<Box<dyn EcmascriptChunkingContext>>;
fn chunking_context(self: Vc<Self>) -> Vc<Box<dyn ChunkingContext>>;

/// Specifies which availablility information the chunk item needs for code
/// generation
Expand Down
6 changes: 2 additions & 4 deletions crates/turbopack-ecmascript/src/chunk/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub(crate) mod chunk_type;
pub(crate) mod content;
pub(crate) mod context;
pub(crate) mod data;
pub(crate) mod item;
pub(crate) mod placeable;
Expand All @@ -26,7 +25,6 @@ use turbopack_core::{
pub use self::{
chunk_type::EcmascriptChunkType,
content::EcmascriptChunkContent,
context::EcmascriptChunkingContext,
data::EcmascriptChunkData,
item::{
EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkItemExt,
Expand All @@ -37,7 +35,7 @@ pub use self::{

#[turbo_tasks::value]
pub struct EcmascriptChunk {
pub chunking_context: Vc<Box<dyn EcmascriptChunkingContext>>,
pub chunking_context: Vc<Box<dyn ChunkingContext>>,
pub content: Vc<EcmascriptChunkContent>,
}

Expand All @@ -48,7 +46,7 @@ pub struct EcmascriptChunks(Vec<Vc<EcmascriptChunk>>);
impl EcmascriptChunk {
#[turbo_tasks::function]
pub async fn new(
chunking_context: Vc<Box<dyn EcmascriptChunkingContext>>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
content: Vc<EcmascriptChunkContent>,
) -> Result<Vc<Self>> {
Ok(EcmascriptChunk {
Expand Down
15 changes: 4 additions & 11 deletions crates/turbopack-ecmascript/src/chunk_group_files_asset.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{Context, Result};
use anyhow::Result;
use indexmap::IndexSet;
use turbo_tasks::{TryJoinIterExt, Value, ValueToString, Vc};
use turbo_tasks_fs::{File, FileSystemPath};
Expand All @@ -23,7 +23,7 @@ use turbopack_core::{
use crate::{
chunk::{
EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkPlaceable,
EcmascriptChunkType, EcmascriptChunkingContext, EcmascriptExports,
EcmascriptChunkType, EcmascriptExports,
},
utils::StringifyJs,
EcmascriptModuleAsset,
Expand Down Expand Up @@ -96,13 +96,6 @@ impl ChunkableModule for ChunkGroupFilesAsset {
chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Result<Vc<Box<dyn turbopack_core::chunk::ChunkItem>>> {
let this = self.await?;
let chunking_context =
Vc::try_resolve_downcast::<Box<dyn EcmascriptChunkingContext>>(chunking_context)
.await?
.context(
"chunking context must impl EcmascriptChunkingContext to use \
ChunkGroupFilesAsset",
)?;
Ok(Vc::upcast(
ChunkGroupFilesChunkItem {
chunking_context,
Expand All @@ -124,7 +117,7 @@ impl EcmascriptChunkPlaceable for ChunkGroupFilesAsset {

#[turbo_tasks::value]
struct ChunkGroupFilesChunkItem {
chunking_context: Vc<Box<dyn EcmascriptChunkingContext>>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
client_root: Vc<FileSystemPath>,
inner: Vc<ChunkGroupFilesAsset>,
}
Expand Down Expand Up @@ -158,7 +151,7 @@ impl ChunkGroupFilesChunkItem {
#[turbo_tasks::value_impl]
impl EcmascriptChunkItem for ChunkGroupFilesChunkItem {
#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn EcmascriptChunkingContext>> {
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
self.chunking_context
}

Expand Down
8 changes: 3 additions & 5 deletions crates/turbopack-ecmascript/src/code_gen.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use serde::{Deserialize, Serialize};
use swc_core::ecma::visit::{AstParentKind, VisitMut};
use turbo_tasks::{debug::ValueDebugFormat, trace::TraceRawVcs, Vc};
use turbopack_core::chunk::AsyncModuleInfo;

use crate::chunk::EcmascriptChunkingContext;
use turbopack_core::chunk::{AsyncModuleInfo, ChunkingContext};

/// impl of code generation inferred from a ModuleReference.
/// This is rust only and can't be implemented by non-rust plugins.
Expand All @@ -28,15 +26,15 @@ pub trait VisitorFactory: Send + Sync {
pub trait CodeGenerateable {
fn code_generation(
self: Vc<Self>,
chunking_context: Vc<Box<dyn EcmascriptChunkingContext>>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Vc<CodeGeneration>;
}

#[turbo_tasks::value_trait]
pub trait CodeGenerateableWithAsyncModuleInfo {
fn code_generation(
self: Vc<Self>,
chunking_context: Vc<Box<dyn EcmascriptChunkingContext>>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
async_module_info: Option<Vc<AsyncModuleInfo>>,
) -> Vc<CodeGeneration>;
}
Expand Down
Loading
Loading