Repository navigation
fix: respect replace_state on navigation where applicable - #13303
konstantinov90 wants to merge 27 commits into
Conversation
🦋 Changeset detectedLatest commit: cc42c80 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
this is an automated message |
|
|
|
@eltigerchino thank you, I had read the docs goto is not meant to be used to navigate outside the app, but still it is used for same domain navigation, so why not do it correctly? |
|
I think even if it's the same domain but not a part of the app it's still considered "outside the app", so you should use |
|
@eltigerchino in theory I agree, but in practice it is quite convenient to use svelte-kit's mechanism to define which route is inside or outside of my current app. With file based routing you need some kind of manifest to determine if you navigate outside and as far as I know we don't have anything like that for client-side |
|
@eltigerchino @dummdidumm hey, guys! on the latest sveltekit version, |
|
Could you add a test for this? |
fcaa948 to
472c362
Compare
Done! For clarity I have created the PR with tests only #13995, so as to illustrate the problems, that I am trying to solve |
| expectPath(page).toBe('/navigation/teststart'); | ||
| }); | ||
|
|
||
| test.describe('navigating outside the app on sameorigin', () => { |
There was a problem hiding this comment.
Here I compare browser history between plain web navigation and sveltekit's goto navigation. I claim that browser history should be the same no matter which type of navigation I perform
| [ | ||
| [ | ||
| 'app.goto { replaceState: false }', | ||
| async ({ app }) => { | ||
| await app.goto('/navigation/nonexistent', { replaceState: false }).catch(() => {}); | ||
| } | ||
| ], | ||
| [ | ||
| 'location.assign', | ||
| async ({ page }) => { | ||
| await page.evaluate(() => { | ||
| location.assign('/navigation/nonexistent'); | ||
| }); | ||
| } | ||
| ] | ||
| ].forEach(([title, navigate]) => { | ||
| test(title, async ({ app, page }) => { | ||
| await navigate({ app, page }); | ||
| await page.waitForLoadState('networkidle'); | ||
| expectPath(page).toBe('/navigation/nonexistent'); | ||
|
|
||
| await page.goBack(); | ||
| expectPath(page).toBe('/navigation/teststart'); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
I'm not sure if we need these tests since they already work currently and are the default behaviour.
There was a problem hiding this comment.
yes, but someone could break it? I am not sure if this behaviour is covered by tests somewhere else
| [ | ||
| 'location.replace', | ||
| async ({ page }) => { | ||
| await page.evaluate(() => { | ||
| location.replace('/navigation/nonexistent'); | ||
| }); | ||
| } | ||
| ] |
There was a problem hiding this comment.
I don't think we need the location.replace tests since they only test the browser functionality and nothing on SvelteKit's side.
There was a problem hiding this comment.
with such tests I tried to emphasize, that sveltekit's navigation behaves exactly the same as default browser navigation. In some way, these tests were aimed at you personally, to persuade you in correctness of this changes :)
if you still consider them to be unnecessary - I shall delete them
There was a problem hiding this comment.
please let me know, if you still would like these extra tests to be deleted
| [ | ||
| 'app.goto { replaceState: false }', | ||
| async ({ app }) => { | ||
| await app.goto('/navigation/nonexistent', { replaceState: false }).catch(() => {}); |
There was a problem hiding this comment.
A simpler flow for these tests without the catch handlers could be:
replaceState for external navigation
- Start at
/goto/a - Click a link that navigates to
/goto/b - Click a button that uses
gotowithreplaceState: trueto a non-existent route. - Press the back button
- Expect to see the page contents of
/goto/a
replaceState for redirects
- Start at
/goto/a - Click a link that navigates to
/goto/b - Click a button that uses
gotowithreplaceState: trueto/goto/redirect - The load function of
/goto/redirectshould redirect to/goto/c - Press the back button
- Expect to see the page contents of
/goto/a
Note that we're adding the test routes to /goto since there's already test routes related to goto there.
There was a problem hiding this comment.
right, thank you, I will do just that
teemingc
left a comment
There was a problem hiding this comment.
LGTM but I'll wait for another maintainer to take a look as well
|
@dummdidumm could you please take a look? |
|
Thank you but we can't merge this as it's a breaking change (as evidenced by the changes needed to unrelated tests, namely I'm also just not sure it's desirable. Feels like it would be better to more consistently enforce the rule, spelled out in the docs, that |
fixes #13403
When navigating via goto with
replaceState: truewith full page reload (e.g. navigating outside of the app) the page is not being replaced, but pushed to history insteadThis PR aims to fix that
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Edits