Repository navigation
refactor(client)!: replace deprecated scrollBehavior with ScrollRestoration - #1727
Open
Mister-Hope wants to merge 1 commit into
Open
Mister-Hope wants to merge 1 commit into
Mister-Hope wants to merge 1 commit into
Conversation
…ration `vue-router` 5.4 deprecates the router `scrollBehavior` option in favor of the `ScrollRestoration` plugin and `useScrollRestoration()`. - bump the `vue-router` catalog to `^5.4.0` - install `ScrollRestoration` before the router in `createVueApp()` - drop `scrollBehavior` from `createVueRouter()` VuePress renders the page layout directly instead of wrapping it in a `<RouterView>`, so the restoration provided by `onRouteRendered` would run before the new page is rendered. `useScrollRestoration()` is therefore registered with `manual: true`, and the scroll is restored after mounting and after each route change. BREAKING CHANGE: `router.options.scrollBehavior` is no longer set. Packages that read or wrap it, e.g. to defer the scroll until their page transition is done, need to be migrated. close #1726
Coverage Report for CI Build 38455032649Coverage remained the same at 73.948%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
vue-router5.4 deprecates the routerscrollBehavioroption:@vuepress/clientstill sets it increateVueRouter(), so VuePress and downstream packages depend on a deprecated API (and packages using type-aware linting are warned about it). This PR migrates the core client to the replacement.Closes #1726.
Changes
vue-routercatalog from^5.2.0to^5.4.0.ScrollRestorationplugin before the router increateVueApp().scrollBehavioroption fromcreateVueRouter().VuePress renders the page layout directly instead of wrapping it in a
<RouterView>, so the restoration provided byonRouteRenderedwould be called inrouter.afterEach(), before the new page is rendered, and cross-page hash links would never scroll.useScrollRestoration()is therefore registered withmanual: true, and the scroll is restored after mounting and after each route change, which keeps the previous behavior intact.The plugin options require
captureandrestoreto be passed explicitly (the documentedapp.use(ScrollRestoration, { router })snippet does not type-check), so the defaultsSCROLL_RESTORATION_CAPTURE_DEFAULTandSCROLL_RESTORATION_RESTORE_DEFAULTare used.Tests
Added
e2e/tests/router/scroll-restoration.spec.tswith a tall fixture page (e2e/docs/router/scroll-restoration.md), covering:Verification
pnpm lintandpnpm check-typespass.pnpm test:unitpasses (666 tests).pnpm test:e2epasses:e2e:dev(87 tests) ande2e:build(94 tests).Notes
router.options.scrollBehavioris no longer set, so packages that read or patch it must be migrated on top of this change:@vuepress/plugin-active-header-linkssets it toundefinedso that updating the hash programmatically does not trigger a scroll.@vuepress/theme-defaultwraps it to wait for its page transition before scrolling.Both live in other repositories, so they will be handled in follow-up PRs. Note that #1724 patches
scrollBehaviorin the same place and will need to be rebased on top of this migration.