Unverified Commit 4ef1cd4e authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Add identifier to NEXT_DATA for gs(s)p (#10812)

* Add identifier to NEXT_DATA for gs(s)p

* Apply suggestions from code review
Co-Authored-By: 's avatarJoe Haddad <joe.haddad@zeit.co>

* fix lint

* apply lint fix
Co-authored-by: 's avatarJoe Haddad <timer150@gmail.com>
parent 3ca022a8
......@@ -78,6 +78,8 @@ export type NEXT_DATA = {
isFallback?: boolean
dynamicIds?: string[]
err?: Error & { statusCode?: number }
gsp?: boolean
gssp?: boolean
}
/**
......
......@@ -181,6 +181,8 @@ function renderDocument(
htmlProps,
bodyTags,
headTags,
gsp,
gssp,
}: RenderOpts & {
props: any
docProps: DocumentInitialProps
......@@ -201,6 +203,8 @@ function renderDocument(
bodyTags: any
headTags: any
isFallback?: boolean
gsp?: boolean
gssp?: boolean
}
): string {
return (
......@@ -221,6 +225,8 @@ function renderDocument(
dynamicIds:
dynamicImportsIds.length === 0 ? undefined : dynamicImportsIds,
err: err ? serializeError(dev, err) : undefined, // Error if one happened, otherwise don't sent in the resulting HTML
gsp, // whether the page is getStaticProps
gssp, // whether the page is getServerSideProps
},
dangerousAsPath,
canonicalBase,
......@@ -680,6 +686,8 @@ export async function renderToHTML(
files,
lowPriorityFiles,
polyfillFiles,
gsp: !!getStaticProps ? true : undefined,
gssp: !!getServerSideProps ? true : undefined,
})
if (inAmpMode && html) {
......
......@@ -191,6 +191,18 @@ const runTests = (dev = false) => {
expect(html).toMatch(/Post:.*?post-1/)
})
it('should have gssp in __NEXT_DATA__', async () => {
const html = await renderViaHTTP(appPort, '/')
const $ = cheerio.load(html)
expect(JSON.parse($('#__NEXT_DATA__').text()).gssp).toBe(true)
})
it('should not have gssp in __NEXT_DATA__ for non-GSSP page', async () => {
const html = await renderViaHTTP(appPort, '/normal')
const $ = cheerio.load(html)
expect('gssp' in JSON.parse($('#__NEXT_DATA__').text())).toBe(false)
})
it('should supply query values SSR', async () => {
const html = await renderViaHTTP(appPort, '/blog/post-1?hello=world')
const $ = cheerio.load(html)
......
......@@ -282,6 +282,18 @@ const runTests = (dev = false, looseMode = false) => {
expect(html).toMatch(/Post:.*?post-1/)
})
it('should have gsp in __NEXT_DATA__', async () => {
const html = await renderViaHTTP(appPort, '/')
const $ = cheerio.load(html)
expect(JSON.parse($('#__NEXT_DATA__').text()).gsp).toBe(true)
})
it('should not have gsp in __NEXT_DATA__ for non-GSP page', async () => {
const html = await renderViaHTTP(appPort, '/normal')
const $ = cheerio.load(html)
expect('gsp' in JSON.parse($('#__NEXT_DATA__').text())).toBe(false)
})
it('should not supply query values to params or useRouter non-dynamic page SSR', async () => {
const html = await renderViaHTTP(appPort, '/something?hello=world')
const $ = cheerio.load(html)
......
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