-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Unable to disableScrollHandling
from sveltekit:navigation-start
event
#3220
Comments
I don't understand this. Why not call This sounds like a feature request, but I'm not sure if we need it as we had documented that it should be called on component mount. For context, the reason calling from |
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 |
I think I understand your point now. It would likely be tedious to manually conditionally call
I think 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. |
For some more context I'm prototyping a library for transitioning between pages that would need to control the scroll position itself, hence why I would need to disable it on every page. I agree that normally it would make sense to have this be difficult but as a library author I wouldn't want the user to have to add a component to every page file. Ideally just the layout would suffice. Either way I'll make a pull request for the docs when I get a chance. I think it could just be more explicit that only onMount and actions work. |
I just noticed that server side redirects from an endpoint to the same page also triggers a scroll back to the top. I think given that in such a case Svelte Kit doesn't actually reload the page, but only reruns the <form method="post" action="/api/todo">
<input type="text" name="text" />
<button>Add Item</button>
</form> And after saving it to the DB you redirect back to the same page which will rerun return { status: 302, headers: { location: '/' } }; But it will also scroll back to the top. Couldn't get help on the Discord. |
@HibiscusCoffee I think that's because form submissions are not handled client side, so you are getting the default browser behavior when the page reloads and starts at the top again. Maybe submit as a separate feature request? |
As of #4948 you can call The form thing is a separate issue, but very much expected since a form submission reloads the page. To prevent that you would need to handle the |
Thanks! I think that takes care of my issue. |
* allow disableScrollHandling to be called in afterNavigate - fixes #3220 * fix tests * remove .only * format
Having exactly the same problem |
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 andonMount
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. Thesveletekit: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() } }
andbeforeUpdate(disableScrollHandling)
and those aren't allowed eitherReproduction
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
The text was updated successfully, but these errors were encountered: