Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: hard-navigate when preflight request fails (#35145)
fixes #34199 Also fixes response code to return `500` when showing error page of preflight request failure on dev mode ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md`
- Loading branch information
Showing
6 changed files
with
72 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
test/integration/middleware/core/pages/errors/_middleware.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { NextResponse } from 'next/server' | ||
|
||
export async function middleware(request) { | ||
const url = request.nextUrl | ||
|
||
if ( | ||
url.pathname === '/errors/throw-on-preflight' && | ||
request.headers.has('x-middleware-preflight') | ||
) { | ||
throw new Error('test error') | ||
} | ||
|
||
return NextResponse.next() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Link from 'next/link' | ||
|
||
export default function Errors() { | ||
return ( | ||
<div> | ||
<Link href="/errors/throw-on-preflight?message=refreshed"> | ||
<a id="throw-on-preflight">Throw on preflight</a> | ||
</Link> | ||
</div> | ||
) | ||
} |
12 changes: 12 additions & 0 deletions
12
test/integration/middleware/core/pages/errors/throw-on-preflight.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export default function ThrowOnPreflight({ message }) { | ||
return ( | ||
<div> | ||
<h1 className="title">Throw on preflight request</h1> | ||
<p className={message}>{message}</p> | ||
</div> | ||
) | ||
} | ||
|
||
export const getServerSideProps = ({ query }) => ({ | ||
props: { message: query.message || '' }, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters