-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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(vue-app): skip page render early on error or navigation #20719
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9d44f0e
fix(vue-app): interrupt page render early on error or navigating away
rchl d0aab15
pass renderState when spa-handling
rchl 3453ceb
remove accidental addition
rchl 8edd4a3
in dev, when calling $forceUpdate, we don't have renderState and thatβ¦
rchl eaa021c
Merge branch '2.x' into fix/slow-middleware-navigate
rchl File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
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,68 @@ | ||
import Browser from '../utils/browser' | ||
import { loadFixture, getPort, Nuxt, waitFor } from '../utils' | ||
|
||
let port | ||
const browser = new Browser() | ||
const url = route => 'http://localhost:' + port + route | ||
|
||
let nuxt = null | ||
let page = null | ||
|
||
describe('basic browser navigation', () => { | ||
beforeAll(async () => { | ||
const config = await loadFixture('basic') | ||
nuxt = new Nuxt(config) | ||
await nuxt.ready() | ||
|
||
port = await getPort() | ||
await nuxt.server.listen(port, 'localhost') | ||
|
||
await browser.start({ | ||
// slowMo: 50, | ||
// headless: false | ||
}) | ||
}) | ||
|
||
const TEST_PATHS = [ | ||
'asyncData-error', | ||
'asyncData-throw', | ||
'middleware-asyncData-error', | ||
'middleware-asyncData-throw' | ||
] | ||
|
||
for (const path of TEST_PATHS) { | ||
test(`Navigate away from /navigation/${path}`, async () => { | ||
page = await browser.page(url('/')) | ||
expect(await page.$text('h1')).toBe('Index page') | ||
|
||
await page.nuxt.navigate('/navigation') | ||
expect(await page.$text('h3')).toContain('Click one of the links below') | ||
|
||
await page.nuxt.navigate(`/navigation/${path}`, /* waitEnd */false) | ||
await waitFor(nuxt.options.loading.throttle + 100) | ||
const loading = await page.nuxt.loadingData() | ||
expect(loading.show).toBe(true) | ||
|
||
await page.nuxt.go(-1) | ||
await page.waitForFunction( | ||
'$nuxt.$loading.$data.show === false' | ||
) | ||
expect(await page.$text('h1')).toBe('Index page') | ||
|
||
await waitFor(2000) | ||
|
||
expect(await page.$text('h1')).toBe('Index page') | ||
}) | ||
} | ||
|
||
// Close server and ask nuxt to stop listening to file changes | ||
afterAll(async () => { | ||
await nuxt.close() | ||
}) | ||
|
||
// Stop browser | ||
afterAll(async () => { | ||
await page.close() | ||
await browser.close() | ||
}) | ||
}) |
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,3 @@ | ||
export default async function () { | ||
await new Promise(resolve => setTimeout(resolve, 2000)) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<template> | ||
<div> | ||
<h3>Click one of the links below and navigate back in history before the page has fully loaded. Pass if no error page shown.</h3> | ||
<ul> | ||
<li v-for="test in tests" :key="test"> | ||
<nuxt-link :to="'navigation/' + test"> | ||
{{ test }} | ||
</nuxt-link> | ||
</li> | ||
</ul> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
computed: { | ||
tests () { | ||
return [ | ||
'asyncData-error', | ||
'asyncData-throw', | ||
'middleware-asyncData-error', | ||
'middleware-asyncData-throw' | ||
] | ||
} | ||
} | ||
} | ||
</script> |
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 @@ | ||
<template> | ||
<h1>Async Data Error</h1> | ||
</template> | ||
<script> | ||
export default { | ||
async asyncData ({ error }) { | ||
await new Promise(resolve => setTimeout(resolve, 2000)) | ||
error({ statusCode: 401, message: 'Not allowed here' }) | ||
} | ||
} | ||
</script> |
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 @@ | ||
<template> | ||
<h1>Async Throw Error</h1> | ||
</template> | ||
<script> | ||
export default { | ||
async asyncData () { | ||
await new Promise(resolve => setTimeout(resolve, 2000)) | ||
throw new Error('crash') | ||
} | ||
} | ||
</script> |
11 changes: 11 additions & 0 deletions
11
test/fixtures/basic/pages/navigation/middleware-asyncData-error.vue
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 @@ | ||
<template> | ||
<h1>Async Data Error</h1> | ||
</template> | ||
<script> | ||
export default { | ||
middleware: ['slow'], | ||
asyncData ({ error, route }) { | ||
error({ statusCode: 401, message: 'Not allowed here' }) | ||
} | ||
} | ||
</script> |
11 changes: 11 additions & 0 deletions
11
test/fixtures/basic/pages/navigation/middleware-asyncData-throw.vue
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 @@ | ||
<template> | ||
<h1>Async Throw Error</h1> | ||
</template> | ||
<script> | ||
export default { | ||
middleware: ['slow'], | ||
asyncData () { | ||
throw new Error('crash') | ||
} | ||
} | ||
</script> |
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 have not put too much thought into that part of the code (the SPA case). I could look more if needed but it could be just left like that, without supporting early abort.