We can't access goto props during beforeNavigate
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
Describe the bug
When running goto:
goto('/route', { replaceState: true });
We cannot access the opts during beforeNavigate, meaning we cannot reconstruct the original goto intention.
Reproduction
https://www.loom.com/share/4d6dce37a81545ef90ffb69914a4eeb3 - video (4min)
https://github.com/oodavid/svelteKit-beforeUnload-goto - repo
Logs
No response
System Info
System:
OS: macOS 12.3.1
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 76.49 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.18.1 - ~/.nvm/versions/node/v16.18.1/bin/node
npm: 8.19.2 - ~/.nvm/versions/node/v16.18.1/bin/npm
Browsers:
Chrome: 109.0.5414.87
Edge: 109.0.1518.52
Firefox: 105.0.1
Safari: 15.4
npmPackages:
@sveltejs/adapter-auto: ^1.0.2 => 1.0.2
@sveltejs/kit: ^1.1.4 => 1.1.4
svelte: ^3.55.1 => 3.55.1
vite: ^4.0.4 => 4.0.4
Severity
annoyance
Additional Information
Intercepting the navigation event with a confirmation UI will be a common use-case for beforeNavigate.
Because of this, it could be useful to be able to pause, cancel or resume the event, that way we can be confident that the original intention is kept intact without having to curry props or opts around.
Going even further; pause, cancel or resume sounds a lot like promises. I've not thought about the interface though.
For the time being, I'm going to use window.confirm
beforeNavigate((navigation) => {
if(!window.confirm('you sure?')){
navigation.cancel();
}
});
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the linked reproduction repo and tracing the beforeNavigate entry point when goto('/route', { replaceState: true }) is called. Confirm whether the navigation callback can receive the original goto options, and consider the work complete when those options are available during beforeNavigate without requiring callers to curry them around.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100