Skip to content

Commit

Permalink
refactor(next-api): update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Oct 11, 2023
1 parent 3f8006c commit 203f65a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
8 changes: 2 additions & 6 deletions packages/next-swc/crates/next-api/src/dynamic_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,9 @@ async fn build_dynamic_imports_map_for_module(
return Ok(OptionDynamicImportsMap::none());
};

// https://github.com/vercel/next.js/pull/56389#discussion_r1349336374
// don't emit specific error as we expect there's a parse error already reported
let ParseResult::Ok { program, .. } = &*ecmascript_asset.parse().await? else {
NextDynamicParsingIssue {
ident: module.ident(),
}
.cell()
.emit();

return Ok(OptionDynamicImportsMap::none());
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ impl CustomTransformer for NextJsDynamic {
},
self.is_server,
self.is_server_components,
// [NOTE] We do not use `NextDynamicMode::Turbopack` yet, it isn't compatible with
// current loadable manifest, which causes hydration errors.
NextDynamicMode::Webpack,
FileName::Real(ctx.file_path_str.into()),
self.pages_dir.clone(),
Expand Down
3 changes: 3 additions & 0 deletions packages/next-swc/crates/next-transform-dynamic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ use swc_core::{

/// Creates a SWC visitor to transform `next/dynamic` calls to have the
/// corresponding `loadableGenerated` property.
///
/// [NOTE] We do not use `NextDynamicMode::Turbopack` yet. It isn't compatible
/// with current loadable manifest, which causes hydration errors.
pub fn next_dynamic(
is_development: bool,
is_server: bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ import {
import { normalizeMetadataRoute } from '../../../lib/metadata/get-metadata-route'
import { clearModuleContext } from '../render-server'
import type { ActionManifest } from '../../../build/webpack/plugins/flight-client-entry-plugin'
import type { LodableManifest } from '../../load-components'

const wsServer = new ws.Server({ noServer: true })

Expand All @@ -131,10 +132,6 @@ type SetupOpts = {
port: number
}

interface LodableManifest {
[k: string]: { id: string | number; files: string[] }
}

async function verifyTypeScript(opts: SetupOpts) {
let usingTypeScript = false
const verifyResult = await verifyTypeScriptSetup({
Expand Down Expand Up @@ -560,7 +557,7 @@ async function startWatcher(opts: SetupOpts) {
)
)
}

async function loadLodableManifest(
pageName: string,
type: 'app' | 'pages' = 'pages'
Expand Down Expand Up @@ -707,7 +704,7 @@ async function startWatcher(opts: SetupOpts) {

return manifest
}

function mergeLodableManifests(manifests: Iterable<LodableManifest>) {
const manifest: LodableManifest = {}
for (const m of manifests) {
Expand Down
11 changes: 11 additions & 0 deletions packages/next/src/server/load-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ export type ManifestItem = {

export type ReactLoadableManifest = { [moduleId: string]: ManifestItem }

/**
* A manifest entry type for the react-loadable-manifest.json.
*
* The whole manifest.json is a type of `Record<pathName, LodableManifest>`
* where pathName is a string-based key points to the path of the page contains
* each dynamic imports.
*/
export interface LodableManifest {
[k: string]: { id: string | number; files: string[] }
}

export type LoadComponentsReturnType<NextModule = any> = {
Component: NextComponentType
pageConfig: PageConfig
Expand Down

0 comments on commit 203f65a

Please sign in to comment.