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

History needs to visit with a restoration identifier to restore scroll position #295

Merged
merged 1 commit into from Jun 30, 2021

Conversation

dhh
Copy link
Member

@dhh dhh commented Jun 29, 2021

We don't need to go through proposeVisit, because the visit already passed that check to get into the history.

…l position

We don't need to go through proposeVisit, because the visit already passed that check to get into the history.
if (this.enabled) {
this.navigator.proposeVisit(location, { action: "restore", historyChanged: true })
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if calling proposeVisit might be needed for the native adapters?
I think this issue was previously solved by passing the restorationIdentifier along in the options to proposeVisit.

Copy link
Member Author

Choose a reason for hiding this comment

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

I checked that with the Android adapter, and it did not seem to be the case: https://github.com/hotwired/turbo-android/blob/556cfae61408811fe488bd877416b27e53cb35ca/turbo/src/main/assets/js/turbo_bridge.js. But will test before rolling further. We also have a test that's explicitly asserting that we're not going through proposeVisit (since that implies the right to cancel): https://github.com/hotwired/turbo/blob/main/src/tests/functional/visit_tests.ts#L74-L81

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure it'd work just to pass the restorationIdentifier as part of the option set either. Where this problem was triggered was in BrowserAdapter#visitPropoposedToLocation, which just always generates a new uuid for the restorationIdentifier: https://github.com/hotwired/turbo/blob/main/src/core/native/browser_adapter.ts#L18. And passing the restorationIdentifier all the way from history popped meant passing it through like 3-4 times.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahh, I see that this other PR added restorationIdentifier to the VisitOptions. Yeah, that would also be a way to go.

Copy link
Member Author

Choose a reason for hiding this comment

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

Verified that historyPoppedToLocationWithRestorationIdentifier is not used by the native adapters. So fine to proceed with this simple fix to the problem as it appears in browsers.

@dhh dhh merged commit 787d1bb into main Jun 30, 2021
@dhh dhh deleted the history-pops-with-restoration-identifier branch June 30, 2021 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants