Skip to content

Commit

Permalink
Ensure history navigation is correct after query update (#38086)
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Jun 28, 2022
1 parent edf4ea3 commit a72e136
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/next/shared/lib/router/router.ts
Expand Up @@ -903,6 +903,8 @@ export default class Router implements BaseRouter {
Object.assign<{}, TransitionOptions, TransitionOptions>({}, options, {
shallow: options.shallow && this._shallow,
locale: options.locale || this.defaultLocale,
// @ts-ignore internal value not exposed on types
_h: 0,
}),
forcedScroll
)
Expand Down
17 changes: 17 additions & 0 deletions test/e2e/middleware-rewrites/test/index.test.ts
Expand Up @@ -50,6 +50,23 @@ describe('Middleware Rewrite', () => {
}, /Welcome Page A/)
})

it('should rewrite correctly when navigating via history after query update', async () => {
const browser = await webdriver(next.url, '/')
await browser.elementByCss('#override-with-internal-rewrite').click()
await check(() => {
return browser.eval('document.documentElement.innerHTML')
}, /Welcome Page A/)

await browser.refresh()
await browser.waitForCondition(`!!window.next.router.isReady`)
await browser.back()
await browser.waitForElementByCss('#override-with-internal-rewrite')
await browser.forward()
await check(() => {
return browser.eval('document.documentElement.innerHTML')
}, /Welcome Page A/)
})

it('should return HTML/data correctly for pre-rendered page', async () => {
for (const slug of [
'first',
Expand Down
20 changes: 20 additions & 0 deletions test/integration/production/test/index.test.js
Expand Up @@ -68,6 +68,26 @@ describe('Production Usage', () => {
await killApp(app)
})

it('should navigate through history after query update', async () => {
const browser = await webdriver(appPort, '/')
await browser.eval('window.next.router.push("/about?a=b")')
await browser.waitForElementByCss('.about-page')
await browser.waitForCondition(`!!window.next.router.isReady`)

await browser.refresh()
await browser.waitForCondition(`!!window.next.router.isReady`)
await browser.back()
await browser.waitForElementByCss('.index-page')
await browser.forward()
await browser.waitForElementByCss('.about-page')
await browser.back()
await browser.waitForElementByCss('.index-page')
await browser.refresh()
await browser.waitForCondition(`!!window.next.router.isReady`)
await browser.forward()
await browser.waitForElementByCss('.about-page')
})

it('should not show target deprecation warning', () => {
expect(output).not.toContain(
'The `target` config is deprecated and will be removed in a future version'
Expand Down

0 comments on commit a72e136

Please sign in to comment.