Skip to content

Commit

Permalink
Make sure to update asPath on hashOnlyChange to (#7255)
Browse files Browse the repository at this point in the history
prevent getInitialProps from firing when it shouldn't
  • Loading branch information
ijjk authored and lfades committed May 5, 2019
1 parent c421c25 commit a243bc4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/next-server/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ export default class Router implements BaseRouter {
// If the url change is only related to a hash change
// We should not proceed. We should only change the state.
if (this.onlyAHashChange(as)) {
this.asPath = as
Router.events.emit('hashChangeStart', as)
this.changeState(method, url, as)
this.scrollToHash(as)
Expand Down
12 changes: 12 additions & 0 deletions test/integration/client-navigation/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,18 @@ describe('Client Navigation', () => {

await browser.close()
})

it('should not run getInitialProps when removing via back', async () => {
const browser = await webdriver(context.appPort, '/nav/hash-changes')

const counter = await browser
.elementByCss('#scroll-to-item-400').click()
.back()
.elementByCss('p').text()

expect(counter).toBe('COUNT: 0')
await browser.close()
})
})

describe('when hash set to empty', () => {
Expand Down

0 comments on commit a243bc4

Please sign in to comment.