Skip to content

Commit

Permalink
Merge branch 'canary' into kdy1/swc-core-96-1
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 authored Jul 8, 2024
2 parents 2847019 + b277e2a commit 92b3627
Show file tree
Hide file tree
Showing 29 changed files with 212 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ You could also use the returned state to display a toast message from the client
### Handling Expected Errors from Server Components
When fetching data inside of a Server Component, you can use the response to conditionally render an error message or `redirect`.
When fetching data inside of a Server Component, you can use the response to conditionally render an error message or [`redirect`](/docs/app/building-your-application/routing/redirecting#redirect-function).
```tsx filename="app/page.tsx" switcher
export default async function Page() {
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": "15.0.0-canary.57"
"version": "15.0.0-canary.58"
}
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": "15.0.0-canary.57",
"version": "15.0.0-canary.58",
"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": "15.0.0-canary.57",
"version": "15.0.0-canary.58",
"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": "15.0.0-canary.57",
"@next/eslint-plugin-next": "15.0.0-canary.58",
"@rushstack/eslint-patch": "^1.3.3",
"@typescript-eslint/eslint-plugin": "^5.4.2 || ^6.0.0 || ^7.0.0",
"@typescript-eslint/parser": "^5.4.2 || ^6.0.0 || ^7.0.0",
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": "15.0.0-canary.57",
"version": "15.0.0-canary.58",
"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": "15.0.0-canary.57",
"version": "15.0.0-canary.58",
"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": "15.0.0-canary.57",
"version": "15.0.0-canary.58",
"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": "15.0.0-canary.57",
"version": "15.0.0-canary.58",
"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": "15.0.0-canary.57",
"version": "15.0.0-canary.58",
"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": "15.0.0-canary.57",
"version": "15.0.0-canary.58",
"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": "15.0.0-canary.57",
"version": "15.0.0-canary.58",
"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": "15.0.0-canary.57",
"version": "15.0.0-canary.58",
"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": "15.0.0-canary.57",
"version": "15.0.0-canary.58",
"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": "15.0.0-canary.57",
"version": "15.0.0-canary.58",
"private": true,
"scripts": {
"clean": "node ../../scripts/rm.mjs native",
Expand Down
12 changes: 6 additions & 6 deletions packages/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "15.0.0-canary.57",
"version": "15.0.0-canary.58",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down Expand Up @@ -93,7 +93,7 @@
]
},
"dependencies": {
"@next/env": "15.0.0-canary.57",
"@next/env": "15.0.0-canary.58",
"@swc/helpers": "0.5.11",
"busboy": "1.6.0",
"caniuse-lite": "^1.0.30001579",
Expand Down Expand Up @@ -157,10 +157,10 @@
"@jest/types": "29.5.0",
"@mswjs/interceptors": "0.23.0",
"@napi-rs/triples": "1.2.0",
"@next/polyfill-module": "15.0.0-canary.57",
"@next/polyfill-nomodule": "15.0.0-canary.57",
"@next/react-refresh-utils": "15.0.0-canary.57",
"@next/swc": "15.0.0-canary.57",
"@next/polyfill-module": "15.0.0-canary.58",
"@next/polyfill-nomodule": "15.0.0-canary.58",
"@next/react-refresh-utils": "15.0.0-canary.58",
"@next/swc": "15.0.0-canary.58",
"@opentelemetry/api": "1.6.0",
"@playwright/test": "1.41.2",
"@swc/core": "1.6.6",
Expand Down
26 changes: 12 additions & 14 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ export default async function build(
distDir,
fetchCacheKeyPrefix: config.experimental.fetchCacheKeyPrefix,
hasRewrites,
// TODO: Implement
// Implemented separately in Turbopack, doesn't have to be passed here.
middlewareMatchers: undefined,
}),
buildId: NextBuildContext.buildId!,
Expand Down Expand Up @@ -1404,13 +1404,6 @@ export default async function build(
encryptionKey,
})

// TODO: implement this
const emptyRewritesObjToBeImplemented = {
beforeFiles: [],
afterFiles: [],
fallback: [],
}

const entrypointsResult = await entrypointsSubscription.next()
if (entrypointsResult.done) {
throw new Error('Turbopack did not return any entrypoints')
Expand Down Expand Up @@ -1442,7 +1435,8 @@ export default async function build(
currentEntryIssues,
manifestLoader,
nextConfig: config,
rewrites: emptyRewritesObjToBeImplemented,
devRewrites: undefined,
productionRewrites: customRoutes.rewrites,
logErrors: false,
})

Expand Down Expand Up @@ -1477,7 +1471,8 @@ export default async function build(
currentEntryIssues,
entrypoints: currentEntrypoints,
manifestLoader,
rewrites: emptyRewritesObjToBeImplemented,
devRewrites: undefined,
productionRewrites: customRoutes.rewrites,
logErrors: false,
})
)
Expand All @@ -1493,7 +1488,8 @@ export default async function build(
currentEntryIssues,
entrypoints: currentEntrypoints,
manifestLoader,
rewrites: emptyRewritesObjToBeImplemented,
devRewrites: undefined,
productionRewrites: customRoutes.rewrites,
logErrors: false,
})
)
Expand All @@ -1504,15 +1500,17 @@ export default async function build(
currentEntryIssues,
entrypoints: currentEntrypoints,
manifestLoader,
rewrites: emptyRewritesObjToBeImplemented,
devRewrites: undefined,
productionRewrites: customRoutes.rewrites,
logErrors: false,
})
)
await Promise.all(promises)

await manifestLoader.writeManifests({
rewrites: emptyRewritesObjToBeImplemented,
pageEntrypoints: currentEntrypoints.page,
devRewrites: undefined,
productionRewrites: customRoutes.rewrites,
entrypoints: currentEntrypoints,
})

const errors: {
Expand Down
14 changes: 10 additions & 4 deletions packages/next/src/build/webpack/plugins/build-manifest-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,15 @@ export function normalizeRewritesForBuildManifest(
rewrites: CustomRoutes['rewrites']
): CustomRoutes['rewrites'] {
return {
afterFiles: rewrites.afterFiles?.map((item) => normalizeRewrite(item)),
beforeFiles: rewrites.beforeFiles?.map((item) => normalizeRewrite(item)),
fallback: rewrites.fallback?.map((item) => normalizeRewrite(item)),
afterFiles: rewrites.afterFiles
?.map(processRoute)
?.map((item) => normalizeRewrite(item)),
beforeFiles: rewrites.beforeFiles
?.map(processRoute)
?.map((item) => normalizeRewrite(item)),
fallback: rewrites.fallback
?.map(processRoute)
?.map((item) => normalizeRewrite(item)),
}
}

Expand Down Expand Up @@ -143,7 +149,7 @@ export const processRoute = (r: Rewrite) => {

// omit external rewrite destinations since these aren't
// handled client-side
if (!rewrite.destination.startsWith('/')) {
if (!rewrite?.destination?.startsWith('/')) {
delete (rewrite as any).destination
}
return rewrite
Expand Down
6 changes: 5 additions & 1 deletion packages/next/src/build/webpack/plugins/define-env-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ export function getDefineEnv({
'process.env.__NEXT_AFTER': config.experimental.after ?? false,
'process.env.NEXT_DEPLOYMENT_ID': config.deploymentId || false,
'process.env.__NEXT_FETCH_CACHE_KEY_PREFIX': fetchCacheKeyPrefix ?? '',
'process.env.__NEXT_MIDDLEWARE_MATCHERS': middlewareMatchers ?? [],
...(isTurbopack
? {}
: {
'process.env.__NEXT_MIDDLEWARE_MATCHERS': middlewareMatchers ?? [],
}),
'process.env.__NEXT_MANUAL_CLIENT_BASE_PATH':
config.experimental.manualClientBasePath ?? false,
'process.env.__NEXT_CLIENT_ROUTER_DYNAMIC_STALETIME': JSON.stringify(
Expand Down
36 changes: 33 additions & 3 deletions packages/next/src/client/page-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { removeTrailingSlash } from '../shared/lib/router/utils/remove-trailing-
import { createRouteLoader, getClientBuildManifest } from './route-loader'
import {
DEV_CLIENT_PAGES_MANIFEST,
DEV_MIDDLEWARE_MANIFEST,
DEV_CLIENT_MIDDLEWARE_MANIFEST,
TURBOPACK_CLIENT_MIDDLEWARE_MANIFEST,
} from '../shared/lib/constants'

declare global {
Expand Down Expand Up @@ -85,12 +86,41 @@ export default class PageLoader {
}

getMiddleware() {
if (process.env.NODE_ENV === 'production') {
// Webpack production
if (
process.env.NODE_ENV === 'production' &&
process.env.__NEXT_MIDDLEWARE_MATCHERS
) {
const middlewareMatchers = process.env.__NEXT_MIDDLEWARE_MATCHERS
window.__MIDDLEWARE_MATCHERS = middlewareMatchers
? (middlewareMatchers as any as MiddlewareMatcher[])
: undefined
return window.__MIDDLEWARE_MATCHERS
// Turbopack production
} else if (process.env.NODE_ENV === 'production') {
if (window.__MIDDLEWARE_MATCHERS) {
return window.__MIDDLEWARE_MATCHERS
} else {
if (!this.promisedMiddlewareMatchers) {
// TODO: Decide what should happen when fetching fails instead of asserting
// @ts-ignore
this.promisedMiddlewareMatchers = fetch(
`${this.assetPrefix}/_next/static/${this.buildId}/${TURBOPACK_CLIENT_MIDDLEWARE_MANIFEST}`,
{ credentials: 'same-origin' }
)
.then((res) => res.json())
.then((matchers: MiddlewareMatcher[]) => {
window.__MIDDLEWARE_MATCHERS = matchers
return matchers
})
.catch((err) => {
console.log(`Failed to fetch _devMiddlewareManifest`, err)
})
}
// TODO Remove this assertion as this could be undefined
return this.promisedMiddlewareMatchers!
}
// Development both Turbopack and Webpack
} else {
if (window.__DEV_MIDDLEWARE_MATCHERS) {
return window.__DEV_MIDDLEWARE_MATCHERS
Expand All @@ -99,7 +129,7 @@ export default class PageLoader {
// TODO: Decide what should happen when fetching fails instead of asserting
// @ts-ignore
this.promisedMiddlewareMatchers = fetch(
`${this.assetPrefix}/_next/static/${this.buildId}/${DEV_MIDDLEWARE_MANIFEST}`,
`${this.assetPrefix}/_next/static/${this.buildId}/${DEV_CLIENT_MIDDLEWARE_MANIFEST}`,
{ credentials: 'same-origin' }
)
.then((res) => res.json())
Expand Down
14 changes: 9 additions & 5 deletions packages/next/src/server/dev/hot-reloader-turbopack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,8 @@ export async function createHotReloaderTurbopack(
currentEntryIssues,
manifestLoader,
nextConfig: opts.nextConfig,
rewrites: opts.fsChecker.rewrites,
devRewrites: opts.fsChecker.rewrites,
productionRewrites: undefined,
logErrors: true,

dev: {
Expand Down Expand Up @@ -800,7 +801,8 @@ export async function createHotReloaderTurbopack(
currentEntryIssues,
entrypoints: currentEntrypoints,
manifestLoader,
rewrites: opts.fsChecker.rewrites,
devRewrites: opts.fsChecker.rewrites,
productionRewrites: undefined,
logErrors: true,

hooks: {
Expand Down Expand Up @@ -861,7 +863,8 @@ export async function createHotReloaderTurbopack(
entrypoints: currentEntrypoints,
manifestLoader,
readyIds,
rewrites: opts.fsChecker.rewrites,
devRewrites: opts.fsChecker.rewrites,
productionRewrites: undefined,
logErrors: true,

hooks: {
Expand All @@ -887,8 +890,9 @@ export async function createHotReloaderTurbopack(
// Write empty manifests
await currentEntriesHandling
await manifestLoader.writeManifests({
rewrites: opts.fsChecker.rewrites,
pageEntrypoints: currentEntrypoints.page,
devRewrites: opts.fsChecker.rewrites,
productionRewrites: undefined,
entrypoints: currentEntrypoints,
})

async function handleProjectUpdates() {
Expand Down
Loading

0 comments on commit 92b3627

Please sign in to comment.