flekschas / svelte-simple-modal

A simple, small, and content-agnostic modal for Svelte v3 and v4
https://svelte.dev/repl/b95ce66b0ef34064a34afc5c0249f313
MIT License
422 stars 30 forks source link

Page scrolling to the top on load, even if an anchor is specified #53

Closed mquandalle closed 2 years ago

mquandalle commented 2 years ago

When the Modal component is used, the page is scrolled to the top on first load, or during in-app navigation. This is unwanted in case we link to an anchor.

Reproduction : https://repro-svelte-simple-modal-anchor-issue-maximequandalle.vercel.app/#anchor Source : https://github.com/mquandalle/repro-svelte-simple-modal-anchor-issue/blob/master/src/routes/index.svelte

mquandalle commented 2 years ago

It seems that this bug was introduced in #31.

flekschas commented 2 years ago

Sorry for the glitch and thanks for reporting the issue. Can you test it with the following version of the Modal?

https://svelte.dev/repl/2eb021eff87d45019549565136b0e6ed?version=3.44.1

In my local tests with your repo this fixes the issue.

mquandalle commented 2 years ago

Yes it fixes the issue.

The problem was indeed the reactivity of isMounted variable in the following block, causing close() to be called on mount: https://github.com/flekschas/svelte-simple-modal/blob/43bb9c19a69965843a525289a4e0aea3a854e77d/src/Modal.svelte#L201-L219

flekschas commented 2 years ago

New version with a fix is out

mquandalle commented 2 years ago

Thank you for the quick fix!