Skip to content

Commit

Permalink
backport turbopack changes (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
ForsakenHarmony committed Aug 16, 2024
1 parent 855bd70 commit ee62103
Show file tree
Hide file tree
Showing 44 changed files with 641 additions and 523 deletions.
14 changes: 8 additions & 6 deletions crates/next-api/src/dynamic_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ pub(crate) async fn collect_evaluated_chunk_group(
/// If an import is specified as dynamic, next.js does few things:
/// - Runs a next_dynamic [transform to the source file](https://github.com/vercel/next.js/blob/ae1b89984d26b2af3658001fa19a19e1e77c312d/packages/next-swc/crates/next-transform-dynamic/src/lib.rs#L22)
/// - This transform will [inject `loadableGenerated` property](https://github.com/vercel/next.js/blob/ae1b89984d26b2af3658001fa19a19e1e77c312d/packages/next-swc/crates/next-transform-dynamic/tests/fixture/wrapped-import/output-webpack-dev.js#L5),
/// which contains the list of the import ids in the form of `${origin} -> ${imported}`.
/// - Emits `react-loadable-manifest.json` which contains the mapping of the import ids to the chunk
/// ids.
/// which contains the list of the import ids in the form of `${origin} ->
/// ${imported}`.
/// - Emits `react-loadable-manifest.json` which contains the mapping of the
/// import ids to the chunk ids.
/// - Webpack: [implementation](https://github.com/vercel/next.js/blob/ae1b89984d26b2af3658001fa19a19e1e77c312d/packages/next/src/build/webpack/plugins/react-loadable-plugin.ts)
/// - Turbopack: [implementation 1](https://github.com/vercel/next.js/pull/56389/files#diff-3cac9d9bfe73e0619e6407f21f6fe652da0719d0ec9074ff813ad3e416d0eb1a),
/// [implementation 2](https://github.com/vercel/next.js/pull/56389/files#diff-791951bbe1fa09bcbad9be9173412d0848168f7d658758f11b6e8888a021552c),
Expand All @@ -123,16 +124,17 @@ pub(crate) async fn collect_evaluated_chunk_group(
/// - Server embeds those into __NEXT_DATA__ and [send to the client.](https://github.com/vercel/next.js/blob/ad42b610c25b72561ad367b82b1c7383fd2a5dd2/packages/next/src/server/render.tsx#L1453)
/// - When client boots up, pass it to the [client preload](https://github.com/vercel/next.js/blob/ad42b610c25b72561ad367b82b1c7383fd2a5dd2/packages/next/src/client/index.tsx#L943)
/// - Loadable runtime [injects preload fn](https://github.com/vercel/next.js/blob/ad42b610c25b72561ad367b82b1c7383fd2a5dd2/packages/next/src/shared/lib/loadable.shared-runtime.tsx#L281)
/// to wait until all the dynamic components are being loaded, this ensures hydration mismatch
/// won't occur
/// to wait until all the dynamic components are being loaded, this ensures
/// hydration mismatch won't occur
#[tracing::instrument(level = Level::INFO, name = "collecting next/dynamic imports", skip_all)]
pub(crate) async fn collect_next_dynamic_imports(
server_entries: impl IntoIterator<Item = Vc<Box<dyn Module>>>,
client_asset_context: Vc<Box<dyn AssetContext>>,
) -> Result<IndexMap<Vc<Box<dyn Module>>, DynamicImportedModules>> {
// Traverse referenced modules graph, collect all of the dynamic imports:
// - Read the Program AST of the Module, this is the origin (A)
// - If there's `dynamic(import(B))`, then B is the module that is being imported
// - If there's `dynamic(import(B))`, then B is the module that is being
// imported
// Returned import mappings are in the form of
// (Module<A>, Vec<(B, Module<B>)>) (where B is the raw import source string,
// and Module<B> is the actual resolved Module)
Expand Down
4 changes: 2 additions & 2 deletions crates/next-core/src/next_app/app_route_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use crate::{
/// Computes the entry for a Next.js app route.
/// # Arguments
///
/// * `original_segment_config` - A next segment config to be specified explicitly for the given
/// source.
/// * `original_segment_config` - A next segment config to be specified
/// explicitly for the given source.
/// For some cases `source` may not be the original but the handler (dynamic
/// metadata) which will lose segment config.
#[turbo_tasks::function]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use turbopack_ecmascript::chunk::EcmascriptChunkPlaceable;

/// An [EcmascriptClientReferenceModule] is a marker module, used by the
/// [super::ecmascript_client_reference_proxy_module::EcmascriptClientReferenceProxyModule] to
/// indicate which client reference should appear in the client reference manifest.
/// indicate which client reference should appear in the client reference
/// manifest.
#[turbo_tasks::value]
pub struct EcmascriptClientReferenceModule {
pub server_ident: Vc<AssetIdent>,
Expand All @@ -24,8 +25,8 @@ impl EcmascriptClientReferenceModule {
///
/// # Arguments
///
/// * `server_ident` - The identifier of the server module, used to identify the client
/// reference.
/// * `server_ident` - The identifier of the server module, used to identify
/// the client reference.
/// * `client_module` - The client module.
/// * `ssr_module` - The SSR module.
#[turbo_tasks::function]
Expand Down
4 changes: 2 additions & 2 deletions crates/next-core/src/next_font/local/font_fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ fn calc_average_width(font: &mut Font<DynamicFontTableProvider>) -> Option<f32>
/// font file:
/// - Most of the text will have normal weight, use the one closest to 400
/// - Most of the text will have normal style, prefer normal over italic
/// - If two font files have the same distance from normal weight, the thinner one will most likely
/// be the bulk of the text
/// - If two font files have the same distance from normal weight, the thinner
/// one will most likely be the bulk of the text
fn pick_font_for_fallback_generation(
font_descriptors: &FontDescriptors,
) -> Result<&FontDescriptor> {
Expand Down
4 changes: 2 additions & 2 deletions crates/next-core/src/next_font/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ pub(crate) enum FontFamilyType {
}

/// Returns a uniquely scoped version of the font family, e.g.`__Roboto_c123b8`
/// * `ty` - Whether to generate a scoped classname for the main font or its fallback equivalent,
/// e.g. `__Roboto_Fallback_c123b8`
/// * `ty` - Whether to generate a scoped classname for the main font or its
/// fallback equivalent, e.g. `__Roboto_Fallback_c123b8`
/// * `font_family_name` - The font name to scope, e.g. `Roboto`
/// * `request_hash` - The hash value of the font request
#[turbo_tasks::function]
Expand Down
11 changes: 6 additions & 5 deletions crates/next-custom-transforms/src/transforms/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ pub enum NextDynamicMode {
/// the React Loadable Webpack plugin.
Webpack,
/// In Turbopack mode:
/// * in development, each `dynamic()` call will generate a key containing both the imported
/// module id and the chunks it needs. This removes the need for a manifest entry
/// * during build, each `dynamic()` call will import the module through the given transition,
/// which takes care of adding an entry to the manifest and returning an asset that exports
/// the entry's key.
/// * in development, each `dynamic()` call will generate a key containing
/// both the imported module id and the chunks it needs. This removes the
/// need for a manifest entry
/// * during build, each `dynamic()` call will import the module through the
/// given transition, which takes care of adding an entry to the manifest
/// and returning an asset that exports the entry's key.
Turbopack { dynamic_transition_name: String },
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ impl PageMode {
}

/// A transform that either:
/// * strips Next.js data exports (getServerSideProps, getStaticProps, getStaticPaths); or
/// * strips Next.js data exports (getServerSideProps, getStaticProps,
/// getStaticPaths); or
/// * strips the default export.
///
/// Note: This transform requires running `resolver` **before** running it.
Expand Down
Loading

0 comments on commit ee62103

Please sign in to comment.