Skip to content

fix(router): replace next() deprecated in Vue Router v5#22643

Merged
J-Sek merged 2 commits intovuetifyjs:masterfrom
dennybiasiolli:fix-22632-deprecated-vue-router-usage
Mar 11, 2026
Merged

fix(router): replace next() deprecated in Vue Router v5#22643
J-Sek merged 2 commits intovuetifyjs:masterfrom
dennybiasiolli:fix-22632-deprecated-vue-router-usage

Conversation

@dennybiasiolli
Copy link
Copy Markdown
Contributor

Description

resolves #22632

vue-router v5 added a deprecation notice in the usage of a NavigationGuardNext function (https://router.vuejs.org/api/interfaces/NavigationGuardNext.html), the "new way" of using it is returning a NavigationGuardReturn directly.

NOTE: consider upgrading to vue-router v5.x in the repo before accepting/merging this

pnpm --filter vuetify add vue-router@5
git add packages/vuetify/package.json pnpm-lock.yaml
git commit -m "feat: upgrading vue-router to v5 in vuetify package"
git push

Markup:

Upgrade to vue-router 5.x to get the console warning:

pnpm --filter vuetify add vue-router@5
<template>
  <v-app>
    <v-container>
      <v-overlay />
    </v-container>
  </v-app>
</template>

<script>
  import { useRouter } from 'vue-router'

  export default {
    name: 'Playground',
    setup () {
      const router = useRouter()
      router.push('/page1').then(() => {
        router.push('/')
      })
      return {
        //
      }
    },
  }
</script>

@dennybiasiolli dennybiasiolli force-pushed the fix-22632-deprecated-vue-router-usage branch 2 times, most recently from 3ceb0d1 to 524e981 Compare February 24, 2026 13:44
@wusonw
Copy link
Copy Markdown

wusonw commented Mar 4, 2026

Hey guys, patches below works fine for me :

diff --git a/lib/composables/router.js b/lib/composables/router.js
index fd42accc1674e85a542ca960e38676fd6878e2e5..3790ca4f5b3b9ec817f4907c138c2c1382703ec6 100644
--- a/lib/composables/router.js
+++ b/lib/composables/router.js
@@ -75,13 +75,25 @@ export function useBackButton(router, cb) {
   if (IN_BROWSER && router?.beforeEach) {
     nextTick(() => {
       window.addEventListener('popstate', onPopstate);
-      removeBefore = router.beforeEach((to, from, next) => {
+      removeBefore = router.beforeEach((to, from) => {
+        if (to === from) return;
+        const runCallback = () => {
+          let result;
+          const next = (val) => { result = val; };
+          if (popped) {
+            cb(next);
+            return result;
+          }
+          return undefined;
+        };
         if (!inTransition) {
-          setTimeout(() => popped ? cb(next) : next());
-        } else {
-          popped ? cb(next) : next();
+          inTransition = true;
+          return new Promise((resolve) => {
+            setTimeout(() => resolve(runCallback()));
+          });
         }
         inTransition = true;
+        return runCallback();
       });
       removeAfter = router?.afterEach(() => {
         inTransition = false;

@dennybiasiolli
Copy link
Copy Markdown
Contributor Author

@wusonw what do you think about my proposed change in this PR?
I also updated the typing of useBackButton function in the same file and the related packages/vuetify/src/components/VOverlay/VOverlay.tsx and packages/docs/src/main.ts.
Also added a few tests for useBackButton

@dennybiasiolli dennybiasiolli force-pushed the fix-22632-deprecated-vue-router-usage branch from 524e981 to 0afdd99 Compare March 9, 2026 21:27
@Elchin5757
Copy link
Copy Markdown

When will this warning be fixed/removed?

@J-Sek
Copy link
Copy Markdown
Contributor

J-Sek commented Mar 10, 2026

@Elchin5757: When will this warning be fixed/removed?

rude 😛 I am sick now and do it for free anyway since OC funds dried up.

Can you download the repo, checkout this branch, build, point your app's package.json to the file:{path}/packages/vuetify, rebuild and verify it works fine in multiple scenarios (mostly dialogs and menus with persistent) while keeping in mind it was the not very reliable in the first place (#18505)? It genuinely would help even after merging this PR.

Tip: add { outline: '2px solid red' } to the styles below v-overlay__content in VOverlay.tsx to make sure your app loaded the local version. If you work with Nuxt, anytime you rebuild local vuetify, remove both node_modules and .nuxt and re-install dependencies.

Copy link
Copy Markdown
Contributor

@J-Sek J-Sek left a comment

Choose a reason for hiding this comment

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

These new tests hardly make any sense to me. Either I need some explanation or we should replace them with 2-3 cases in VDialog.spec.browser.tsx that are somewhat aligned with manual tests we would perform.

@dennybiasiolli
Copy link
Copy Markdown
Contributor Author

It was to unit-test the useBackButton that was missing tests.
Let me remove them and try to add a test inside VDialog.spec.browser.tsx if possible.
If you have suggestions about the tests that needs to be performed, let me know, I will try to figure out something in the meantime

@dennybiasiolli
Copy link
Copy Markdown
Contributor Author

BTW, I think the issue in VDialog is out of the topic of this PR, I will try to investigate that in another PR right after this one, is that ok for you?

The current PR removes the deprecation warning in the console when using the next parameter in navigation guards from vue-router inside v-overlay components.

I know, they are used in VDialog, but also in VMenu, VOtpInput and others.

@dennybiasiolli dennybiasiolli force-pushed the fix-22632-deprecated-vue-router-usage branch from 0afdd99 to c921641 Compare March 11, 2026 10:10
@J-Sek
Copy link
Copy Markdown
Contributor

J-Sek commented Mar 11, 2026

Hi, thanks for taking time to resolve the deprecation warnings. I would not mind unit-tests, but those were some kind of accidental nonsense that would only hurt us in the long run - by giving false confidence or failing for non-obvious reason. The more practical approach will be to have test for VDialog that are easy to grasp and repeat manually. You have proven the useBackButton can be broken in non-obvious way and I have spent hours on verification, so we will definitely benefit from the coverage.

If you can tackle any other outstanding issue with useBackButton, it would be of great help. Just prepare yourself to be questioned about the reason behind any changes in the code that are not 100% related to the problem 😉 If you got help from LLM-based tools, remember to trim, self-review and check the final output to avoid pushing slop with logical errors.

@J-Sek J-Sek added upstream Problem with a third party library that we may have to work around C: VOverlay E: router labels Mar 11, 2026
@J-Sek J-Sek changed the title fix(VOverlay): remove deprecated usage of Vue Router next() callback fix(router): replace next() deprecated in Vue Router v5 Mar 11, 2026
@J-Sek J-Sek merged commit 87c4129 into vuetifyjs:master Mar 11, 2026
9 checks passed
J-Sek pushed a commit that referenced this pull request Mar 11, 2026
Co-authored-by: J-Sek <J-Sek@users.noreply.github.com>

resolves #22632
@dennybiasiolli dennybiasiolli deleted the fix-22632-deprecated-vue-router-usage branch March 11, 2026 15:35
@pizzaeater

This comment was marked as resolved.

@J-Sek

This comment was marked as outdated.

@pizzaeater

This comment was marked as outdated.

@J-Sek

This comment was marked as outdated.

@dennybiasiolli
Copy link
Copy Markdown
Contributor Author

Warning gone after updating to the newly released v3.12.3

@pizzaeater
Copy link
Copy Markdown

4e93846 landed in v3.12.3 Do you observe the warnings after the update?

Yes, it seems like it's fixed now! Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C: VOverlay E: router upstream Problem with a third party library that we may have to work around

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug Report][3.11.8] useBackButton uses deprecated Vue Router next() callback

5 participants