Skip to content

Commit

Permalink
Merge branch 'canary' into shu/kx67
Browse files Browse the repository at this point in the history
  • Loading branch information
shuding committed Sep 26, 2022
2 parents 6c3c839 + 7ccc95c commit 8da3eca
Show file tree
Hide file tree
Showing 23 changed files with 554 additions and 376 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Expand Up @@ -16,5 +16,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "12.3.2-canary.7"
"version": "12.3.2-canary.8"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "12.3.2-canary.7",
"version": "12.3.2-canary.8",
"keywords": [
"react",
"next",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-next/package.json
@@ -1,6 +1,6 @@
{
"name": "eslint-config-next",
"version": "12.3.2-canary.7",
"version": "12.3.2-canary.8",
"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": "12.3.2-canary.7",
"@next/eslint-plugin-next": "12.3.2-canary.8",
"@rushstack/eslint-patch": "^1.1.3",
"@typescript-eslint/parser": "^5.21.0",
"eslint-import-resolver-node": "^0.3.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/eslint-plugin-next",
"version": "12.3.2-canary.7",
"version": "12.3.2-canary.8",
"description": "ESLint plugin for NextJS.",
"main": "lib/index.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/font/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/font",
"version": "12.3.2-canary.7",
"version": "12.3.2-canary.8",
"repository": {
"url": "vercel/next.js",
"directory": "packages/font"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "12.3.2-canary.7",
"version": "12.3.2-canary.8",
"main": "index.js",
"types": "index.d.ts",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-codemod/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/codemod",
"version": "12.3.2-canary.7",
"version": "12.3.2-canary.8",
"license": "MIT",
"dependencies": {
"chalk": "4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-env/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/env",
"version": "12.3.2-canary.7",
"version": "12.3.2-canary.8",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "12.3.2-canary.7",
"version": "12.3.2-canary.8",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-storybook/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-storybook",
"version": "12.3.2-canary.7",
"version": "12.3.2-canary.8",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-storybook"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-module/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-module",
"version": "12.3.2-canary.7",
"version": "12.3.2-canary.8",
"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
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "12.3.2-canary.7",
"version": "12.3.2-canary.8",
"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
@@ -1,6 +1,6 @@
{
"name": "@next/swc",
"version": "12.3.2-canary.7",
"version": "12.3.2-canary.8",
"private": true,
"scripts": {
"build-native": "napi build --platform -p next-swc-napi --cargo-name next_swc_napi native --features plugin",
Expand Down
7 changes: 4 additions & 3 deletions packages/next/client/components/layout-router.client.tsx
Expand Up @@ -309,8 +309,9 @@ class RedirectErrorBoundary extends React.Component<
}

static getDerivedStateFromError(error: any) {
if (error.digest === 'NEXT_REDIRECT') {
return { redirect: error.url }
if (error.digest?.startsWith('NEXT_REDIRECT')) {
const url = error.digest.split(';')[1]
return { redirect: url }
}
// Re-throw if error is not for 404
throw error
Expand Down Expand Up @@ -354,7 +355,7 @@ class NotFoundErrorBoundary extends React.Component<
}

static getDerivedStateFromError(error: any) {
if (error.code === 'NEXT_NOT_FOUND') {
if (error.digest === 'NEXT_NOT_FOUND') {
return { notFoundTriggered: true }
}
// Re-throw if error is not for 404
Expand Down
6 changes: 3 additions & 3 deletions packages/next/client/components/not-found.ts
Expand Up @@ -2,7 +2,7 @@ export const NOT_FOUND_ERROR_CODE = 'NEXT_NOT_FOUND'

export function notFound() {
// eslint-disable-next-line no-throw-literal
throw {
code: NOT_FOUND_ERROR_CODE,
}
const error = new Error(NOT_FOUND_ERROR_CODE)
;(error as any).digest = NOT_FOUND_ERROR_CODE
throw error
}
3 changes: 1 addition & 2 deletions packages/next/client/components/redirect.ts
Expand Up @@ -3,7 +3,6 @@ export const REDIRECT_ERROR_CODE = 'NEXT_REDIRECT'
export function redirect(url: string) {
// eslint-disable-next-line no-throw-literal
const error = new Error(REDIRECT_ERROR_CODE)
;(error as any).url = url
;(error as any).digest = REDIRECT_ERROR_CODE
;(error as any).digest = REDIRECT_ERROR_CODE + ';' + url
throw error
}
4 changes: 3 additions & 1 deletion packages/next/export/worker.ts
Expand Up @@ -30,6 +30,7 @@ import { addRequestMeta } from '../server/request-meta'
import { normalizeAppPath } from '../shared/lib/router/utils/app-paths'
import { REDIRECT_ERROR_CODE } from '../client/components/redirect'
import { DYNAMIC_ERROR_CODE } from '../client/components/hooks-server-context'
import { NOT_FOUND_ERROR_CODE } from '../client/components/not-found'

loadRequireHook()
const envConfig = require('../shared/lib/runtime-config')
Expand Down Expand Up @@ -419,7 +420,8 @@ export default async function exportPage({
} catch (err: any) {
if (
err.digest !== DYNAMIC_ERROR_CODE &&
err.digest !== REDIRECT_ERROR_CODE
err.digest !== NOT_FOUND_ERROR_CODE &&
!err.digest?.startsWith(REDIRECT_ERROR_CODE)
) {
throw err
}
Expand Down
14 changes: 7 additions & 7 deletions packages/next/package.json
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "12.3.2-canary.7",
"version": "12.3.2-canary.8",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down Expand Up @@ -68,7 +68,7 @@
]
},
"dependencies": {
"@next/env": "12.3.2-canary.7",
"@next/env": "12.3.2-canary.8",
"@swc/helpers": "0.4.11",
"caniuse-lite": "^1.0.30001406",
"postcss": "8.4.14",
Expand Down Expand Up @@ -119,11 +119,11 @@
"@hapi/accept": "5.0.2",
"@napi-rs/cli": "2.7.0",
"@napi-rs/triples": "1.1.0",
"@next/polyfill-module": "12.3.2-canary.7",
"@next/polyfill-nomodule": "12.3.2-canary.7",
"@next/react-dev-overlay": "12.3.2-canary.7",
"@next/react-refresh-utils": "12.3.2-canary.7",
"@next/swc": "12.3.2-canary.7",
"@next/polyfill-module": "12.3.2-canary.8",
"@next/polyfill-nomodule": "12.3.2-canary.8",
"@next/react-dev-overlay": "12.3.2-canary.8",
"@next/react-refresh-utils": "12.3.2-canary.8",
"@next/swc": "12.3.2-canary.8",
"@segment/ajv-human-errors": "2.1.2",
"@taskr/clear": "1.1.0",
"@taskr/esnext": "1.1.0",
Expand Down
24 changes: 4 additions & 20 deletions packages/next/server/app-render.tsx
Expand Up @@ -31,6 +31,7 @@ import type { ComponentsType } from '../build/webpack/loaders/next-app-loader'
import { REDIRECT_ERROR_CODE } from '../client/components/redirect'
import { NextCookies } from './web/spec-extension/cookies'
import { DYNAMIC_ERROR_CODE } from '../client/components/hooks-server-context'
import { NOT_FOUND_ERROR_CODE } from '../client/components/not-found'

const INTERNAL_HEADERS_INSTANCE = Symbol('internal for headers readonly')

Expand Down Expand Up @@ -173,7 +174,8 @@ function createErrorHandler(
if (
// TODO-APP: Handle redirect throw
err.digest !== DYNAMIC_ERROR_CODE &&
err.digest !== REDIRECT_ERROR_CODE
err.digest !== NOT_FOUND_ERROR_CODE &&
!err.digest?.startsWith(REDIRECT_ERROR_CODE)
) {
// Used for debugging error source
// console.error(_source, err)
Expand Down Expand Up @@ -1299,10 +1301,6 @@ export async function renderToHTMLOrFlight(
flushEffectsToHead: true,
})
} catch (err: any) {
if (err.digest === REDIRECT_ERROR_CODE) {
throw err
}

// TODO-APP: show error overlay in development. `element` should probably be wrapped in AppRouter for this case.
const renderStream = await renderToInitialStream({
ReactDOMServer,
Expand Down Expand Up @@ -1358,21 +1356,7 @@ export async function renderToHTMLOrFlight(
return new RenderResult(staticHtml)
}

try {
return new RenderResult(await bodyResult())
} catch (err: any) {
if (err.digest === REDIRECT_ERROR_CODE) {
;(renderOpts as any).pageData = {
pageProps: {
__N_REDIRECT: err.url,
__N_REDIRECT_STATUS: 307,
},
}
;(renderOpts as any).isRedirect = true
return RenderResult.fromStatic('')
}
throw err
}
return new RenderResult(await bodyResult())
}

const initialStaticGenerationStore = {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dev-overlay/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/react-dev-overlay",
"version": "12.3.2-canary.7",
"version": "12.3.2-canary.8",
"description": "A development-only overlay for developing React applications.",
"repository": {
"url": "vercel/next.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-refresh-utils/package.json
@@ -1,6 +1,6 @@
{
"name": "@next/react-refresh-utils",
"version": "12.3.2-canary.7",
"version": "12.3.2-canary.8",
"description": "An experimental package providing utilities for React Refresh.",
"repository": {
"url": "vercel/next.js",
Expand Down

0 comments on commit 8da3eca

Please sign in to comment.