提交 45832e44 编写于 作者: J JJ Kasper 提交者: Joe Haddad

Make sure to parse query values for SSG page after hydration (#9545)

* Make sure to parse query values for SSG page after hydration

* Update to re-use __NEXT_SPR
上级 ca3f881a
...@@ -101,8 +101,9 @@ class Container extends React.Component { ...@@ -101,8 +101,9 @@ class Container extends React.Component {
// If page was exported and has a querystring // If page was exported and has a querystring
// If it's a dynamic route or has a querystring // If it's a dynamic route or has a querystring
if ( if (
data.nextExport && (data.nextExport &&
(isDynamicRoute(router.pathname) || location.search) (isDynamicRoute(router.pathname) || location.search)) ||
(Component.__NEXT_SPR && location.search)
) { ) {
// update query on mount for exported pages // update query on mount for exported pages
router.replace( router.replace(
......
import React from 'react' import React from 'react'
import Link from 'next/link' import Link from 'next/link'
import { useRouter } from 'next/router'
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
export async function unstable_getStaticPaths() { export async function unstable_getStaticPaths() {
...@@ -37,6 +38,7 @@ export default ({ post, time }) => { ...@@ -37,6 +38,7 @@ export default ({ post, time }) => {
<> <>
<p>Post: {post}</p> <p>Post: {post}</p>
<span>time: {time}</span> <span>time: {time}</span>
<div id="query">{JSON.stringify(useRouter().query)}</div>
<Link href="/"> <Link href="/">
<a id="home">to home</a> <a id="home">to home</a>
</Link> </Link>
......
...@@ -213,6 +213,14 @@ const runTests = (dev = false) => { ...@@ -213,6 +213,14 @@ const runTests = (dev = false) => {
expect(text).toMatch(/a normal page/) expect(text).toMatch(/a normal page/)
}) })
it('should parse query values on mount correctly', async () => {
const browser = await webdriver(appPort, '/blog/post-1?another=value')
await waitFor(2000)
const text = await browser.elementByCss('#query').text()
expect(text).toMatch(/another.*?value/)
expect(text).toMatch(/post.*?post-1/)
})
if (dev) { if (dev) {
it('should always call getStaticProps without caching in dev', async () => { it('should always call getStaticProps without caching in dev', async () => {
const initialRes = await fetchViaHTTP(appPort, '/something') const initialRes = await fetchViaHTTP(appPort, '/something')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册