Unverified Commit ec62ea61 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Ensure minimal mode SSR 404 handling is correct (#23996)

parent f02363e0
......@@ -1288,6 +1288,7 @@ export default class Server {
// we don't modify the URL for _next/data request but still
// call render so we special case this to prevent an infinite loop
if (
!this.minimalMode &&
!query._nextDataReq &&
(url.match(/^\/_next\//) ||
(this.hasStaticDir && url.match(/^\/static\//)))
......
let curConfig
const idk = Math.random()
export default () => {
console.log('returning config', idk, curConfig)
return curConfig
}
export function setConfig(configValue) {
curConfig = configValue
console.log('set config', idk, configValue)
}
module.exports = {
// ensure incorrect target is overridden by env
target: 'serverless',
rewrites() {
return [
{
source: '/some-catch-all/:path*',
destination: '/',
},
]
},
}
export default function NotFound() {
return 'custom 404'
}
export const getStaticProps = () => {
return {
props: {
hello: 'world',
},
}
}
export const getStaticPaths = () => {
return {
paths: [],
fallback: true,
}
}
export default function Page(props) {
return <p id="slug-page">[slug] page</p>
}
import App from 'next/app'
import { setConfig } from '../lib/config'
setConfig({ hello: 'world' })
function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}
MyApp.getInitialProps = async (appContext) => {
// calls page's `getInitialProps` and fills `appProps.pageProps`
const appProps = await App.getInitialProps(appContext)
return { ...appProps }
}
export default MyApp
export default (req, res) => {
console.log(req.url, 'query', req.query)
res.json({
url: req.url,
query: req.query,
})
}
import { useRouter } from 'next/router'
export const getStaticProps = ({ params }) => {
return {
props: {
hello: 'world',
params: params || null,
random: Math.random(),
},
}
}
export const getStaticPaths = () => {
return {
paths: ['/catch-all/hello'],
fallback: true,
}
}
export default function Page(props) {
const router = useRouter()
return (
<>
<p id="catch-all">optional catch-all page</p>
<p id="router">{JSON.stringify(router)}</p>
<p id="props">{JSON.stringify(props)}</p>
</>
)
}
import { useRouter } from 'next/router'
export const getServerSideProps = ({ params }) => {
return {
props: {
hello: 'world',
slug: params.slug,
random: Math.random(),
},
}
}
export default function Page(props) {
const router = useRouter()
return (
<>
<p id="dynamic">dynamic page</p>
<p id="slug">{props.slug}</p>
<p id="router">{JSON.stringify(router)}</p>
<p id="props">{JSON.stringify(props)}</p>
</>
)
}
function Page(props) {
return <p>here comes an error</p>
}
Page.getInitialProps = ({ query }) => {
if (query.crash) {
throw new Error('gip hit an oops')
}
return {
hello: 'world',
}
}
export default Page
import { useRouter } from 'next/router'
function Page(props) {
if (useRouter().isFallback) {
return <p>loading...</p>
}
return <p>here comes an error</p>
}
export const getStaticPaths = () => {
return {
paths: [],
fallback: true,
}
}
export const getStaticProps = ({ params }) => {
if (params.post === 'crash') {
throw new Error('gsp hit an oops')
}
return {
props: {
hello: 'world',
},
}
}
export default Page
function Page(props) {
return <p>here comes an error</p>
}
export const getServerSideProps = ({ query }) => {
if (query.crash) {
throw new Error('gssp hit an oops')
}
return {
props: {
hello: 'world',
},
}
}
export default Page
import { useRouter } from 'next/router'
export const getStaticProps = ({ params }) => {
return {
props: {
hello: 'world',
slug: params.slug,
random: Math.random(),
},
}
}
export const getStaticPaths = () => {
return {
paths: ['/fallback/first'],
fallback: true,
}
}
export default function Page(props) {
const router = useRouter()
return (
<>
<p id="fallback">fallback page</p>
<p id="slug">{props.slug}</p>
<p id="router">{JSON.stringify(router)}</p>
<p id="props">{JSON.stringify(props)}</p>
</>
)
}
import { useRouter } from 'next/router'
import getConfig from '../lib/config'
const localConfig = getConfig()
if (localConfig.hello !== 'world') {
throw new Error('oof import order is wrong, _app comes first')
}
export const getServerSideProps = ({ req }) => {
return {
props: {
hello: 'world',
random: Math.random(),
},
}
}
export default function Page(props) {
const router = useRouter()
return (
<>
<p id="index">index page</p>
<p id="router">{JSON.stringify(router)}</p>
<p id="props">{JSON.stringify(props)}</p>
</>
)
}
export const getStaticProps = ({ params }) => {
return {
props: {
random: Math.random(),
params: params || null,
},
revalidate: 1,
}
}
export const getStaticPaths = () => {
return {
paths: [],
fallback: true,
}
}
export default function Page(props) {
return <p id="props">{JSON.stringify(props)}</p>
}
export const getServerSideProps = ({ query, params }) => {
return {
props: {
random: Math.random(),
query: query,
params: params || null,
},
}
}
export default function Page(props) {
return <p id="props">{JSON.stringify(props)}</p>
}
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