Skip to content

Commit

Permalink
Merge branch 'canary' into wyattjoh/pages-route-rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattjoh committed May 30, 2023
2 parents f3d0754 + 8dba9a7 commit a89d43f
Show file tree
Hide file tree
Showing 34 changed files with 429 additions and 222 deletions.
309 changes: 152 additions & 157 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ next-transform-strip-page-exports = { path = "packages/next-swc/crates/next-tran

# SWC crates
# Keep consistent with preset_env_base through swc_core
swc_core = { version = "0.76.18" }
testing = { version = "0.33.11" }
swc_core = { version = "0.76.37" }
testing = { version = "0.33.13" }

# Turbo crates
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230526.5" }
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "13.4.5-canary.0"
"version": "13.4.5-canary.2"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "13.4.5-canary.0",
"version": "13.4.5-canary.2",
"keywords": [
"react",
"next",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-config-next",
"version": "13.4.5-canary.0",
"version": "13.4.5-canary.2",
"description": "ESLint configuration used by NextJS.",
"main": "index.js",
"license": "MIT",
Expand All @@ -9,7 +9,7 @@
"directory": "packages/eslint-config-next"
},
"dependencies": {
"@next/eslint-plugin-next": "13.4.5-canary.0",
"@next/eslint-plugin-next": "13.4.5-canary.2",
"@rushstack/eslint-patch": "^1.1.3",
"@typescript-eslint/parser": "^5.42.0",
"eslint-import-resolver-node": "^0.3.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/eslint-plugin-next",
"version": "13.4.5-canary.0",
"version": "13.4.5-canary.2",
"description": "ESLint plugin for NextJS.",
"main": "dist/index.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/font/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/font",
"version": "13.4.5-canary.0",
"version": "13.4.5-canary.2",
"repository": {
"url": "vercel/next.js",
"directory": "packages/font"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "13.4.5-canary.0",
"version": "13.4.5-canary.2",
"main": "index.js",
"types": "index.d.ts",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-codemod/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/codemod",
"version": "13.4.5-canary.0",
"version": "13.4.5-canary.2",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-env/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/env",
"version": "13.4.5-canary.0",
"version": "13.4.5-canary.2",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "13.4.5-canary.0",
"version": "13.4.5-canary.2",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-storybook/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-storybook",
"version": "13.4.5-canary.0",
"version": "13.4.5-canary.2",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-storybook"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-module/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-module",
"version": "13.4.5-canary.0",
"version": "13.4.5-canary.2",
"description": "A standard library polyfill for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)",
"main": "dist/polyfill-module.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-nomodule/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "13.4.5-canary.0",
"version": "13.4.5-canary.2",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/swc",
"version": "13.4.5-canary.0",
"version": "13.4.5-canary.2",
"private": true,
"scripts": {
"clean": "node ../../scripts/rm.mjs native",
Expand Down
14 changes: 7 additions & 7 deletions packages/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "13.4.5-canary.0",
"version": "13.4.5-canary.2",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down Expand Up @@ -83,7 +83,7 @@
]
},
"dependencies": {
"@next/env": "13.4.5-canary.0",
"@next/env": "13.4.5-canary.2",
"@swc/helpers": "0.5.1",
"busboy": "1.6.0",
"caniuse-lite": "^1.0.30001406",
Expand Down Expand Up @@ -139,11 +139,11 @@
"@jest/types": "29.5.0",
"@napi-rs/cli": "2.14.7",
"@napi-rs/triples": "1.1.0",
"@next/polyfill-module": "13.4.5-canary.0",
"@next/polyfill-nomodule": "13.4.5-canary.0",
"@next/react-dev-overlay": "13.4.5-canary.0",
"@next/react-refresh-utils": "13.4.5-canary.0",
"@next/swc": "13.4.5-canary.0",
"@next/polyfill-module": "13.4.5-canary.2",
"@next/polyfill-nomodule": "13.4.5-canary.2",
"@next/react-dev-overlay": "13.4.5-canary.2",
"@next/react-refresh-utils": "13.4.5-canary.2",
"@next/swc": "13.4.5-canary.2",
"@opentelemetry/api": "1.4.1",
"@segment/ajv-human-errors": "2.1.2",
"@taskr/clear": "1.1.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/next/src/build/analysis/get-page-static-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface PageStaticInfo {
ssr?: boolean
rsc?: RSCModuleType
middleware?: Partial<MiddlewareConfig>
amp?: boolean | 'hybrid'
}

const CLIENT_MODULE_LABEL =
Expand Down Expand Up @@ -488,6 +489,7 @@ export async function getPageStaticInfo(params: {
ssr,
ssg,
rsc,
amp: config.amp || false,
...(middlewareConfig && { middleware: middlewareConfig }),
...(resolvedRuntime && { runtime: resolvedRuntime }),
preferredRegion,
Expand All @@ -498,6 +500,7 @@ export async function getPageStaticInfo(params: {
ssr: false,
ssg: false,
rsc: RSC_MODULE_TYPES.server,
amp: false,
runtime: undefined,
}
}
7 changes: 1 addition & 6 deletions packages/next/src/build/webpack/loaders/next-app-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,7 @@ async function createTreeCodeFromPath(
const defaultPath =
(await resolver(
`${appDirPrefix}${segmentPath}/${actualSegment}/default`
)) ??
(await resolver(
`next/dist/client/components/parallel-route-default`,
false,
true
))
)) ?? 'next/dist/client/components/parallel-route-default'

props[normalizeParallelKey(adjacentParallelSegment)] = `[
'__DEFAULT__',
Expand Down
120 changes: 105 additions & 15 deletions packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,66 @@ const pluginState = getProxiedPluginState({
injectedClientEntries: {} as Record<string, string>,
})

function deduplicateCSSImportsForEntry(mergedCSSimports: CssImports) {
// If multiple entry module connections are having the same CSS import,
// we only need to have one module to keep track of that CSS import.
// It is based on the fact that if a page or a layout is rendered in the
// given entry, all its parent layouts are always rendered too.
// This can avoid duplicate CSS imports in the generated CSS manifest,
// for example, if a page and its parent layout are both using the same
// CSS import, we only need to have the layout to keep track of that CSS
// import.
// To achieve this, we need to first collect all the CSS imports from
// every connection, and deduplicate them in the order of layers from
// top to bottom. The implementation can be generally described as:
// - Sort by number of `/` in the request path (the more `/`, the deeper)
// - When in the same depth, sort by the filename (template < layout < page and others)

// Sort the connections as described above.
const sortedCSSImports = Object.entries(mergedCSSimports).sort((a, b) => {
const [aPath] = a
const [bPath] = b

const aDepth = aPath.split('/').length
const bDepth = bPath.split('/').length

if (aDepth !== bDepth) {
return aDepth - bDepth
}

const aName = path.parse(aPath).name
const bName = path.parse(bPath).name

const indexA = ['template', 'layout'].indexOf(aName)
const indexB = ['template', 'layout'].indexOf(bName)

if (indexA === -1) return 1
if (indexB === -1) return -1
return indexA - indexB
})

const dedupedCSSImports: CssImports = {}
const trackedCSSImports = new Set<string>()
for (const [entryName, cssImports] of sortedCSSImports) {
for (const cssImport of cssImports) {
if (trackedCSSImports.has(cssImport)) continue

// Only track CSS imports that are in files that can inherit CSS.
const filename = path.parse(entryName).name
if (['template', 'layout'].includes(filename)) {
trackedCSSImports.add(cssImport)
}

if (!dedupedCSSImports[entryName]) {
dedupedCSSImports[entryName] = []
}
dedupedCSSImports[entryName].push(cssImport)
}
}

return dedupedCSSImports
}

export class ClientReferenceEntryPlugin {
dev: boolean
appDir: string
Expand Down Expand Up @@ -196,6 +256,8 @@ export class ClientReferenceEntryPlugin {
ClientComponentImports[0]
>()
const actionEntryImports = new Map<string, string[]>()
const clientEntriesToInject = []
const mergedCSSimports: CssImports = {}

for (const connection of compilation.moduleGraph.getOutgoingConnections(
entryModule
Expand All @@ -204,7 +266,7 @@ export class ClientReferenceEntryPlugin {
const entryDependency = connection.dependency
const entryRequest = connection.dependency.request

const { clientImports, actionImports } =
const { clientComponentImports, actionImports, cssImports } =
this.collectComponentInfoFromDependencies({
entryRequest,
compilation,
Expand All @@ -219,12 +281,18 @@ export class ClientReferenceEntryPlugin {

// Next.js internals are put into a separate entry.
if (!isAbsoluteRequest) {
clientImports.forEach((value) =>
clientComponentImports.forEach((value) =>
internalClientComponentEntryImports.add(value)
)
continue
}

// TODO-APP: Enable these lines. This ensures no entrypoint is created for layout/page when there are no client components.
// Currently disabled because it causes test failures in CI.
// if (clientImports.length === 0 && actionImports.length === 0) {
// continue
// }

const relativeRequest = isAbsoluteRequest
? path.relative(compilation.options.context, entryRequest)
: entryRequest
Expand All @@ -234,14 +302,30 @@ export class ClientReferenceEntryPlugin {
relativeRequest.replace(/\.[^.\\/]+$/, '').replace(/^src[\\/]/, '')
)

Object.assign(mergedCSSimports, cssImports)
clientEntriesToInject.push({
compiler,
compilation,
entryName: name,
clientComponentImports,
cssImports,
bundlePath,
absolutePagePath: entryRequest,
})
}

// Make sure CSS imports are deduplicated before injecting the client entry
// and SSR modules.
const dedupedCSSImports = deduplicateCSSImportsForEntry(mergedCSSimports)
for (const clientEntryToInject of clientEntriesToInject) {
addClientEntryAndSSRModulesList.push(
this.injectClientEntryAndSSRModules({
compiler,
compilation,
entryName: name,
clientImports,
bundlePath,
absolutePagePath: entryRequest,
...clientEntryToInject,
clientImports: [
...clientEntryToInject.clientComponentImports,
...(dedupedCSSImports[clientEntryToInject.absolutePagePath] ||
[]),
],
})
)
}
Expand Down Expand Up @@ -447,6 +531,8 @@ export class ClientReferenceEntryPlugin {
forEachEntryModule(compilation, ({ name, entryModule }) => {
const clientEntryDependencyMap = collectClientEntryDependencyMap(name)
const tracked = new Set<string>()
const mergedCSSimports: CssImports = {}

for (const connection of compilation.moduleGraph.getOutgoingConnections(
entryModule
)) {
Expand All @@ -465,9 +551,14 @@ export class ClientReferenceEntryPlugin {
clientEntryDependencyMap,
})

if (!cssManifest.cssImports) cssManifest.cssImports = {}
Object.assign(cssManifest.cssImports, cssImports)
Object.assign(mergedCSSimports, cssImports)
}

if (!cssManifest.cssImports) cssManifest.cssImports = {}
Object.assign(
cssManifest.cssImports,
deduplicateCSSImportsForEntry(mergedCSSimports)
)
})
})

Expand Down Expand Up @@ -534,8 +625,8 @@ export class ClientReferenceEntryPlugin {
dependency: any /* Dependency */
clientEntryDependencyMap?: Record<string, any>
}): {
clientImports: ClientComponentImports
cssImports: CssImports
clientComponentImports: ClientComponentImports
actionImports: [string, string[]][]
clientActionImports: [string, string[]][]
} {
Expand Down Expand Up @@ -605,13 +696,12 @@ export class ClientReferenceEntryPlugin {
CSSImports.add(modRequest)
}

// Check if request is for css file.
if ((!inClientComponentBoundary && isClientComponent) || isCSS) {
if (!inClientComponentBoundary && isClientComponent) {
clientComponentImports.push(modRequest)

// Here we are entering a client boundary, and we need to collect dependencies
// in the client graph too.
if (isClientComponent && clientEntryDependencyMap) {
if (clientEntryDependencyMap) {
if (clientEntryDependencyMap[modRequest]) {
filterClientComponents(clientEntryDependencyMap[modRequest], true)
}
Expand All @@ -637,7 +727,7 @@ export class ClientReferenceEntryPlugin {
}

return {
clientImports: clientComponentImports,
clientComponentImports,
cssImports: CSSImports.size
? {
[entryRequest]: Array.from(CSSImports),
Expand Down

0 comments on commit a89d43f

Please sign in to comment.