mefechoel / svelte-navigator

Simple, accessible routing for Svelte
Other
502 stars 39 forks source link

useLocation hook throws #33

Closed mataslib closed 3 years ago

mataslib commented 3 years ago

Describe the bug A clear and concise description of what the bug is.

useLocation() hook throws error Function called oustide component initialization.

To Reproduce Steps to reproduce the behavior:

  1. npm init @vitejs/app (choose svelte > javascript)
  2. cd vite-project && npm install
  3. npm install svelte-navigator --save
  4. add router with link to route having useLocation()
  5. click the link and see error in console

Please add a link to an example in the Svelte REPL or in a Codesandbox, if you can.

https://github.com/mataslib/uselocation-bug-repl

Expected behavior A clear and concise description of what you expected to happen.

Show route content

Screenshots If applicable, add screenshots to help explain your problem.

errorprtscr

Additional context Add any other context about the problem here.

Seems to not work only with Vite dev. It works with vite build, when u visit builded dist html. I used useLocation() before with rollup and it was working. Then I switched to vite for its speed and it also did work. Today, I was removing and updating npm deps and it stopped working with this error. Unfortunately I wasn't able to revert to working state and detect the culprit, so I made this clean repl.

mefechoel commented 3 years ago

Duplicate of #34