mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 22:25:12 +00:00
refator: only throw jsdomerror in window initialization
This commit is contained in:
parent
d6f22c904d
commit
d9d747c9a8
@ -421,12 +421,18 @@ module.exports = class Renderer {
|
|||||||
window.scrollTo = () => {}
|
window.scrollTo = () => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const jsdomErrHandler = err => { throw err }
|
||||||
if (opts.virtualConsole !== false) {
|
if (opts.virtualConsole !== false) {
|
||||||
options.virtualConsole = new jsdom.VirtualConsole().sendTo(console, { omitJSDOMErrors: true })
|
options.virtualConsole = new jsdom.VirtualConsole().sendTo(console, { omitJSDOMErrors: false })
|
||||||
options.virtualConsole.on('jsdomError', err => { throw err })
|
// throw error when window creation failed
|
||||||
|
options.virtualConsole.on('jsdomError', jsdomErrHandler)
|
||||||
}
|
}
|
||||||
url = url || 'http://localhost:3000'
|
url = url || 'http://localhost:3000'
|
||||||
const { window } = await jsdom.JSDOM.fromURL(url, options)
|
const { window } = await jsdom.JSDOM.fromURL(url, options)
|
||||||
|
if (opts.virtualConsole !== false) {
|
||||||
|
// after window initialized successfully
|
||||||
|
options.virtualConsole.removeListener('jsdomError', jsdomErrHandler)
|
||||||
|
}
|
||||||
// If Nuxt could not be loaded (error from the server-side)
|
// If Nuxt could not be loaded (error from the server-side)
|
||||||
const nuxtExists = window.document.body.innerHTML.includes(
|
const nuxtExists = window.document.body.innerHTML.includes(
|
||||||
this.options.render.ssr ? 'window.__NUXT__' : '<div id="__nuxt">'
|
this.options.render.ssr ? 'window.__NUXT__' : '<div id="__nuxt">'
|
||||||
|
Loading…
Reference in New Issue
Block a user