Unverified Commit a5f30e68 authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

pages bugfix: prevent cancellation errors from being logged (#69766)

When another data request is received by the pages router, a
cancellation error is thrown and is meant to be caught by `change` to
signal that the navigation request was aborted. However we were logging
the error right before we handled the logic to properly bubble the error
up. This meant that it was logging an exception to the console that
wasn't actionable.

Fixes #40554
Closes NEXT-3731
parent e3294157
...@@ -1893,8 +1893,6 @@ export default class Router implements BaseRouter { ...@@ -1893,8 +1893,6 @@ export default class Router implements BaseRouter {
routeProps: RouteProperties, routeProps: RouteProperties,
loadErrorFail?: boolean loadErrorFail?: boolean
): Promise<CompletePrivateRouteInfo> { ): Promise<CompletePrivateRouteInfo> {
console.error(err)
if (err.cancelled) { if (err.cancelled) {
// bubble up cancellation errors // bubble up cancellation errors
throw err throw err
...@@ -1919,6 +1917,8 @@ export default class Router implements BaseRouter { ...@@ -1919,6 +1917,8 @@ export default class Router implements BaseRouter {
throw buildCancellationError() throw buildCancellationError()
} }
console.error(err)
try { try {
let props: Record<string, any> | undefined let props: Record<string, any> | undefined
const { page: Component, styleSheets } = const { page: Component, styleSheets } =
......
...@@ -93,6 +93,8 @@ const Page = ({ world, time, url }) => { ...@@ -93,6 +93,8 @@ const Page = ({ world, time, url }) => {
<Link href="/something?another=thing" id="something-query"> <Link href="/something?another=thing" id="something-query">
to something?another=thing to something?another=thing
</Link> </Link>
<br />
<Link href="/redirect-page">to redirect-page</Link>
</> </>
) )
} }
......
import Router from 'next/router'
const RedirectPage = () => {
return <h1>Redirect Page</h1>
}
RedirectPage.getInitialProps = (context) => {
const { req, res } = context
if (req) {
res.writeHead(302, { Location: '/normal' })
res.end()
} else {
Router.push('/normal')
}
return {}
}
export default RedirectPage
...@@ -5,6 +5,7 @@ import { createNext, FileRef } from 'e2e-utils' ...@@ -5,6 +5,7 @@ import { createNext, FileRef } from 'e2e-utils'
import escapeRegex from 'escape-string-regexp' import escapeRegex from 'escape-string-regexp'
import { import {
check, check,
retry,
fetchViaHTTP, fetchViaHTTP,
getBrowserBodyText, getBrowserBodyText,
getRedboxHeader, getRedboxHeader,
...@@ -669,6 +670,21 @@ const runTests = (isDev = false, isDeploy = false) => { ...@@ -669,6 +670,21 @@ const runTests = (isDev = false, isDeploy = false) => {
expect(curRandom).toBe(initialRandom + '') expect(curRandom).toBe(initialRandom + '')
}) })
it('should not trigger an error when a data request is cancelled due to another navigation', async () => {
const browser = await webdriver(next.url, ' /')
await browser.elementByCss("[href='/redirect-page']").click()
// redirect-page will redirect to /normal
await retry(async () => {
expect(await getBrowserBodyText(browser)).toInclude('a normal page')
})
// there should not be any console errors
const logs = await browser.log()
expect(logs.filter((log) => log.source === 'error').length).toBe(0)
})
it('should dedupe server data requests', async () => { it('should dedupe server data requests', async () => {
const browser = await webdriver(next.url, '/') const browser = await webdriver(next.url, '/')
await waitFor(2000) await waitFor(2000)
...@@ -851,6 +867,7 @@ describe('getServerSideProps', () => { ...@@ -851,6 +867,7 @@ describe('getServerSideProps', () => {
next = await createNext({ next = await createNext({
files: { files: {
pages: new FileRef(join(appDir, 'pages')), pages: new FileRef(join(appDir, 'pages')),
public: new FileRef(join(appDir, 'public')),
'world.txt': new FileRef(join(appDir, 'world.txt')), 'world.txt': new FileRef(join(appDir, 'world.txt')),
'next.config.js': new FileRef(join(appDir, 'next.config.js')), 'next.config.js': new FileRef(join(appDir, 'next.config.js')),
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment