Skip to content

Commit

Permalink
refactor(turbopack-dev-server): Remove unresolved Vc from DevHtmlEntr…
Browse files Browse the repository at this point in the history
…y, use a named struct
  • Loading branch information
bgw committed Jan 11, 2025
1 parent 3651a45 commit 8249ddd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
24 changes: 15 additions & 9 deletions turbopack/crates/turbopack-cli/src/dev/web_entry_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use turbopack_core::{
},
};
use turbopack_dev_server::{
html::DevHtmlAsset,
html::{DevHtmlAsset, DevHtmlEntry},
source::{asset_graph::AssetGraphContentSource, ContentSource},
};
use turbopack_ecmascript_runtime::RuntimeType;
Expand Down Expand Up @@ -112,7 +112,9 @@ pub async fn create_web_entry_source(
server_root,
*server_root_to_root_path,
compile_time_info.environment(),
);
)
.to_resolved()
.await?;
let entries = get_client_runtime_entries(root_path, node_env);

let runtime_entries = entries.resolve_entries(asset_context);
Expand All @@ -138,21 +140,25 @@ pub async fn create_web_entry_source(
.into_iter()
.flatten()
.map(|module| async move {
if let (Some(chnkable), Some(entry)) = (
if let (Some(chunkable_module), Some(entry)) = (
ResolvedVc::try_sidecast::<Box<dyn ChunkableModule>>(module).await?,
ResolvedVc::try_sidecast::<Box<dyn EvaluatableAsset>>(module).await?,
) {
Ok((
chnkable,
Ok(DevHtmlEntry {
chunkable_module,
chunking_context,
Some(runtime_entries.with_entry(*entry)),
))
} else if let Some(chunkable) =
runtime_entries: Some(runtime_entries.with_entry(*entry).to_resolved().await?),
})
} else if let Some(chunkable_module) =
ResolvedVc::try_sidecast::<Box<dyn ChunkableModule>>(module).await?
{
// TODO this is missing runtime code, so it's probably broken and we should also
// add an ecmascript chunk with the runtime code
Ok((chunkable, chunking_context, None))
Ok(DevHtmlEntry {
chunkable_module,
chunking_context,
runtime_entries: None,
})
} else {
// TODO convert into a serve-able asset
Err(anyhow!(
Expand Down
35 changes: 23 additions & 12 deletions turbopack/crates/turbopack-dev-server/src/html.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use anyhow::Result;
use mime_guess::mime::TEXT_HTML_UTF_8;
use serde::{Deserialize, Serialize};
use turbo_rcstr::RcStr;
use turbo_tasks::{ReadRef, ResolvedVc, TryJoinIterExt, Value, Vc};
use turbo_tasks::{
trace::TraceRawVcs, NonLocalValue, ReadRef, ResolvedVc, TaskInput, TryJoinIterExt, Value, Vc,
};
use turbo_tasks_fs::{File, FileSystemPath};
use turbo_tasks_hash::{encode_hex, Xxh3Hash64Hasher};
use turbopack_core::{
Expand All @@ -16,18 +19,19 @@ use turbopack_core::{
version::{Version, VersionedContent},
};

// TODO(WEB-945) This should become a struct once we have a
// `turbo_tasks::input` attribute macro/`Input` derive macro.
type DevHtmlEntry = (
ResolvedVc<Box<dyn ChunkableModule>>,
Vc<Box<dyn ChunkingContext>>,
Option<Vc<EvaluatableAssets>>,
);
#[derive(
Clone, Debug, Deserialize, Eq, Hash, NonLocalValue, PartialEq, Serialize, TaskInput, TraceRawVcs,
)]
pub struct DevHtmlEntry {
pub chunkable_module: ResolvedVc<Box<dyn ChunkableModule>>,
pub chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
pub runtime_entries: Option<ResolvedVc<EvaluatableAssets>>,
}

/// The HTML entry point of the dev server.
///
/// Generates an HTML page that includes the ES and CSS chunks.
#[turbo_tasks::value(shared, local)]
#[turbo_tasks::value(shared)]
#[derive(Clone)]
pub struct DevHtmlAsset {
path: ResolvedVc<FileSystemPath>,
Expand Down Expand Up @@ -132,19 +136,26 @@ impl DevHtmlAsset {
.entries
.iter()
.map(|entry| async move {
let &(chunkable_module, chunking_context, runtime_entries) = entry;
let &DevHtmlEntry {
chunkable_module,
chunking_context,
runtime_entries,
} = entry;

let assets = if let Some(runtime_entries) = runtime_entries {
let runtime_entries = if let Some(evaluatable) =
ResolvedVc::try_downcast(chunkable_module).await?
{
runtime_entries.with_entry(*evaluatable)
runtime_entries
.with_entry(*evaluatable)
.to_resolved()
.await?
} else {
runtime_entries
};
chunking_context.evaluated_chunk_group_assets(
chunkable_module.ident(),
runtime_entries,
*runtime_entries,
Value::new(AvailabilityInfo::Root),
)
} else {
Expand Down

0 comments on commit 8249ddd

Please sign in to comment.