Skip to content

Unable to disableScrollHandling from sveltekit:navigation-start event #3220

@nonphoto

Description

@nonphoto

Describe the bug

I'm not sure whether to classify this as a bug or a feature request. disableScrollHandling is very restrictive as to when it can be called. It seems like only actions and onMount work. However, I would like to disable scroll handling for every page on which a specific component is mounted, so I can't use onMount because the component might be mounted across multiple pages. The sveletekit:navigation-start event seems perfect for this, but it is not possible to disable scroll handling from there.

It's worth noting that I tried $: { if ($navigating) { disableScrollHandling() } } and beforeUpdate(disableScrollHandling) and those aren't allowed either

Reproduction

https://stackblitz.com/edit/sveltekit-yzgemn?file=src/routes/index.svelte

Clicking on "About" link causes Error: Can only disable scroll handling during navigation.

Logs

start.js:516 Uncaught (in promise) Error: Can only disable scroll handling during navigation
    at Renderer.disable_scroll_handling (start.js:516)
    at disableScrollHandling_ (navigation.js:27)
    at Router._navigate (start.js:272)
    at start.js:176


### System Info

```shell
System:
    OS: Linux undefined
    CPU: (4) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: Unknown - /bin/jsh
  Binaries:
    Node: 14.16.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /bin/yarn
    npm: 7.17.0 - /bin/npm
  npmPackages:
    @sveltejs/kit: ^1.0.0-next.216 => 1.0.0-next.216 
    svelte: ^3.42.6 => 3.44.3 


### Severity

serious, but I can work around it

### Additional Information

_No response_

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions