-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix middleware fallback: false case (#69799)
This ensures we properly set the request meta during our middleware invoke so that the `NoFallbackError` bubbling is handled properly. Without these fields set we bubble the error unexpectedly causing an unexpected 500 instead of a 404. x-ref: #66987 Closes: #69428
- Loading branch information
Showing
3 changed files
with
65 additions
and
0 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
53 changes: 53 additions & 0 deletions
53
test/e2e/middleware-general/app/pages/ssg-fallback-false/[slug].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,53 @@ | ||
import { useRouter } from 'next/router' | ||
import { useEffect } from 'react' | ||
import { useState } from 'react' | ||
|
||
export default function Page(props) { | ||
const router = useRouter() | ||
const [asPath, setAsPath] = useState( | ||
router.isReady ? router.asPath : router.href | ||
) | ||
|
||
if (!props.params) { | ||
console.error('props', props) | ||
throw new Error('missing props!!!') | ||
} | ||
|
||
useEffect(() => { | ||
if (router.isReady) { | ||
setAsPath(router.asPath) | ||
} | ||
}, [router.asPath, router.isReady]) | ||
|
||
return ( | ||
<> | ||
<p id="ssg">/blog/[slug]</p> | ||
<p id="query">{JSON.stringify(router.query)}</p> | ||
<p id="pathname">{router.pathname}</p> | ||
<p id="as-path">{asPath}</p> | ||
<p id="props">{JSON.stringify(props)}</p> | ||
</> | ||
) | ||
} | ||
|
||
export function getStaticProps({ params }) { | ||
if (params.slug.includes('not-found')) { | ||
return { | ||
notFound: true, | ||
} | ||
} | ||
|
||
return { | ||
props: { | ||
now: Date.now(), | ||
params, | ||
}, | ||
} | ||
} | ||
|
||
export function getStaticPaths() { | ||
return { | ||
paths: ['/ssg-fallback-false/first', '/ssg-fallback-false/hello'], | ||
fallback: false, | ||
} | ||
} |
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