inertiajs / inertia

Inertia.js lets you quickly build modern single-page React, Vue and Svelte apps using classic server-side routing and controllers.
https://inertiajs.com
MIT License
6.3k stars 423 forks source link

[1.x] Fix a bug with [scroll-region] elements not restoring correct scroll positions in react adapter #1796

Closed dsazup closed 2 weeks ago

dsazup commented 7 months ago

Hi, I'm using react and I run into a bug where I have a [scroll-region] element and after navigating back, the scroll position is not restored, even though the page has saved the positions correctly.

This happens because in the restoreScrollPositions method this.scrollRegions() returns an empty array. It thinks that there aren't any [scroll-region] elements, because the document body hasn't been updated yet. Even though there actually is an element. Simply wrapping the whole thing in setTimeout fixes it and positions are restored correctly.

pedroborges commented 4 weeks ago

1803 also fixes a scroll restoration bug in the React adapter. These PRs conflict with each other but that will be easy to consolidate.

pedroborges commented 2 weeks ago

Fixed by #1980 ✅