mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Remove all the inline code.
This commit is contained in:
parent
822a99b0d5
commit
76bfc38a09
|
@ -35,7 +35,15 @@ if (window.NEXT_LOADED_PAGES) {
|
|||
}
|
||||
|
||||
const ErrorComponent = pageLoader.loadPageSync('/_error')
|
||||
const Component = pageLoader.loadPageSync(pathname) || ErrorComponent
|
||||
let Component
|
||||
|
||||
try {
|
||||
Component = pageLoader.loadPageSync(pathname)
|
||||
} catch (err) {
|
||||
console.error(`${err.message}\n${err.stack}`)
|
||||
Component = ErrorComponent
|
||||
}
|
||||
|
||||
let lastAppProps
|
||||
|
||||
export const router = createRouter(pathname, query, getURL(), {
|
||||
|
|
|
@ -95,25 +95,16 @@ export class NextScript extends Component {
|
|||
return this.getChunkScript('app.js', { async: true })
|
||||
}
|
||||
|
||||
getMainComponents () {
|
||||
const { component, errorComponent } = this.context._documentProps
|
||||
|
||||
return (
|
||||
<div>
|
||||
<script dangerouslySetInnerHTML={{ __html: component }} />
|
||||
<script dangerouslySetInnerHTML={{ __html: errorComponent }} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
render () {
|
||||
const { staticMarkup, __NEXT_DATA__ } = this.context._documentProps
|
||||
const { pathname, buildId } = __NEXT_DATA__
|
||||
|
||||
return <div>
|
||||
{staticMarkup ? null : <script dangerouslySetInnerHTML={{
|
||||
__html: `__NEXT_DATA__ = ${htmlescape(__NEXT_DATA__)}; module={};`
|
||||
}} />}
|
||||
{staticMarkup ? null : this.getMainComponents()}
|
||||
<script type='text/javascript' src={`/_next/${buildId}/page${pathname}`} />
|
||||
<script type='text/javascript' src={`/_next/${buildId}/page/_error`} />
|
||||
{staticMarkup ? null : this.getScripts()}
|
||||
</div>
|
||||
}
|
||||
|
|
|
@ -114,6 +114,18 @@ export default class Server {
|
|||
await this.serveStatic(req, res, p)
|
||||
},
|
||||
|
||||
'/_next/:buildId/page/_error': async (req, res, params) => {
|
||||
if (!this.handleBuildId(params.buildId, res)) {
|
||||
const error = new Error('INVALID_BUILD_ID')
|
||||
const customFields = { buildIdMismatched: true }
|
||||
|
||||
return await renderScriptError(req, res, '/_error', error, customFields, this.renderOpts)
|
||||
}
|
||||
|
||||
const p = join(this.dir, '.next/client-bundles/pages/_error.js')
|
||||
await this.serveStatic(req, res, p)
|
||||
},
|
||||
|
||||
'/_next/:buildId/page/:path*': async (req, res, params) => {
|
||||
const paths = params.path || ['']
|
||||
const page = `/${paths.join('/')}`
|
||||
|
|
|
@ -131,10 +131,19 @@ export async function renderScriptError (req, res, page, error, customFields, op
|
|||
if (error.code === 'ENOENT') {
|
||||
res.setHeader('Content-Type', 'text/javascript')
|
||||
res.end(`
|
||||
var error = new Error('Page not exists: ${page}')
|
||||
error.pageNotFound = true
|
||||
error.statusCode = 404
|
||||
NEXT_PAGE_LOADER.registerPage('${page}', error)
|
||||
function loadPage () {
|
||||
var error = new Error('Page not exists: ${page}')
|
||||
error.pageNotFound = true
|
||||
error.statusCode = 404
|
||||
NEXT_PAGE_LOADER.registerPage('${page}', error)
|
||||
}
|
||||
|
||||
if (window.NEXT_PAGE_LOADER) {
|
||||
loadPage()
|
||||
} else {
|
||||
window.NEXT_LOADED_PAGES = window.NEXT_LOADED_PAGES || []
|
||||
window.NEXT_LOADED_PAGES.push(loadPage)
|
||||
}
|
||||
`)
|
||||
return
|
||||
}
|
||||
|
@ -146,8 +155,17 @@ export async function renderScriptError (req, res, page, error, customFields, op
|
|||
}
|
||||
|
||||
res.end(`
|
||||
var error = ${JSON.stringify(errorJson)}
|
||||
NEXT_PAGE_LOADER.registerPage('${page}', error)
|
||||
function loadPage () {
|
||||
var error = ${JSON.stringify(errorJson)}
|
||||
NEXT_PAGE_LOADER.registerPage('${page}', error)
|
||||
}
|
||||
|
||||
if (window.NEXT_PAGE_LOADER) {
|
||||
loadPage()
|
||||
} else {
|
||||
window.NEXT_LOADED_PAGES = window.NEXT_LOADED_PAGES || []
|
||||
window.NEXT_LOADED_PAGES.push(loadPage)
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue