-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
fix: do not create unwanted record in history when redirecting after an invalidation #11895
Closed
konstantinov90
wants to merge
7
commits into
sveltejs:main
from
konstantinov90:redirect-after-invalidate
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e5c1bd3
fix redirect after invalidate
edc0bd5
fix lint
5ea5240
changeset
acc4772
Merge branch 'main' into pr/konstantinov90/11895
eltigerchino 98e2cf3
cleanup test
eltigerchino 5cb602f
move test
eltigerchino 0a07b1f
prettier
eltigerchino File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@sveltejs/kit": patch | ||
--- | ||
|
||
fix: redirect loop after invalidate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/kit/test/apps/basics/src/routes/redirect/app-with-auth/+layout.server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export async function load({ cookies }) { | ||
return { | ||
loggedIn: cookies.get('logged_in') === '1' | ||
}; | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/kit/test/apps/basics/src/routes/redirect/app-with-auth/+page.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>App with authorization</h1> | ||
<a href="/redirect/app-with-auth/main" data-testid="enter"> enter </a> |
10 changes: 10 additions & 0 deletions
10
packages/kit/test/apps/basics/src/routes/redirect/app-with-auth/main/+page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { redirect } from '@sveltejs/kit'; | ||
|
||
export async function load({ parent }) { | ||
const { loggedIn } = await parent(); | ||
if (!loggedIn) { | ||
redirect(302, '/redirect/app-with-auth/signin'); | ||
} | ||
|
||
return {}; | ||
} |
1 change: 1 addition & 0 deletions
1
packages/kit/test/apps/basics/src/routes/redirect/app-with-auth/main/+page.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>main</h1> |
10 changes: 10 additions & 0 deletions
10
packages/kit/test/apps/basics/src/routes/redirect/app-with-auth/signin/+page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { redirect } from '@sveltejs/kit'; | ||
|
||
export async function load({ parent }) { | ||
const { loggedIn } = await parent(); | ||
if (loggedIn) { | ||
redirect(302, '/redirect/app-with-auth/main'); | ||
} | ||
|
||
return {}; | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/kit/test/apps/basics/src/routes/redirect/app-with-auth/signin/+page.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script> | ||
import { invalidateAll } from '$app/navigation'; | ||
|
||
function login() { | ||
document.cookie = 'logged_in=1;path=/redirect/app-with-auth'; | ||
invalidateAll(); | ||
} | ||
</script> | ||
|
||
<h1>signin</h1> | ||
<button on:click={login} data-testid="login"> login </button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is right. If the result is a redirect, we do want to create a history entry for the redirect. Can you can explain why you've made this change here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, you don't want to create a history entry, because
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. So we want the intermediate navigations to not create history entries. Is that correct? But the final navigation should still create a history entry?