-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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 browser back issue of redirects from getServerSideProps / getStaticProps #17741
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -123,6 +123,10 @@ const runTests = () => { | |
window.next.router.push('/gssp-blog/redirect-dest-_another') | ||
})()`) | ||
await browser.waitForElementByCss('#another') | ||
|
||
const text = await browser.elementByCss('#another').text() | ||
|
||
expect(text).toEqual('another Page') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In first commit, I added them to the existing test cases because there are no any "expect" functions. |
||
}) | ||
|
||
it('should apply redirect when GSSP page is navigated to client-side (external)', async () => { | ||
|
@@ -149,6 +153,10 @@ const runTests = () => { | |
window.next.router.push('/gsp-blog/redirect-dest-_another') | ||
})()`) | ||
await browser.waitForElementByCss('#another') | ||
|
||
const text = await browser.elementByCss('#another').text() | ||
|
||
expect(text).toEqual('another Page') | ||
}) | ||
|
||
it('should apply redirect when GSP page is navigated to client-side (external)', async () => { | ||
|
@@ -167,6 +175,94 @@ const runTests = () => { | |
}, | ||
}) | ||
}) | ||
|
||
it('should not replace history of the origin page when GSSP page is navigated to client-side (internal normal)', async () => { | ||
const browser = await webdriver(appPort, '/another?mark_as=root') | ||
|
||
await browser.eval(`(function () { | ||
window.location.href = '/' | ||
})()`) | ||
await browser.waitForElementByCss('#index') | ||
|
||
await browser.eval(`(function () { | ||
window.next.router.push('/gssp-blog/redirect-dest-_another') | ||
})()`) | ||
await browser.waitForElementByCss('#another') | ||
|
||
await browser.eval(`(function () { | ||
window.history.back() | ||
})()`) | ||
|
||
const curUrl = await browser.url() | ||
const { path } = url.parse(curUrl) | ||
expect(path).toEqual('/') | ||
}) | ||
|
||
it('should not replace history of the origin page when GSSP page is navigated to client-side (external)', async () => { | ||
const browser = await webdriver(appPort, '/another?mark_as=root') | ||
|
||
await browser.eval(`(function () { | ||
window.location.href = '/' | ||
})()`) | ||
await browser.waitForElementByCss('#index') | ||
|
||
await browser.eval(`(function () { | ||
window.next.router.push('/gssp-blog/redirect-dest-_gssp-blog_first') | ||
})()`) | ||
await browser.waitForElementByCss('#gssp') | ||
|
||
await browser.eval(`(function () { | ||
window.history.back() | ||
})()`) | ||
|
||
const curUrl = await browser.url() | ||
const { path } = url.parse(curUrl) | ||
expect(path).toEqual('/') | ||
}) | ||
|
||
it('should not replace history of the origin page when GSP page is navigated to client-side (internal)', async () => { | ||
const browser = await webdriver(appPort, '/another?mark_as=root') | ||
|
||
await browser.eval(`(function () { | ||
window.location.href = '/' | ||
})()`) | ||
await browser.waitForElementByCss('#index') | ||
|
||
await browser.eval(`(function () { | ||
window.next.router.push('/gsp-blog/redirect-dest-_another') | ||
})()`) | ||
await browser.waitForElementByCss('#another') | ||
|
||
await browser.eval(`(function () { | ||
window.history.back() | ||
})()`) | ||
|
||
const curUrl = await browser.url() | ||
const { path } = url.parse(curUrl) | ||
expect(path).toEqual('/') | ||
}) | ||
|
||
it('should not replace history of the origin page when GSP page is navigated to client-side (external)', async () => { | ||
const browser = await webdriver(appPort, '/another?mark_as=root') | ||
|
||
await browser.eval(`(function () { | ||
window.location.href = '/' | ||
})()`) | ||
await browser.waitForElementByCss('#index') | ||
|
||
await browser.eval(`(function () { | ||
window.next.router.push('/gsp-blog/redirect-dest-_gsp-blog_first') | ||
})()`) | ||
await browser.waitForElementByCss('#gsp') | ||
|
||
await browser.eval(`(function () { | ||
window.history.back() | ||
})()`) | ||
|
||
const curUrl = await browser.url() | ||
const { path } = url.parse(curUrl) | ||
expect(path).toEqual('/') | ||
}) | ||
} | ||
|
||
describe('GS(S)P Redirect Support', () => { | ||
|
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.
In previous code, this replaced history of the origin page not the one with redirect settings with new page. So, I think it is better to use "pushState" for client-side navigation and use "replaceState" in the only case of first navigation of SSG.