Skip to content

Commit

Permalink
Merge branch 'canary' into 07-12-render_source
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Jul 12, 2024
2 parents c9a07d4 + 38a6b01 commit b68b59d
Show file tree
Hide file tree
Showing 26 changed files with 255 additions and 47 deletions.
4 changes: 2 additions & 2 deletions packages/next-swc/crates/next-api/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,8 @@ impl Project {
self.project_path(),
node_root,
node_root,
node_root.join("chunks".into()),
node_root.join("assets".into()),
node_root.join("build/chunks".into()),
node_root.join("build/assets".into()),
node_build_environment(),
next_mode.runtime_type(),
)
Expand Down
9 changes: 6 additions & 3 deletions packages/next/src/client/components/is-next-router-error.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { isNotFoundError } from './not-found'
import { isRedirectError } from './redirect'

/**
* Returns true if the error is a navigation signal error. These errors are
* thrown by user code to perform navigation operations and interrupt the React
* render.
*/
export function isNextRouterError(error: any): boolean {
return (
error && error.digest && (isRedirectError(error) || isNotFoundError(error))
)
return isRedirectError(error) || isNotFoundError(error)
}
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ function processMessage(
router.fastRefresh()
dispatcher.onRefresh()
})
reportHmrLatency(sendMessage, [])

