Skip to content

Commit

Permalink
Merge branch 'canary' into upgrade-react
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi authored Feb 21, 2024
2 parents 1b76efe + 063c286 commit 58ef5c4
Show file tree
Hide file tree
Showing 80 changed files with 1,834 additions and 14,506 deletions.
2 changes: 2 additions & 0 deletions docs/02-app/02-api-reference/01-components/link.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ Prefetching happens when a `<Link />` component enters the user's viewport (init
- **`true` (default)**: The full route and its data will be prefetched.
- `false`: Prefetching will be disabled.

> **Good to know**: When `prefetch` is set to `false`, prefetching will still occur on hover.
```tsx filename="pages/index.tsx" switcher
import Link from 'next/link'

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": "14.1.1-canary.65"
"version": "14.1.1-canary.67"
}
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": "14.1.1-canary.65",
"version": "14.1.1-canary.67",
"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": "14.1.1-canary.65",
"version": "14.1.1-canary.67",
"description": "ESLint configuration used by Next.js.",
"main": "index.js",
"license": "MIT",
Expand All @@ -10,7 +10,7 @@
},
"homepage": "https://nextjs.org/docs/app/building-your-application/configuring/eslint#eslint-config",
"dependencies": {
"@next/eslint-plugin-next": "14.1.1-canary.65",
"@next/eslint-plugin-next": "14.1.1-canary.67",
"@rushstack/eslint-patch": "^1.3.3",
"@typescript-eslint/parser": "^5.4.2 || ^6.0.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": "14.1.1-canary.65",
"version": "14.1.1-canary.67",
"description": "ESLint plugin for Next.js.",
"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": "14.1.1-canary.65",
"version": "14.1.1-canary.67",
"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": "14.1.1-canary.65",
"version": "14.1.1-canary.67",
"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": "14.1.1-canary.65",
"version": "14.1.1-canary.67",
"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": "14.1.1-canary.65",
"version": "14.1.1-canary.67",
"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": "14.1.1-canary.65",
"version": "14.1.1-canary.67",
"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": "14.1.1-canary.65",
"version": "14.1.1-canary.67",
"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": "14.1.1-canary.65",
"version": "14.1.1-canary.67",
"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": "14.1.1-canary.65",
"version": "14.1.1-canary.67",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
7 changes: 1 addition & 6 deletions packages/next-swc/crates/next-core/src/app_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ async fn get_directory_tree_internal(
// appDir ignores paths starting with an underscore
if !basename.starts_with('_') {
let result = get_directory_tree(dir, page_extensions);
subdirectories.insert(get_underscore_normalized_path(basename), result);
subdirectories.insert(basename.to_string(), result);
}
}
// TODO(WEB-952) handle symlinks in app dir
Expand Down Expand Up @@ -1145,11 +1145,6 @@ async fn directory_tree_to_entrypoints_internal_untraced(
Ok(Vc::cell(result))
}

/// If path contains %5F, replace it with _. [reference](https://github.com/vercel/next.js/blob/c390c1662bc79e12cf7c037dcb382ef5ead6e492/packages/next/src/build/entries.ts#L119)
fn get_underscore_normalized_path(path: &str) -> String {
path.replace("%5F", "_")
}

/// Returns the global metadata for an app directory.
#[turbo_tasks::function]
pub async fn get_global_metadata(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,23 @@ impl ClientReferenceManifest {

let client_reference_manifest_json = serde_json::to_string(&entry_manifest).unwrap();

// We put normalized path for the each entry key and the manifest output path,
// to conform next.js's load client reference manifest behavior:
// https://github.com/vercel/next.js/blob/2f9d718695e4c90be13c3bf0f3647643533071bf/packages/next/src/server/load-components.ts#L162-L164
// note this only applies to the manifests, assets are placed to the original
// path still (same as webpack does)
let normalized_manifest_entry = entry_name.replace("%5F", "_");
Ok(Vc::upcast(VirtualOutputAsset::new(
node_root.join(format!(
"server/app/{entry_name}_client-reference-manifest.js",
"server/app{normalized_manifest_entry}_client-reference-manifest.js",
)),
AssetContent::file(
File::from(formatdoc! {
r#"
globalThis.__RSC_MANIFEST = globalThis.__RSC_MANIFEST || {{}};
globalThis.__RSC_MANIFEST[{entry_name}] = {manifest}
"#,
entry_name = StringifyJs(&entry_name),
entry_name = StringifyJs(&normalized_manifest_entry),
manifest = &client_reference_manifest_json
})
.into(),
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": "14.1.1-canary.65",
"version": "14.1.1-canary.67",
"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": "14.1.1-canary.65",
"version": "14.1.1-canary.67",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down Expand Up @@ -92,7 +92,7 @@
]
},
"dependencies": {
"@next/env": "14.1.1-canary.65",
"@next/env": "14.1.1-canary.67",
"@swc/helpers": "0.5.5",
"busboy": "1.6.0",
"caniuse-lite": "^1.0.30001579",
Expand Down Expand Up @@ -136,7 +136,7 @@
"@babel/runtime": "7.22.5",
"@babel/traverse": "7.22.5",
"@babel/types": "7.22.5",
"@capsizecss/metrics": "1.1.0",
"@capsizecss/metrics": "2.0.0",
"@edge-runtime/cookies": "4.0.2",
"@edge-runtime/ponyfill": "2.4.1",
"@edge-runtime/primitives": "4.0.2",
Expand All @@ -145,10 +145,10 @@
"@jest/types": "29.5.0",
"@mswjs/interceptors": "0.23.0",
"@napi-rs/triples": "1.2.0",
"@next/polyfill-module": "14.1.1-canary.65",
"@next/polyfill-nomodule": "14.1.1-canary.65",
"@next/react-refresh-utils": "14.1.1-canary.65",
"@next/swc": "14.1.1-canary.65",
"@next/polyfill-module": "14.1.1-canary.67",
"@next/polyfill-nomodule": "14.1.1-canary.67",
"@next/react-refresh-utils": "14.1.1-canary.67",
"@next/swc": "14.1.1-canary.67",
"@opentelemetry/api": "1.6.0",
"@playwright/test": "1.41.2",
"@taskr/clear": "1.1.0",
Expand Down
63 changes: 21 additions & 42 deletions packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,15 +715,11 @@ export default async function getBaseWebpackConfig(
// Packages which will be split into the 'framework' chunk.
// Only top-level packages are included, e.g. nested copies like
// 'node_modules/meow/node_modules/object-assign' are not included.
const nextFrameworkPaths: string[] = []
const topLevelFrameworkPaths: string[] = []
const visitedFrameworkPackages = new Set<string>()

// Adds package-paths of dependencies recursively
const addPackagePath = (
packageName: string,
relativeToPath: string,
paths: string[]
) => {
const addPackagePath = (packageName: string, relativeToPath: string) => {
try {
if (visitedFrameworkPackages.has(packageName)) {
return
Expand All @@ -742,11 +738,11 @@ export default async function getBaseWebpackConfig(
const directory = path.join(packageJsonPath, '../')

// Returning from the function in case the directory has already been added and traversed
if (paths.includes(directory)) return
paths.push(directory)
if (topLevelFrameworkPaths.includes(directory)) return
topLevelFrameworkPaths.push(directory)
const dependencies = require(packageJsonPath).dependencies || {}
for (const name of Object.keys(dependencies)) {
addPackagePath(name, directory, paths)
addPackagePath(name, directory)
}
} catch (_) {
// don't error on failing to resolve framework packages
Expand All @@ -763,9 +759,8 @@ export default async function getBaseWebpackConfig(
]
: []),
]) {
addPackagePath(packageName, dir, topLevelFrameworkPaths)
addPackagePath(packageName, dir)
}
addPackagePath('next', dir, nextFrameworkPaths)

const crossOrigin = config.crossOrigin

Expand Down Expand Up @@ -918,7 +913,6 @@ export default async function getBaseWebpackConfig(
splitChunks: (():
| Required<webpack.Configuration>['optimization']['splitChunks']
| false => {
// server chunking
if (dev) {
if (isNodeServer) {
/*
Expand Down Expand Up @@ -969,6 +963,21 @@ export default async function getBaseWebpackConfig(
return false
}

if (isNodeServer) {
return {
filename: '[name].js',
chunks: 'all',
minChunks: 2,
}
}

if (isEdgeServer) {
return {
filename: 'edge-chunks/[name].js',
minChunks: 2,
}
}

const frameworkCacheGroup = {
chunks: 'all' as const,
name: 'framework',
Expand All @@ -987,22 +996,6 @@ export default async function getBaseWebpackConfig(
// becoming a part of the commons chunk)
enforce: true,
}

const nextRuntimeCacheGroup = {
chunks: 'all' as const,
name: 'next-runtime',
test(module: any) {
const resource = module.nameForCondition?.()
return resource
? nextFrameworkPaths.some((pkgPath) =>
resource.startsWith(pkgPath)
)
: false
},
priority: 30,
enforce: true,
}

const libCacheGroup = {
test(module: {
size: Function
Expand Down Expand Up @@ -1044,20 +1037,6 @@ export default async function getBaseWebpackConfig(
minChunks: 1,
reuseExistingChunk: true,
}

if (isNodeServer || isEdgeServer) {
return {
filename: `${isEdgeServer ? 'edge-chunks/' : ''}[name].js`,
cacheGroups: {
nextRuntime: nextRuntimeCacheGroup,
framework: frameworkCacheGroup,
lib: libCacheGroup,
},
minChunks: 2,
}
}

// client chunking
const cssCacheGroup = {
test: /\.(css|sass|scss)$/i,
chunks: 'all' as const,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ export class TerserPlugin {
return false
}

// don't minify _middleware as it can break in some cases
// and doesn't provide too much of a benefit as it's server-side
if (
name.match(
/(edge-runtime-webpack\.js|edge-chunks|middleware\.js$)/
)
) {
return false
}

const { info } = res

// Skip double minimize assets from child compilation
Expand Down
Loading

0 comments on commit 58ef5c4

Please sign in to comment.