mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-29 09:02:03 +00:00
perf: fixed-length arrays in error and templates
This commit is contained in:
parent
a7dcc6a48c
commit
38b9db2fe4
@ -117,20 +117,31 @@ export const componentsTypeTemplate = {
|
||||
})
|
||||
|
||||
const islandType = 'type IslandComponent<T extends DefineComponent> = T & DefineComponent<{}, {refresh: () => Promise<void>}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, SlotsType<{ fallback: { error: unknown } }>>'
|
||||
const globalSyncComponents: string[] = new Array(componentTypes.length)
|
||||
const globalAsyncComponents: string[] = new Array(componentTypes.length)
|
||||
const globalSyncComponentsExport: string[] = new Array(componentTypes.length)
|
||||
const globalAsyncComponentsExport: string[] = new Array(componentTypes.length)
|
||||
for (let i = 0; i < componentTypes.length; i++) {
|
||||
const [pascalName, type] = componentTypes[i]
|
||||
globalSyncComponents[i] = ` '${pascalName}': ${type}`
|
||||
globalAsyncComponents[i] = ` 'Lazy${pascalName}': ${type}`
|
||||
globalSyncComponentsExport[i] = `export const ${pascalName}: ${type}`
|
||||
globalAsyncComponentsExport[i] = `export const Lazy${pascalName}: ${type}`
|
||||
}
|
||||
return `
|
||||
import type { DefineComponent, SlotsType } from 'vue'
|
||||
${nuxt.options.experimental.componentIslands ? islandType : ''}
|
||||
interface _GlobalComponents {
|
||||
${componentTypes.map(([pascalName, type]) => ` '${pascalName}': ${type}`).join('\n')}
|
||||
${componentTypes.map(([pascalName, type]) => ` 'Lazy${pascalName}': ${type}`).join('\n')}
|
||||
${globalSyncComponents.join('\n')}
|
||||
${globalAsyncComponents.join('\n')}
|
||||
}
|
||||
|
||||
declare module 'vue' {
|
||||
export interface GlobalComponents extends _GlobalComponents { }
|
||||
}
|
||||
|
||||
${componentTypes.map(([pascalName, type]) => `export const ${pascalName}: ${type}`).join('\n')}
|
||||
${componentTypes.map(([pascalName, type]) => `export const Lazy${pascalName}: ${type}`).join('\n')}
|
||||
${globalSyncComponentsExport.join('\n')}
|
||||
${globalAsyncComponentsExport.join('\n')}
|
||||
|
||||
export const componentNames: string[]
|
||||
`
|
||||
|
@ -9,6 +9,13 @@ export default <NitroErrorHandler> async function errorhandler (error: H3Error,
|
||||
// Parse and normalize error
|
||||
const { stack, statusCode, statusMessage, message } = normalizeError(error)
|
||||
|
||||
const errorStack: string[] = new Array(stack.length)
|
||||
const consoleStack: string[] = new Array(stack.length)
|
||||
for (let count = 0; count < stack.length; count++) {
|
||||
const i = stack[count]!
|
||||
errorStack[count] = `<span class="stack${i.internal ? ' internal' : ''}">${i.text}</span>`
|
||||
consoleStack[count] = ' ' + i.text
|
||||
}
|
||||
// Create an error object
|
||||
const errorObject = {
|
||||
url: event.path,
|
||||
@ -16,7 +23,7 @@ export default <NitroErrorHandler> async function errorhandler (error: H3Error,
|
||||
statusMessage,
|
||||
message,
|
||||
stack: import.meta.dev && statusCode !== 404
|
||||
? `<pre>${stack.map(i => `<span class="stack${i.internal ? ' internal' : ''}">${i.text}</span>`).join('\n')}</pre>`
|
||||
? `<pre>${errorStack.join('\n')}</pre>`
|
||||
: '',
|
||||
// TODO: check and validate error.data for serialisation into query
|
||||
data: error.data as any,
|
||||
@ -31,7 +38,7 @@ export default <NitroErrorHandler> async function errorhandler (error: H3Error,
|
||||
error.fatal && '[fatal]',
|
||||
Number(errorObject.statusCode) !== 200 && `[${errorObject.statusCode}]`,
|
||||
].filter(Boolean).join(' ')
|
||||
console.error(tags, (error.message || error.toString() || 'internal server error') + '\n' + stack.map(l => ' ' + l.text).join(' \n'))
|
||||
console.error(tags, (error.message || error.toString() || 'internal server error') + '\n' + consoleStack.join(' \n'))
|
||||
}
|
||||
|
||||
if (event.handled) { return }
|
||||
|
Loading…
Reference in New Issue
Block a user