question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to `disableScrollHandling` from `sveltekit:navigation-start` event

See original GitHub issue

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_

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bluwycommented, Jan 8, 2022

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.

As far as I know there’s no way to write a component that mounts on every navigation. For example if I want to disable scroll handling from a component at the layout level, that component will only mount when navigating to each page for the first time.

This is maybe just documentation clarity though. It should probably clarify that navigation-start happens before navigation, not at the start of navigation. I would definitely expect $: { if ($navigating) { disableScrollHandling() } } to work though based on the wording in the docs right now.

I think start and before are both still ambiguous and interchangeable for the navigation lifecycle, and I think the docs for disableScrollHandling is clear though as it mentions to work for onMount 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.

0reactions
nonphotocommented, May 16, 2022

Thanks! I think that takes care of my issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Modules • Docs • SvelteKit
async function handleSubmit ( event ) { ... disableScrollHandling , ... Returns a Promise that resolves when SvelteKit navigates (or fails to navigate, ......
Read more >
ccxt fetchbalances() returns SPOT balance by default - IssueHint
Unable to `disableScrollHandling` from `sveltekit:navigation-start ` event, 8, 2022-01-06, 2022-09-08. Slow UPDATE queries? 2, 2022-11-24, 2022-11-18.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found