mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Move ensurePage to DevServer (#5582)
It's no longer needed inside the `render()` function since we have a separate devServer
This commit is contained in:
parent
1496ad6299
commit
a1bdbad2cf
|
@ -24,8 +24,6 @@ function getDynamicImportBundles (manifest, moduleIds) {
|
|||
}, [])
|
||||
}
|
||||
|
||||
const logger = console
|
||||
|
||||
// since send doesn't support wasm yet
|
||||
send.mime.define({ 'application/wasm': ['wasm'] })
|
||||
|
||||
|
@ -63,7 +61,6 @@ async function doRender (req, res, pathname, query, {
|
|||
err,
|
||||
page,
|
||||
buildId,
|
||||
hotReloader,
|
||||
assetPrefix,
|
||||
runtimeConfig,
|
||||
distDir,
|
||||
|
@ -74,11 +71,6 @@ async function doRender (req, res, pathname, query, {
|
|||
} = {}) {
|
||||
page = page || pathname
|
||||
|
||||
// In dev mode we use on demand entries to compile the page before rendering
|
||||
if (hotReloader) {
|
||||
await hotReloader.ensurePage(page)
|
||||
}
|
||||
|
||||
const documentPath = join(distDir, SERVER_DIRECTORY, CLIENT_STATIC_FILES_PATH, buildId, 'pages', '_document')
|
||||
const appPath = join(distDir, SERVER_DIRECTORY, CLIENT_STATIC_FILES_PATH, buildId, 'pages', '_app')
|
||||
let [buildManifest, reactLoadableManifest, Component, Document, App] = await Promise.all([
|
||||
|
@ -203,7 +195,7 @@ export async function renderScriptError (req, res, page, error) {
|
|||
return
|
||||
}
|
||||
|
||||
logger.error(error.stack)
|
||||
console.error(error.stack)
|
||||
res.statusCode = 500
|
||||
res.end('500 - Internal Error')
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ export default class DevServer extends Server {
|
|||
constructor (options) {
|
||||
super(options)
|
||||
this.hotReloader = new HotReloader(this.dir, { config: this.nextConfig, buildId: this.buildId })
|
||||
this.renderOpts.hotReloader = this.hotReloader
|
||||
this.renderOpts.dev = true
|
||||
}
|
||||
|
||||
|
@ -90,6 +89,17 @@ export default class DevServer extends Server {
|
|||
return this.renderErrorToHTML(compilationErr, req, res, pathname, query)
|
||||
}
|
||||
|
||||
// In dev mode we use on demand entries to compile the page before rendering
|
||||
try {
|
||||
await this.hotReloader.ensurePage(pathname)
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
res.statusCode = 404
|
||||
return this.renderErrorToHTML(null, req, res, pathname, query)
|
||||
}
|
||||
if (!this.quiet) console.error(err)
|
||||
}
|
||||
|
||||
return super.renderToHTML(req, res, pathname, query)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue