未验证 提交 e63d8221 编写于 作者: J JJ Kasper 提交者: GitHub

Make sure to not override initial navigation when refreshing static page's query (#10353)

* Add failing case

* Make sure to only refresh query if still on initial page
Co-authored-by: NJoe Haddad <timer150@gmail.com>
上级 9e6689e6
...@@ -99,9 +99,10 @@ class Container extends React.Component { ...@@ -99,9 +99,10 @@ 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 && router.isSsr &&
((data.nextExport &&
(isDynamicRoute(router.pathname) || location.search)) || (isDynamicRoute(router.pathname) || location.search)) ||
(Component && Component.__N_SSG && location.search) (Component && Component.__N_SSG && 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 Router from 'next/router'
class Page extends React.Component {
componentDidMount() {
Router.push('/')
}
render() {
return <p>redirecting..</p>
}
}
export default Page
...@@ -83,6 +83,12 @@ function runTests(dev) { ...@@ -83,6 +83,12 @@ function runTests(dev) {
} }
}) })
it('should allow calling Router.push on mount successfully', async () => {
const browser = await webdriver(appPort, '/post-1/on-mount-redir')
waitFor(2000)
expect(await browser.elementByCss('h3').text()).toBe('My blog')
})
// it('should navigate optional dynamic page', async () => { // it('should navigate optional dynamic page', async () => {
// let browser // let browser
// try { // try {
...@@ -456,6 +462,12 @@ function runTests(dev) { ...@@ -456,6 +462,12 @@ function runTests(dev) {
page: '/[name]/comments', page: '/[name]/comments',
regex: normalizeRegEx('^\\/([^\\/]+?)\\/comments(?:\\/)?$'), regex: normalizeRegEx('^\\/([^\\/]+?)\\/comments(?:\\/)?$'),
}, },
{
page: '/[name]/on-mount-redir',
regex: normalizeRegEx(
'^\\/([^\\/]+?)\\/on\\-mount\\-redir(?:\\/)?$'
),
},
{ {
page: '/[name]/[comment]', page: '/[name]/[comment]',
regex: normalizeRegEx('^\\/([^\\/]+?)\\/([^\\/]+?)(?:\\/)?$'), regex: normalizeRegEx('^\\/([^\\/]+?)\\/([^\\/]+?)(?:\\/)?$'),
...@@ -507,7 +519,10 @@ describe('Dynamic Routing', () => { ...@@ -507,7 +519,10 @@ describe('Dynamic Routing', () => {
}) })
describe('serverless mode', () => { describe('serverless mode', () => {
let origNextConfig
beforeAll(async () => { beforeAll(async () => {
origNextConfig = await fs.readFile(nextConfig, 'utf8')
await fs.writeFile( await fs.writeFile(
nextConfig, nextConfig,
` `
...@@ -526,7 +541,10 @@ describe('Dynamic Routing', () => { ...@@ -526,7 +541,10 @@ describe('Dynamic Routing', () => {
appPort = await findPort() appPort = await findPort()
app = await nextStart(appDir, appPort) app = await nextStart(appDir, appPort)
}) })
afterAll(() => killApp(app)) afterAll(async () => {
await fs.writeFile(nextConfig, origNextConfig)
await killApp(app)
})
runTests() runTests()
}) })
}) })
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册