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

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

Closed
wants to merge 2 commits into from

Conversation

dsazup
Copy link

@dsazup dsazup commented Feb 12, 2024

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 pedroborges added react Related to the react adapter core Related to the core Inertia library labels Sep 6, 2024
Copy link
Collaborator

@pedroborges pedroborges left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested locally and reproduced the bug with the React adapter. Your solution fixes it, @dsazup. Thank you!

The core has been rewritten to support async requests, the restoreScrollPositions method has been renamed and moved to the packages/core/src/scroll.ts file. Let's wait until that work is merged into master to rebase and merge this one 👍

@pedroborges
Copy link
Collaborator

pedroborges commented Sep 6, 2024

#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 pedroborges changed the title Fix a bug with [scroll-region] elements not restoring correct scroll positions in react adapter [1.x] Fix a bug with [scroll-region] elements not restoring correct scroll positions in react adapter Sep 13, 2024
@pedroborges pedroborges removed the request for review from joetannenbaum September 17, 2024 19:55
@pedroborges
Copy link
Collaborator

Fixed by #1980

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to the core Inertia library react Related to the react adapter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants