mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +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 = () => {}
|
||||
}
|
||||
}
|
||||
const jsdomErrHandler = err => { throw err }
|
||||
if (opts.virtualConsole !== false) {
|
||||
options.virtualConsole = new jsdom.VirtualConsole().sendTo(console, { omitJSDOMErrors: true })
|
||||
options.virtualConsole.on('jsdomError', err => { throw err })
|
||||
options.virtualConsole = new jsdom.VirtualConsole().sendTo(console, { omitJSDOMErrors: false })
|
||||
// throw error when window creation failed
|
||||
options.virtualConsole.on('jsdomError', jsdomErrHandler)
|
||||
}
|
||||
url = url || 'http://localhost:3000'
|
||||
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)
|
||||
const nuxtExists = window.document.body.innerHTML.includes(
|
||||
this.options.render.ssr ? 'window.__NUXT__' : '<div id="__nuxt">'
|
||||
|
Loading…
Reference in New Issue
Block a user