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

Smooth scrolling does not work in firefox but does in chrome #1411

Open
lxgr-linux opened this issue May 19, 2022 · 2 comments
Open

Smooth scrolling does not work in firefox but does in chrome #1411

lxgr-linux opened this issue May 19, 2022 · 2 comments
Labels
browser quirk Specific to a browser bug Something isn't working has workaround A workaround has been found to deal with the issue

Comments

@lxgr-linux
Copy link

Version

4.0.15

Reproduction link

github.com

Steps to reproduce

Run the reproduction scroll down and press the link titled link.

What is expected?

It is expected that the current page is changed to the test page and is smoothly scrolled to the top.

What is actually happening?

In firefox the current page switches to the test page, but does not scroll up.


Works in chrome. Removing the behavior: 'smooth' makes the test page at least start on top, but also removes the intended scroll effect.

@posva
Copy link
Member

posva commented May 20, 2022

hmm, this is weird, it could be a Firefox regression similar to #1147. It would require checking which version broke and why:

At least there is a very easy workaround: delay one tick the resolution of the scrollBehavior:

const delay = (t) => new Promise((r) => setTimeout(r, t))

const router = createRouter({
  history: createWebHashHistory(),
  // history: createWebHistory(),
  routes,
  async scrollBehavior(to, from, savedPosition) {
    console.log({ savedPosition })
    if (savedPosition) {
      return savedPosition
    } else {
      await delay(0)
      return { top: 0, behavior: 'smooth' }
    }
  },
})

@posva posva added bug Something isn't working has workaround A workaround has been found to deal with the issue browser quirk Specific to a browser labels May 20, 2022
@lxgr-linux
Copy link
Author

Thanks a lot for the workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
browser quirk Specific to a browser bug Something isn't working has workaround A workaround has been found to deal with the issue
Projects
Status: Planned
Development

No branches or pull requests

2 participants