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

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

Merged
merged 4 commits into from Feb 1, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/next/client/index.js
Expand Up @@ -99,9 +99,10 @@ class Container extends React.Component {
// If page was exported and has a querystring
// If it's a dynamic route or has a querystring
if (
(data.nextExport &&
router.isSsr &&
((data.nextExport &&
(isDynamicRoute(router.pathname) || location.search)) ||
(Component && Component.__N_SSG && location.search)
(Component && Component.__N_SSG && location.search))
) {
// update query on mount for exported pages
router.replace(
Expand Down
14 changes: 14 additions & 0 deletions test/integration/dynamic-routing/pages/[name]/on-mount-redir.js
@@ -0,0 +1,14 @@
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
20 changes: 19 additions & 1 deletion test/integration/dynamic-routing/test/index.test.js
Expand Up @@ -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 () => {
// let browser
// try {
Expand Down Expand Up @@ -456,6 +462,12 @@ function runTests(dev) {
page: '/[name]/comments',
regex: normalizeRegEx('^\\/([^\\/]+?)\\/comments(?:\\/)?$'),
},
{
page: '/[name]/on-mount-redir',
regex: normalizeRegEx(
'^\\/([^\\/]+?)\\/on\\-mount\\-redir(?:\\/)?$'
),
},
{
page: '/[name]/[comment]',
regex: normalizeRegEx('^\\/([^\\/]+?)\\/([^\\/]+?)(?:\\/)?$'),
Expand Down Expand Up @@ -507,7 +519,10 @@ describe('Dynamic Routing', () => {
})

describe('serverless mode', () => {
let origNextConfig

beforeAll(async () => {
origNextConfig = await fs.readFile(nextConfig, 'utf8')
await fs.writeFile(
nextConfig,
`
Expand All @@ -526,7 +541,10 @@ describe('Dynamic Routing', () => {
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))
afterAll(async () => {
await fs.writeFile(nextConfig, origNextConfig)
await killApp(app)
})
runTests()
})
})