Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
393 changes: 265 additions & 128 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 13 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,15 @@ hashbrown = "0.14.5"
image = { version = "0.25.8", default-features = false }
indexmap = "2.13.0"
indoc = "2.0.0"
inventory = "0.3.21"
itertools = "0.10.5"
lightningcss = { version = "1.0.0-alpha.70", features = [
lightningcss = { version = "1.0.0-alpha.72", features = [
"serde",
"visitor",
"into_owned",
"browserslist",
] }
lightningcss-napi = { version = "0.4.6", default-features = false, features = [
lightningcss-napi = { version = "0.4.8", default-features = false, features = [
"visitor",
] }
lzzzz = "2.0.0"
Expand All @@ -309,8 +310,9 @@ napi-derive = "2"
napi-build = "2"
nohash-hasher = "0.2.0"
notify = "8.1.0"
notify-types = "2.0.0"
owo-colors = "4.2.2"
parcel_selectors = "0.28.2"
parcel_selectors = "0.28.3"
parking_lot = "0.12.1"
pathdiff = "0.2.1"
phf = { version = "0.11", features = ["macros"] }
Expand All @@ -322,6 +324,7 @@ qstring = "0.7.2"
quick_cache = { version = "0.6.14" }
quote = "1.0.45"
rand = "0.10.1"
getrandom = "0.3"
rayon = "1.10.0"
regex = "1.12.3"
regress = "0.10.4"
Expand Down Expand Up @@ -353,7 +356,7 @@ tempfile = "3.20.0"
terminal_size = "0.3.0"
thiserror = "1.0.48"
thread_local = "1.1.8"
tokio = "1.52.1"
tokio = "=1.51.0"
tokio-util = { version = "0.7.18", features = ["io", "rt"] }
tracing = "0.1.44"
tracing-subscriber = "0.3.16"
Expand All @@ -375,3 +378,9 @@ virtue = { git = "https://github.com/bgw/virtue.git", branch = "bgw/fix-generic-
mdxjs = { git = "https://github.com/vercel-labs/mdxjs-rs-turbopack.git", branch = "turbopack" }
# Doesn't compile on recent nightly versions because of https://github.com/Michael-F-Bryan/include_dir/pull/117
include_dir = { git = "https://github.com/vercel-labs/include_dir", branch = "turbopack" }
libmimalloc-sys = { git = "https://github.com/utooland/mimalloc_rust.git" }
lightningcss = { git = "https://github.com/utooland/lightningcss", branch = "support-css-module-global" }
mimalloc = { git = "https://github.com/utooland/mimalloc_rust.git" }
parcel_selectors = { git = "https://github.com/utooland/lightningcss", branch = "support-css-module-global" }
tokio = { git = "https://github.com/utooland/tokio.git", package = "tokio" }
tokio-util = { git = "https://github.com/utooland/tokio.git", package = "tokio-util" }
8 changes: 6 additions & 2 deletions crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use turbopack_core::{
asset::AssetContent,
chunk::{
ChunkGroupResult, ChunkingContext, ChunkingContextExt, EvaluatableAsset, EvaluatableAssets,
availability_info::AvailabilityInfo,
HmrChunkListSource, availability_info::AvailabilityInfo,
},
file_source::FileSource,
ident::{AssetIdent, Layer},
Expand Down Expand Up @@ -1427,7 +1427,11 @@ impl AppEndpoint {
let client_reference_chunks =
get_client_references_chunks_for_hmr(*client_references_chunks);
client_chunking_context
.hmr_chunk_list(client_components_chunks_ident, client_reference_chunks)
.hmr_chunk_list(
client_components_chunks_ident,
client_reference_chunks,
HmrChunkListSource::Entry,
)
.await?
.iter()
.copied()
Expand Down
8 changes: 5 additions & 3 deletions crates/next-core/src/next_client/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use turbopack_browser::{
};
use turbopack_core::{
chunk::{
AssetSuffix, ChunkLoadRetry, ChunkingConfig, ChunkingContext, ContentHashing, CrossOrigin,
MangleType, MinifyType, SourceMapSourceType, SourceMapsType, UnusedReferences, UrlBehavior,
chunk_id_strategy::ModuleIdStrategy,
AssetSuffix, ChunkLoadRetry, ChunkingConfig, ChunkingContext, CompressType, ContentHashing,
CrossOrigin, MangleType, MinifyType, SourceMapSourceType, SourceMapsType, UnusedReferences,
UrlBehavior, chunk_id_strategy::ModuleIdStrategy,
},
compile_time_info::{CompileTimeDefines, CompileTimeInfo, FreeVarReference, FreeVarReferences},
environment::{BrowserEnvironment, Environment, ExecutionEnvironment},
Expand Down Expand Up @@ -578,6 +578,7 @@ pub async fn get_client_chunking_context(
.minify_type(if *minify.await? {
MinifyType::Minify {
mangle: (!*no_mangling.await?).then_some(MangleType::OptimalSize),
compress: Some(CompressType::Default),
}
} else {
MinifyType::NoMinify
Expand Down Expand Up @@ -690,6 +691,7 @@ pub async fn get_service_worker_chunking_context(
.minify_type(if *minify.await? {
MinifyType::Minify {
mangle: (!*no_mangling.await?).then_some(MangleType::OptimalSize),
compress: Some(CompressType::Default),
}
} else {
MinifyType::NoMinify
Expand Down
6 changes: 4 additions & 2 deletions crates/next-core/src/next_edge/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use turbo_tasks_fs::FileSystemPath;
use turbopack_browser::BrowserChunkingContext;
use turbopack_core::{
chunk::{
AssetSuffix, ChunkingConfig, ChunkingContext, CrossOrigin, MangleType, MinifyType,
SourceMapSourceType, SourceMapsType, UnusedReferences, UrlBehavior,
AssetSuffix, ChunkingConfig, ChunkingContext, CompressType, CrossOrigin, MangleType,
MinifyType, SourceMapSourceType, SourceMapsType, UnusedReferences, UrlBehavior,
chunk_id_strategy::ModuleIdStrategy,
},
compile_time_info::{CompileTimeDefines, CompileTimeInfo, FreeVarReference, FreeVarReferences},
Expand Down Expand Up @@ -262,6 +262,7 @@ pub async fn get_edge_chunking_context_with_client_assets(
MinifyType::Minify {
// React needs deterministic function names to work correctly.
mangle: (!*no_mangling.await?).then_some(MangleType::Deterministic),
compress: Some(CompressType::Default),
}
} else {
MinifyType::NoMinify
Expand Down Expand Up @@ -375,6 +376,7 @@ pub async fn get_edge_chunking_context(
.minify_type(if *turbo_minify.await? {
MinifyType::Minify {
mangle: (!*no_mangling.await?).then_some(MangleType::OptimalSize),
compress: Some(CompressType::Default),
}
} else {
MinifyType::NoMinify
Expand Down
6 changes: 4 additions & 2 deletions crates/next-core/src/next_server/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use turbopack::{
};
use turbopack_core::{
chunk::{
AssetSuffix, ChunkingConfig, MangleType, MinifyType, SourceMapSourceType, SourceMapsType,
UnusedReferences, UrlBehavior, chunk_id_strategy::ModuleIdStrategy,
AssetSuffix, ChunkingConfig, CompressType, MangleType, MinifyType, SourceMapSourceType,
SourceMapsType, UnusedReferences, UrlBehavior, chunk_id_strategy::ModuleIdStrategy,
},
compile_time_defines,
compile_time_info::{CompileTimeDefines, CompileTimeInfo, FreeVarReferences},
Expand Down Expand Up @@ -1116,6 +1116,7 @@ pub async fn get_server_chunking_context_with_client_assets(
MinifyType::Minify {
// React needs deterministic function names to work correctly.
mangle: (!*no_mangling.await?).then_some(MangleType::Deterministic),
compress: Some(CompressType::Default),
}
} else {
MinifyType::NoMinify
Expand Down Expand Up @@ -1223,6 +1224,7 @@ pub async fn get_server_chunking_context(
.minify_type(if *minify.await? {
MinifyType::Minify {
mangle: (!*no_mangling.await?).then_some(MangleType::OptimalSize),
compress: Some(CompressType::Default),
}
} else {
MinifyType::NoMinify
Expand Down
3 changes: 2 additions & 1 deletion packages/next/src/client/dev/hot-reloader/app/web-socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export function createProcessTurbopackMessage(
import(
// @ts-expect-error requires "moduleResolution": "node16" in tsconfig.json and not .ts extension
'@vercel/turbopack-ecmascript-runtime/browser/dev/hmr-client/hmr-client.ts'
).then(({ connect }) => {
).then(({ connect, TURBOPACK_CHUNK_UPDATE_LISTENERS_GLOBAL }) => {
connect({
addMessageListener(cb: (msg: TurbopackMessageSentToBrowser) => void) {
callback = cb
Expand All @@ -201,6 +201,7 @@ export function createProcessTurbopackMessage(
},
sendMessage,
onUpdateError: (err: unknown) => performFullReload(err, sendMessage),
chunkUpdateListenersGlobal: TURBOPACK_CHUNK_UPDATE_LISTENERS_GLOBAL,
})
})

Expand Down
4 changes: 3 additions & 1 deletion packages/next/src/client/next-dev-turbopack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { initialize, version, router, emitter } from './'
import initHMR from './dev/hot-middleware-client'

import { pageBootstrap } from './page-bootstrap'
// prettier-ignore
//@ts-expect-error requires "moduleResolution": "node16" in tsconfig.json and not .ts extension
import { connect } from '@vercel/turbopack-ecmascript-runtime/browser/dev/hmr-client/hmr-client.ts'
import { connect, TURBOPACK_CHUNK_UPDATE_LISTENERS_GLOBAL } from '@vercel/turbopack-ecmascript-runtime/browser/dev/hmr-client/hmr-client.ts'
import type { TurbopackMessageSentToBrowser } from '../server/dev/hot-reloader-types'

window.next = {
Expand Down Expand Up @@ -48,6 +49,7 @@ initialize({
},
sendMessage: devClient.sendTurbopackMessage,
onUpdateError: devClient.handleUpdateError,
chunkUpdateListenersGlobal: TURBOPACK_CHUNK_UPDATE_LISTENERS_GLOBAL,
})

return pageBootstrap(assetPrefix)
Expand Down
11 changes: 10 additions & 1 deletion test/production/escheck-output/app/foo/page.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
'use client'

async function fetchMore() {
const res = await Promise.resolve('more data')
return res
}

export default function Page() {
return <button>Client</button>
return (
<div>
<button onClick={() => fetchMore().then(console.log)}>Client</button>
</div>
)
}
7 changes: 7 additions & 0 deletions test/production/escheck-output/app/tla-page/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Server component page that uses top-level await (TLA).
// Tests that TLA is properly transpiled for older browser targets.
import { data } from '../tla'

export default function TlaPage() {
return <div>{data.message}</div>
}
3 changes: 3 additions & 0 deletions test/production/escheck-output/app/tla.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This module uses top-level await (TLA) to test that Turbopack/SWC
// properly transpiles async/await for older browser targets.
export const data = await Promise.resolve({ message: 'loaded' })
35 changes: 35 additions & 0 deletions test/production/escheck-output/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,39 @@ describe('escheck-output', () => {
expect(esCheckOutput).toContain('info: ✓ ES-Check passed!')
})
})

// Chrome 50 does not support async/await (added in Chrome 55).
// This validates that TLA and async functions in app/tla.js and app/foo/page.js
// are properly transpiled by SWC preset-env.
// Webpack doesn't properly downlevel
;(process.env.IS_TURBOPACK_TEST ? describe : describe.skip)(
'pre-async browsers',
() => {
let browserslist = ['chrome 50']

const { next } = nextTestSetup({
files: __dirname,
dependencies,
packageJson: {
browserslist,
},
})

it('should downlevel async/await', () => {
let esCheckOutput = execSync(
`node_modules/.bin/es-check checkBrowser ".next/static/**/*.js" --browserslistQuery="${browserslist.join(', ')}" --noCache`,
{ cwd: next.testDir, encoding: 'utf8' }
)

expect(esCheckOutput).toContain('info: ✓ ES-Check passed!')
})

it('should render TLA page correctly', async () => {
const res = await next.fetch('/tla-page')
expect(res.status).toBe(200)
const html = await res.text()
expect(html).toContain('loaded')
})
}
)
})
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,6 @@ impl<E: Entry> StreamingSstWriter<E> {
qfilter::Filter::new(actual_count.max(1), AMQF_FALSE_POSITIVE_RATE)
.expect("Filter can't be constructed"),
);

let fp_size = builder.fingerprint_size();
assert!(fp_size < 32, "fp_size {fp_size} exceeds u32");
let fp_mask = (1u32 << fp_size) - 1;
Expand Down
24 changes: 14 additions & 10 deletions turbopack/crates/turbo-rcstr-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,26 @@ pub fn rcstr(input: TokenStream) -> TokenStream {
format!("::turbo_rcstr::inline_atom({lit}).unwrap()")
} else {
format!(
"{{ static RCSTR_STORAGE: ::turbo_rcstr::StaticPrehashedString = \
::turbo_rcstr::make_const_prehashed_string({lit}); const RCSTR: \
::turbo_rcstr::RcStr = ::turbo_rcstr::from_static(&RCSTR_STORAGE); \
::turbo_rcstr::__rcstr_static_submit!(
::turbo_rcstr::StaticRcStr(&RCSTR_STORAGE) ); RCSTR }}",
"{{ #[cfg(target_arch = \"wasm32\")] {{ ::turbo_rcstr::RcStr::from({lit}) }} \
#[cfg(not(target_arch = \"wasm32\"))] {{ static RCSTR_STORAGE: \
::turbo_rcstr::StaticPrehashedString = \
::turbo_rcstr::make_const_prehashed_string({lit}); \
::turbo_rcstr::__rcstr_static_submit!( \
::turbo_rcstr::StaticRcStr(&RCSTR_STORAGE) ); \
::turbo_rcstr::from_static(&RCSTR_STORAGE) }} }}",
)
}
} else {
format!(
"{{ const TEXT: &str = {input}; if ::turbo_rcstr::is_atom_inlineable(TEXT) {{ \
"{{ const TEXT: &str = {input}; #[cfg(target_arch = \"wasm32\")] {{ \
::turbo_rcstr::inline_atom(TEXT).unwrap() }} #[cfg(not(target_arch = \
\"wasm32\"))] {{ if ::turbo_rcstr::is_atom_inlineable(TEXT) {{ \
::turbo_rcstr::inline_atom(TEXT).unwrap() }} else {{ static RCSTR_STORAGE: \
::turbo_rcstr::StaticPrehashedString = \
::turbo_rcstr::make_const_prehashed_string(TEXT); const RCSTR: \
::turbo_rcstr::RcStr = ::turbo_rcstr::from_static(&RCSTR_STORAGE); \
::turbo_rcstr::__rcstr_static_submit!(
::turbo_rcstr::StaticRcStr(&RCSTR_STORAGE) ); RCSTR }} }}",
::turbo_rcstr::make_const_prehashed_string(TEXT); \
::turbo_rcstr::__rcstr_static_submit!( \
::turbo_rcstr::StaticRcStr(&RCSTR_STORAGE) ); \
::turbo_rcstr::from_static(&RCSTR_STORAGE) }} }} }}",
)
};
TokenStream::from_str(&source).expect("emitted source parses")
Expand Down
4 changes: 3 additions & 1 deletion turbopack/crates/turbo-tasks-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ smallvec = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
turbo-bincode = { workspace = true }
turbo-persistence = { workspace = true }
turbo-rcstr = { workspace = true }
turbo-tasks = { workspace = true }
turbo-tasks-hash = { workspace = true }
turbo-tasks-malloc = { workspace = true, default-features = false }
thread_local = { workspace = true }

[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dependencies]
turbo-persistence = { workspace = true }

[dev-dependencies]
async-trait = { workspace = true }
criterion = { workspace = true, features = ["async_tokio"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
num::NonZeroU32,
ops::{ControlFlow, Deref},
thread::yield_now,
time::{Duration, Instant},
time::Duration,
};

use anyhow::Result;
Expand All @@ -15,6 +15,7 @@ use indexmap::map::Entry;
use ringmap::RingSet;
use rustc_hash::{FxBuildHasher, FxHashMap};
use smallvec::{SmallVec, smallvec};
use tokio::time::Instant;
#[cfg(feature = "trace_aggregation_update_queue")]
use tracing::span::Span;
#[cfg(any(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ impl<'e> ExecuteContextImpl<'e> {

// Fast path: no backing storage to restore from — all tasks should already
// have restored flags set at allocation time, so just invoke callbacks directly.
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
if !self.backend.should_restore() {
for (task_id, category) in task_ids {
self.task_lock_counter.acquire();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
use turbo_persistence::{FamilyConfig, FamilyKind};

#[derive(Debug, Clone, Copy)]
Expand All @@ -7,6 +8,8 @@ pub enum KeySpace {
TaskData = 2,
TaskCache = 3,
}

#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
impl KeySpace {
/// Constructs a [`KeySpace`] from its numeric index (i.e., the `usize` discriminant).
///
Expand Down
1 change: 1 addition & 0 deletions turbopack/crates/turbo-tasks-backend/src/database/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod db_invalidation;
pub mod db_versioning;
pub mod key_value_database;
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
pub mod turbo;
pub mod write_batch;
Loading
Loading