You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit ce33787
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: packages/docs/experimental/scroll-restoration.md
+18-2Lines changed: 18 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -97,9 +97,9 @@ The router _captures_ the position **when you leave the page**, and when the bro
97
97
98
98
## Capture events
99
99
100
-
The plugin captures positions after each successful navigationand when the document becomes hidden. It does not listen to `pagehide`.
100
+
The plugin captures positions after each successful navigation, on `pagehide`, and when the document becomes hidden.
101
101
102
-
Use `setupListeners(capture, signal)` to replace the default `visibilitychange` listener. The supplied `capture()` saves all active scroll registrations for the current route. Navigation capture remains enabled.
102
+
Use `setupListeners(capture, signal)` to replace the default event listeners. The supplied `capture()` saves all active scroll registrations for the current route. Navigation capture remains enabled.
103
103
104
104
For example, capture on scroll:
105
105
@@ -116,6 +116,22 @@ app.use(ScrollRestoration, {
116
116
117
117
Pass `signal` to your listeners so they are removed when the app is unmounted. You can listen to your own event instead, or save the supplied `capture` function and call it manually. To disable additional capture events, use `setupListeners: () => {}`.
118
118
119
+
To keep the default events and add your own, call `SCROLL_RESTORATION_SETUP_LISTENERS_DEFAULT`:
window.addEventListener('save-scroll', capture, { signal })
131
+
},
132
+
})
133
+
```
134
+
119
135
A [`scroll` event cannot be canceled](https://developer.chrome.com/blog/passive-event-listeners), so `passive: true` does not improve scroll performance. Each capture calls all active capture functions and writes to `sessionStorage` synchronously. For frequent events, throttle captures and use the signal to cancel pending work on unmount.
0 commit comments