mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
fix(vue-renderer): improve ready handling (#4511)
This commit is contained in:
parent
6d8aeec81c
commit
f0cb654a5d
@ -104,11 +104,24 @@ export default class VueRenderer {
|
||||
}
|
||||
|
||||
async ready() {
|
||||
if (!this.context.options.dev) {
|
||||
// Production: Load SSR resources from fs
|
||||
// -- Development mode --
|
||||
|
||||
if (this.context.options.dev) {
|
||||
this.context.nuxt.hook('build:resources', mfs => this.loadResources(mfs, true))
|
||||
return
|
||||
}
|
||||
|
||||
// -- Production mode --
|
||||
|
||||
// Try once to load SSR resources from fs
|
||||
await this.loadResources(fs)
|
||||
|
||||
// Verify
|
||||
// Without using`nuxt start` (Programatic, Tests and Generate)
|
||||
if (!this.context.options._start) {
|
||||
this.context.nuxt.hook('build:resources', () => this.loadResources(fs))
|
||||
}
|
||||
|
||||
// Verify resources
|
||||
if (this.context.options._start) {
|
||||
if (!this.isReady) {
|
||||
throw new Error(
|
||||
@ -120,10 +133,6 @@ export default class VueRenderer {
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Development: Listen on build:resources hook
|
||||
this.context.nuxt.hook('build:resources', mfs => this.loadResources(mfs, true))
|
||||
}
|
||||
}
|
||||
|
||||
loadResources(_fs, isMFS = false) {
|
||||
@ -280,12 +289,16 @@ export default class VueRenderer {
|
||||
return fn(opts)
|
||||
}
|
||||
|
||||
async renderRoute(url, context = {}) {
|
||||
async renderRoute(url, context = {}, retries = 5) {
|
||||
/* istanbul ignore if */
|
||||
if (!this.isReady) {
|
||||
if (this.context.options.dev && retries > 0) {
|
||||
consola.info('Waiting for server resources...')
|
||||
await waitFor(1000)
|
||||
return this.renderRoute(url, context)
|
||||
return this.renderRoute(url, context, retries - 1)
|
||||
} else {
|
||||
throw new Error('Server resources are not available!')
|
||||
}
|
||||
}
|
||||
|
||||
// Log rendered url
|
||||
|
Loading…
Reference in New Issue
Block a user