if (process.env.__NEXT_TEST_MODE) {
if (self.__NEXT_HMR_CB) {
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/export/helpers/is-dynamic-usage-error.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { isDynamicServerError } from '../../client/components/hooks-server-context'
import { isBailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr'
import { isNavigationSignalError } from './is-navigation-signal-error'
import { isNextRouterError } from '../../client/components/is-next-router-error'

export const isDynamicUsageError = (err: unknown) =>
isDynamicServerError(err) ||
isBailoutToCSRError(err) ||
isNavigationSignalError(err)
isNextRouterError(err)
10 changes: 0 additions & 10 deletions packages/next/src/export/helpers/is-navigation-signal-error.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/next/src/server/app-render/create-error-handler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { formatServerError } from '../../lib/format-server-error'
import { SpanStatusCode, getTracer } from '../lib/trace/tracer'
import { isAbortError } from '../pipe-readable'
import { isBailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr'
import { isNavigationSignalError } from '../../export/helpers/is-navigation-signal-error'
import { isDynamicServerError } from '../../client/components/hooks-server-context'
import { isNextRouterError } from '../../client/components/is-next-router-error'

declare global {
var __next_log_error__: undefined | ((err: unknown) => void)
Expand Down Expand Up @@ -56,7 +56,7 @@ export function createErrorHandler({
if (isBailoutToCSRError(err)) return err.digest

// If this is a navigation error, we don't need to log the error.
if (isNavigationSignalError(err)) return err.digest
if (isNextRouterError(err)) return err.digest

err = getErrorByRenderSource(err)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ describe('create-env-definitions', () => {
declare global {
namespace NodeJS {
interface ProcessEnv {
FROM_DEV_ENV_LOCAL: readonly string
FROM_ENV_LOCAL: readonly string
FROM_ENV: readonly string
FROM_NEXT_CONFIG: readonly string
FROM_DEV_ENV_LOCAL: string
FROM_ENV_LOCAL: string
FROM_ENV: string
FROM_NEXT_CONFIG: string
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export async function createEnvDefinitions({
env: Env
}) {
const envKeysStr = Object.keys(env)
.map((key) => ` ${key}: readonly string`)
.map((key) => ` ${key}: string`)
.join('\n')

const definitionStr = `// Type definitions for Next.js environment variables
Expand Down
24 changes: 12 additions & 12 deletions test/development/app-dir/typed-env/typed-env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ describe('typed-env', () => {
},

// should not include from production-specific env
// e.g. FROM_PROD_ENV_LOCAL: readonly string
// e.g. FROM_PROD_ENV_LOCAL: string
`// Type definitions for Next.js environment variables
declare global {
namespace NodeJS {
interface ProcessEnv {
FROM_DEV_ENV_LOCAL: readonly string
FROM_ENV_LOCAL: readonly string
FROM_ENV: readonly string
FROM_NEXT_CONFIG: readonly string
FROM_DEV_ENV_LOCAL: string
FROM_ENV_LOCAL: string
FROM_ENV: string
FROM_NEXT_CONFIG: string
}
}
}
Expand All @@ -35,15 +35,15 @@ export {}`
return await next.readFile('.next/types/env.d.ts')
},
// env.d.ts is written from original .env
/FROM_ENV: readonly string/
/FROM_ENV: string/
)

// modify .env
await next.patchFile('.env', 'MODIFIED_ENV="MODIFIED_ENV"')

// should not include from original .env
// e.g. FROM_ENV: readonly string
// but have MODIFIED_ENV: readonly string
// e.g. FROM_ENV: string
// but have MODIFIED_ENV: string
await check(
async () => {
return await next.readFile('.next/types/env.d.ts')
Expand All @@ -52,10 +52,10 @@ export {}`
declare global {
namespace NodeJS {
interface ProcessEnv {
FROM_DEV_ENV_LOCAL: readonly string
FROM_ENV_LOCAL: readonly string
MODIFIED_ENV: readonly string
FROM_NEXT_CONFIG: readonly string
FROM_DEV_ENV_LOCAL: string
FROM_ENV_LOCAL: string
MODIFIED_ENV: string
FROM_NEXT_CONFIG: string
}
}
}
Expand Down
59 changes: 49 additions & 10 deletions test/development/app-hmr/hmr.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { nextTestSetup } from 'e2e-utils'
import { check, waitFor } from 'next-test-utils'
import { retry, waitFor } from 'next-test-utils'

const envFile = '.env.development.local'

Expand Down Expand Up @@ -40,11 +40,10 @@ describe(`app-dir-hmr`, () => {

try {
// Should be 404 in a few seconds
await check(async () => {
await retry(async () => {
const body = await browser.elementByCss('body').text()
expect(body).toContain('404')
return 'success'
}, 'success')
})

// The new page should be rendered
const newHTML = await next.render('/folder-renamed')
Expand All @@ -61,11 +60,31 @@ describe(`app-dir-hmr`, () => {
expect(await browser.elementByCss('p').text()).toBe('mac')
await next.patchFile(envFile, 'MY_DEVICE="ipad"')

const logs = await browser.log()
await retry(async () => {
expect(logs).toEqual(
expect.arrayContaining([
expect.objectContaining({
message: '[Fast Refresh] rebuilding',
source: 'log',
}),
])
)
})

try {
await check(async () => {
await retry(async () => {
expect(await browser.elementByCss('p').text()).toBe('ipad')
return 'success'
}, /success/)
})

expect(logs).toEqual(
expect.arrayContaining([
expect.objectContaining({
message: expect.stringContaining('[Fast Refresh] done in'),
source: 'log',
}),
])
)
} finally {
await next.patchFile(envFile, envContent)
}
Expand All @@ -77,11 +96,31 @@ describe(`app-dir-hmr`, () => {
expect(await browser.elementByCss('p').text()).toBe('mac')
await next.patchFile(envFile, 'MY_DEVICE="ipad"')

const logs = await browser.log()
await retry(async () => {
expect(logs).toEqual(
expect.arrayContaining([
expect.objectContaining({
message: '[Fast Refresh] rebuilding',
source: 'log',
}),
])
)
})

try {
await check(async () => {
await retry(async () => {
expect(await browser.elementByCss('p').text()).toBe('ipad')
return 'success'
}, /success/)
})

expect(logs).toEqual(
expect.arrayContaining([
expect.objectContaining({
message: expect.stringContaining('[Fast Refresh] done in'),
source: 'log',
}),
])
)
} finally {
await next.patchFile(envFile, envContent)
}
Expand Down
7 changes: 6 additions & 1 deletion test/e2e/on-request-error/basic/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'

describe('on-request-error - basic', () => {
const { next } = nextTestSetup({
const { next, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
env: {
__NEXT_EXPERIMENTAL_INSTRUMENTATION: '1',
},
})

if (skipped) {
return
}

const outputLogPath = 'output-log.json'

async function getOutputLogJson() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return <p>another</p>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { notFound } from 'next/navigation'

export function GET() {
notFound()
}

export const dynamic = 'force-dynamic'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { redirect } from 'next/navigation'

export function GET() {
redirect('/another')
}

export const dynamic = 'force-dynamic'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default async function Page() {
await fetch('https://example.vercel.sh')
return <p>dynamic page</p>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Component() {
return <p>Component</p>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use client'

import nextDynamic from 'next/dynamic'

const Component = nextDynamic(() => import('./component'))

export default function Page() {
return <Component />
}

export const dynamic = 'force-dynamic'
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use client'

import { notFound } from 'next/navigation'

export default function Page() {
notFound()
}

export const dynamic = 'force-dynamic'
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use client'

import { redirect } from 'next/navigation'

export default function Page() {
redirect('/another')
}

export const dynamic = 'force-dynamic'
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function Layout({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}

export const dynamic = 'force-dynamic'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default async function Page() {
await fetch('https://example.vercel.sh')
return <p>dynamic page</p>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { notFound } from 'next/navigation'

export default function Page() {
notFound()
}

export const dynamic = 'force-dynamic'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { redirect } from 'next/navigation'

export default function Page() {
redirect('/another')
}

export const dynamic = 'force-dynamic'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function onRequestError(err, request, context) {
console.log('[instrumentation]:error', err.message)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
experimental: {
instrumentationHook: true,
},
}
Loading

0 comments on commit b68b59d

Please sign in to comment.