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

Fix broken hash scroll logic #4766

Merged
merged 4 commits into from
Aug 11, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class Container extends Component {
}

scrollToHash () {
const { hash } = this.props
const { hash } = this.context._containerProps
if (!hash) return

const el = document.getElementById(hash)
Expand All @@ -73,8 +73,7 @@ export class Container extends Component {
}

render () {
const {children} = this.props
return <>{children}</>
return this.props.children
}
}

Expand Down
1 change: 1 addition & 0 deletions test/integration/basic/pages/nav/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default class extends Component {
Counter: {counter}
</div>
<button id='increase' onClick={() => this.increase()}>Increase</button>
<Link href='/nav/hash-changes#item-400'><a id='scroll-to-hash'>Scroll to hash</a></Link>
</div>
)
}
Expand Down
21 changes: 20 additions & 1 deletion test/integration/basic/test/client-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export default (context, render) => {
browser.close()
})

it('should scroll to the specified position', async () => {
it('should scroll to the specified position on the same page', async () => {
let browser
try {
browser = await webdriver(context.appPort, '/nav/hash-changes')
Expand All @@ -272,6 +272,25 @@ export default (context, render) => {
}
}
})

it('should scroll to the specified position to a new page', async () => {
let browser
try {
browser = await webdriver(context.appPort, '/nav')

// Scrolls to item 400 on the page
await browser
.elementByCss('#scroll-to-hash').click()
.waitForElementByCss('#hash-changes-page')

const scrollPosition = await browser.eval('window.pageYOffset')
expect(scrollPosition).toBe(7258)
} finally {
if (browser) {
browser.close()
}
}
})
})

describe('when hash change via A tag', () => {
Expand Down