mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Remove Unneeded _error import (#6224)
This commit is contained in:
parent
cc0b3ef451
commit
28b61a8c94
|
@ -15,19 +15,19 @@ type ComponentsEnhancer = {enhanceApp?: Enhancer, enhanceComponent?: Enhancer}|E
|
|||
|
||||
function enhanceComponents(options: ComponentsEnhancer, App: React.ComponentType, Component: React.ComponentType): {
|
||||
App: React.ComponentType,
|
||||
Component: React.ComponentType
|
||||
Component: React.ComponentType,
|
||||
} {
|
||||
// For backwards compatibility
|
||||
if(typeof options === 'function') {
|
||||
if (typeof options === 'function') {
|
||||
return {
|
||||
App: App,
|
||||
Component: options(Component)
|
||||
App,
|
||||
Component: options(Component),
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
App: options.enhanceApp ? options.enhanceApp(App) : App,
|
||||
Component: options.enhanceComponent ? options.enhanceComponent(Component) : Component
|
||||
Component: options.enhanceComponent ? options.enhanceComponent(Component) : Component,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ type RenderOpts = {
|
|||
Component: React.ComponentType,
|
||||
Document: React.ComponentType,
|
||||
App: React.ComponentType,
|
||||
ErrorDebug?: React.ComponentType<{error: Error}>
|
||||
ErrorDebug?: React.ComponentType<{error: Error}>,
|
||||
}
|
||||
|
||||
function renderDocument(Document: React.ComponentType, {
|
||||
|
@ -97,7 +97,7 @@ function renderDocument(Document: React.ComponentType, {
|
|||
runtimeConfig, // runtimeConfig if provided, otherwise don't sent in the resulting HTML
|
||||
nextExport, // If this is a page exported by `next export`
|
||||
dynamicIds: dynamicImportsIds.length === 0 ? undefined : dynamicImportsIds,
|
||||
err: (err) ? serializeError(dev, err) : undefined // Error if one happened, otherwise don't sent in the resulting HTML
|
||||
err: (err) ? serializeError(dev, err) : undefined, // Error if one happened, otherwise don't sent in the resulting HTML
|
||||
}}
|
||||
staticMarkup={staticMarkup}
|
||||
devFiles={devFiles}
|
||||
|
@ -105,11 +105,11 @@ function renderDocument(Document: React.ComponentType, {
|
|||
dynamicImports={dynamicImports}
|
||||
assetPrefix={assetPrefix}
|
||||
{...docProps}
|
||||
/>
|
||||
/>,
|
||||
)
|
||||
}
|
||||
|
||||
export async function renderToHTML (req: IncomingMessage, res: ServerResponse, pathname: string, query: ParsedUrlQuery, renderOpts: RenderOpts): Promise<string|null> {
|
||||
export async function renderToHTML(req: IncomingMessage, res: ServerResponse, pathname: string, query: ParsedUrlQuery, renderOpts: RenderOpts): Promise<string|null> {
|
||||
const {
|
||||
err,
|
||||
dev = false,
|
||||
|
@ -119,10 +119,9 @@ export async function renderToHTML (req: IncomingMessage, res: ServerResponse, p
|
|||
Component,
|
||||
buildManifest,
|
||||
reactLoadableManifest,
|
||||
ErrorDebug
|
||||
ErrorDebug,
|
||||
} = renderOpts
|
||||
|
||||
|
||||
await Loadable.preloadAll() // Make sure all dynamic imports are loaded
|
||||
|
||||
if (dev) {
|
||||
|
@ -153,15 +152,14 @@ export async function renderToHTML (req: IncomingMessage, res: ServerResponse, p
|
|||
...new Set([
|
||||
...getPageFiles(buildManifest, pathname),
|
||||
...getPageFiles(buildManifest, '/_app'),
|
||||
...getPageFiles(buildManifest, '/_error')
|
||||
])
|
||||
]),
|
||||
]
|
||||
|
||||
const reactLoadableModules: string[] = []
|
||||
const renderPage = (options: ComponentsEnhancer = {}): {html: string, head: any} => {
|
||||
const renderElementToString = staticMarkup ? renderToStaticMarkup : renderToString
|
||||
|
||||
if(err && ErrorDebug) {
|
||||
if (err && ErrorDebug) {
|
||||
return render(renderElementToString, <ErrorDebug error={err} />)
|
||||
}
|
||||
|
||||
|
@ -174,7 +172,7 @@ export async function renderToHTML (req: IncomingMessage, res: ServerResponse, p
|
|||
router={router}
|
||||
{...props}
|
||||
/>
|
||||
</LoadableCapture>
|
||||
</LoadableCapture>,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -194,16 +192,16 @@ export async function renderToHTML (req: IncomingMessage, res: ServerResponse, p
|
|||
dynamicImportsIds,
|
||||
dynamicImports,
|
||||
files,
|
||||
devFiles
|
||||
devFiles,
|
||||
})
|
||||
}
|
||||
|
||||
function errorToJSON (err: Error): Error {
|
||||
function errorToJSON(err: Error): Error {
|
||||
const { name, message, stack } = err
|
||||
return { name, message, stack }
|
||||
}
|
||||
|
||||
function serializeError (dev: boolean|undefined, err: Error): Error & {statusCode?: number} {
|
||||
function serializeError(dev: boolean|undefined, err: Error): Error & {statusCode?: number} {
|
||||
if (dev) {
|
||||
return errorToJSON(err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue