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

Ensure history navigation is correct after query update #38086

Merged
merged 1 commit into from Jun 28, 2022
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
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