Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure minimal mode SSR 404 handling is correct #23996

Merged
merged 1 commit into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/next/next-server/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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\//)))
Expand Down
13 changes: 13 additions & 0 deletions test/integration/required-server-files-ssr-404/lib/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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)
}
12 changes: 12 additions & 0 deletions test/integration/required-server-files-ssr-404/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
// ensure incorrect target is overridden by env
target: 'serverless',
rewrites() {
return [
{
source: '/some-catch-all/:path*',
destination: '/',
},
]
},
}
3 changes: 3 additions & 0 deletions test/integration/required-server-files-ssr-404/pages/404.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function NotFound() {
return 'custom 404'
}
18 changes: 18 additions & 0 deletions test/integration/required-server-files-ssr-404/pages/[slug].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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>
}
17 changes: 17 additions & 0 deletions test/integration/required-server-files-ssr-404/pages/_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default (req, res) => {
console.log(req.url, 'query', req.query)
res.json({
url: req.url,
query: req.query,
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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>
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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>
</>
)
}
14 changes: 14 additions & 0 deletions test/integration/required-server-files-ssr-404/pages/errors/gip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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>
</>
)
}
28 changes: 28 additions & 0 deletions test/integration/required-server-files-ssr-404/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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>
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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>
}
Loading