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

ScrollRestoration on RR 6.4 #4844

Merged
merged 4 commits into from Dec 16, 2022

Conversation

brophdawg11
Copy link
Contributor

@brophdawg11 brophdawg11 commented Dec 12, 2022

Update to ScrollRestoration to wrap the RR 6.4 internals

Testing:

  • Needs to be run with changes from Updates for Remix on RR 6.4 react-router#9664
  • Confirm client side scroll restoration works on back/forward button routing
  • Confirm SSR restoration works on hard reloads
  • Confirm <ScrollRestoration getKey={(location, matches) => ...} /> works
  • Confirm <Link preventScrollReset> works

@changeset-bot
Copy link

changeset-bot bot commented Dec 12, 2022

⚠️ No Changeset found

Latest commit: 2264efa

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

export function useBeforeUnload(
callback: (event: BeforeUnloadEvent) => any
): void {
// TODO: Export from react-router-dom
Copy link
Contributor Author

Choose a reason for hiding this comment

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

import type { ScrollRestorationProps as ScrollRestorationPropsRR } from "react-router-dom";
import {
useLocation,
UNSAFE_useScrollRestoration as useScrollRestoration,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The hook was private in both Remix and RR so kept it that way via the UNSAFE_ prefix

useScrollRestoration({
getKey,
storageKey: STORAGE_KEY,
skip: !hydrated,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Matt to do some double checking here and see if there's any way skip could go away...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we assume hydrationData means "skip the first restoration" then we could get rid of this

@brophdawg11 brophdawg11 force-pushed the brophdawg11/scroll-restoration-6-4 branch from 09e580a to 8fa967f Compare December 14, 2022 16:31
Base automatically changed from rrr-hydration to feat/rrr-rendering December 14, 2022 16:32
@brophdawg11 brophdawg11 merged commit 917b75e into feat/rrr-rendering Dec 16, 2022
@brophdawg11 brophdawg11 deleted the brophdawg11/scroll-restoration-6-4 branch December 16, 2022 22:25
brophdawg11 added a commit that referenced this pull request Dec 16, 2022
brophdawg11 added a commit that referenced this pull request Dec 19, 2022
* Bump remix to react-router-dom@6.4.4 (#4668)
* RRR Step 2 - Server Rendering (#4669)
* RRR Step 3 - Hydration (#4703)
* RRR Rendering Follow Ups (#4885)
* ScrollRestoration on RR 6.4 (#4844)

Co-authored-by: Jacob Ebey <jacob.ebey@live.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants