mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
Merge pull request #2950 from clarkdo/jsdomError
fix: throw jsdomError to avoid renderAndGetWindow hanging
This commit is contained in:
commit
bb5a604c1b
@ -421,8 +421,11 @@ module.exports = class Renderer {
|
||||
window.scrollTo = () => {}
|
||||
}
|
||||
}
|
||||
const jsdomErrHandler = err => { throw err }
|
||||
if (opts.virtualConsole !== false) {
|
||||
options.virtualConsole = new jsdom.VirtualConsole().sendTo(console)
|
||||
// throw error when window creation failed
|
||||
options.virtualConsole.on('jsdomError', jsdomErrHandler)
|
||||
}
|
||||
url = url || 'http://localhost:3000'
|
||||
const { window } = await jsdom.JSDOM.fromURL(url, options)
|
||||
@ -440,6 +443,10 @@ module.exports = class Renderer {
|
||||
await new Promise(resolve => {
|
||||
window._onNuxtLoaded = () => resolve(window)
|
||||
})
|
||||
if (opts.virtualConsole !== false) {
|
||||
// after window initialized successfully
|
||||
options.virtualConsole.removeListener('jsdomError', jsdomErrHandler)
|
||||
}
|
||||
// Send back window object
|
||||
return window
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user