Unverified Commit 235b3bef authored by Fabio Benedetti's avatar Fabio Benedetti Committed by GitHub

fix(client-routing): page render (#13305)

Fixes https://github.com/zeit/next.js/issues/12935
parent 7bd52b8d
...@@ -290,7 +290,8 @@ const nextServerlessLoader: loader.Loader = function () { ...@@ -290,7 +290,8 @@ const nextServerlessLoader: loader.Loader = function () {
{ {
Component, Component,
pageConfig: config, pageConfig: config,
nextExport: fromExport nextExport: fromExport,
isDataReq: _nextData,
}, },
options, options,
) )
......
...@@ -1049,6 +1049,7 @@ export default class Server { ...@@ -1049,6 +1049,7 @@ export default class Server {
const renderOpts: RenderOpts = { const renderOpts: RenderOpts = {
...components, ...components,
...opts, ...opts,
isDataReq,
} }
renderResult = await renderToHTML(req, res, pathname, query, renderOpts) renderResult = await renderToHTML(req, res, pathname, query, renderOpts)
......
...@@ -666,7 +666,7 @@ export async function renderToHTML( ...@@ -666,7 +666,7 @@ export async function renderToHTML(
// We only need to do this if we want to support calling // We only need to do this if we want to support calling
// _app's getInitialProps for getServerSideProps if not this can be removed // _app's getInitialProps for getServerSideProps if not this can be removed
if (isDataReq) return props if (isDataReq && !isSSG) return props
// We don't call getStaticProps or getServerSideProps while generating // We don't call getStaticProps or getServerSideProps while generating
// the fallback so make sure to set pageProps to an empty object // the fallback so make sure to set pageProps to an empty object
......
import Link from 'next/link' import Link from 'next/link'
export async function getServerSideProps() { export async function getServerSideProps({ req }) {
return { return {
props: { props: {
url: req.url,
world: 'world', world: 'world',
time: new Date().getTime(), time: new Date().getTime(),
}, },
} }
} }
const Page = ({ world, time }) => { const Page = ({ world, time, url }) => {
if (typeof window === 'undefined') {
if (url.startsWith('/_next/data/')) {
throw new Error('invalid render for data request')
}
}
return ( return (
<> <>
<p>hello {world}</p> <p>hello {world}</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