Unable to `disableScrollHandling` from `sveltekit:navigation-start` event
See original GitHub issueDescribe 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_
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (3 by maintainers)
I think I understand your point now. It would likely be tedious to manually conditionally call
disableScrollHandling
on a per-page basis (as a workaround), but on one hand it’s intended to be that way because we discourage the use of the function.I think
start
andbefore
are both still ambiguous and interchangeable for the navigation lifecycle, and I think the docs fordisableScrollHandling
is clear though as it mentions to work foronMount
and actions only. When we start a navigation, the new page is not guaranteed to be mounted yet.Back to the feature request of this issue, I’m trying to think some ways of implementing it, but I feel it would open a can of worms. So maybe the better path forward is to document this, but it’s not clear to me what else should we elaborate on.
If you have some ideas, feel free to open a pull request though.
Thanks! I think that takes care of my issue.