Dedupe double logged server errors (#67464)
### What Only call error log in SSR renderer, instead of calling it in all RSC and SSR renderers. Fixes #67352 Close NEXT-3579 ### Why The RSC rendered generated result will be rendered by SSR renderer again, at there we can get the actual error. So when there's a RSC error happening, only logging once in SSR rendering layer is enough.
This commit is contained in:
parent
bda92a1be5
commit
1268f99e9e
8 changed files with 86 additions and 1 deletions
|
@ -107,7 +107,13 @@ export function createErrorHandler({
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!silenceLogger) {
|
if (
|
||||||
|
(!silenceLogger &&
|
||||||
|
// Only log the error from SSR rendering errors and flight data render errors,
|
||||||
|
// as RSC renderer error will still be pipped into SSR renderer as well.
|
||||||
|
source === 'html') ||
|
||||||
|
source === 'flightData'
|
||||||
|
) {
|
||||||
if (errorLogger) {
|
if (errorLogger) {
|
||||||
errorLogger(err).catch(() => {})
|
errorLogger(err).catch(() => {})
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
'use client'
|
||||||
|
|
||||||
|
import { ErrorComponent } from '../../component'
|
||||||
|
|
||||||
|
export default () => <ErrorComponent name="client-edge" />
|
||||||
|
|
||||||
|
export const runtime = 'edge'
|
|
@ -0,0 +1,7 @@
|
||||||
|
'use client'
|
||||||
|
|
||||||
|
import { ErrorComponent } from '../component'
|
||||||
|
|
||||||
|
export default () => <ErrorComponent name="client-node" />
|
||||||
|
|
||||||
|
export const dynamic = 'force-dynamic'
|
8
test/e2e/app-dir/dedupe-rsc-error-log/app/component.tsx
Normal file
8
test/e2e/app-dir/dedupe-rsc-error-log/app/component.tsx
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
async function getData(name: string) {
|
||||||
|
throw new Error('Custom error:' + name)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function ErrorComponent({ name }: { name: string }) {
|
||||||
|
await getData(name)
|
||||||
|
return null
|
||||||
|
}
|
11
test/e2e/app-dir/dedupe-rsc-error-log/app/layout.tsx
Normal file
11
test/e2e/app-dir/dedupe-rsc-error-log/app/layout.tsx
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import { ReactNode } from 'react'
|
||||||
|
|
||||||
|
export default function Root({ children }: { children: ReactNode }) {
|
||||||
|
return (
|
||||||
|
<html>
|
||||||
|
<body>{children}</body>
|
||||||
|
</html>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const dynamic = 'force-dynamic'
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { ErrorComponent } from '../../component'
|
||||||
|
|
||||||
|
export default () => <ErrorComponent name="server-edge" />
|
||||||
|
|
||||||
|
export const runtime = 'edge'
|
|
@ -0,0 +1,5 @@
|
||||||
|
import { ErrorComponent } from '../component'
|
||||||
|
|
||||||
|
export default () => <ErrorComponent name="server-node" />
|
||||||
|
|
||||||
|
export const dynamic = 'force-dynamic'
|
|
@ -0,0 +1,36 @@
|
||||||
|
import { nextTestSetup } from 'e2e-utils'
|
||||||
|
import { retry } from 'next-test-utils'
|
||||||
|
|
||||||
|
async function expectContainOnce(next: any, search: string) {
|
||||||
|
// Ensure the search string is found once
|
||||||
|
await retry(() => {
|
||||||
|
const parts = next.cliOutput.split(search)
|
||||||
|
expect(parts.length).toBe(2)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('dedupe-rsc-error-log', () => {
|
||||||
|
const { next } = nextTestSetup({
|
||||||
|
files: __dirname,
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should only log RSC error once for nodejs runtime', async () => {
|
||||||
|
await next.fetch('/server')
|
||||||
|
await expectContainOnce(next, 'Custom error:server-node')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should only log RSC error once for edge runtime', async () => {
|
||||||
|
await next.fetch('/server/edge')
|
||||||
|
await expectContainOnce(next, 'Custom error:server-edge')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should only log SSR error once for nodejs runtime', async () => {
|
||||||
|
await next.fetch('/client')
|
||||||
|
await expectContainOnce(next, 'Custom error:client-node')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should only log SSR error once for edge runtime', async () => {
|
||||||
|
await next.fetch('/client/edge')
|
||||||
|
await expectContainOnce(next, 'Custom error:client-edge')
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in a new issue