Ensure history navigation is correct after query update (#38086)

This commit is contained in:
JJ Kasper 2022-06-27 21:08:08 -05:00 committed by GitHub
parent edf4ea3944
commit a72e136c79
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 0 deletions

View file

@ -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
)

View file

@ -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',

View file

@ -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'