Automattic / Automattic/jetpack
Infinite scroll: on scrolled page, browser "back" button creates offset issues
- Dominant language
- PHP
- Stars
- 1.8k
- Forks
- 898
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 774
Description
This happens always on Chrome, and only sometimes on Firefox.
This happens on a shop page which is set as a front-page (and not on an archive page, for example).
Stock Storefront theme. Only Jetpack and WooCommerce enabled.
Video:
https://www.loom.com/share/0d3c3dad7c77472bb576df6f7c4a6655
on infinity.min.js, this line calculates the next page number:
`page: this.page + this.offset`
On a regular scroll, the types of both `this.page` and `this.offset` are `number` (see video).
But, when coming back to the page via the browser back button, the type of `this.offset` is a `string` (see video).
For this reason, instead of, for example, going from page 3 to 4, the code goes to page 13 (see video).
When replacing:
`page: this.page + this.offset`
With:
`page: this.page +Number(this.offset)`
The issue is solved.
Another issue that might be related (#17109) (also happening in Chrome and not in Firefox):
When coming back to the page via the browser back button, the page starts with the current scrolled batch and **not** loading all previous batches until the current position.
Contributor guide
Research direction
Start in infinity.min.js at the page calculation using this.page and this.offset, then reproduce the browser-back flow on a front-page shop using Chrome and the Storefront theme. Done means the offset remains numeric so scrolling advances from page 3 to 4 rather than page 13, and the reported behavior is checked in Firefox as well.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100