Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
fix(nuxt): lazy load and tree-shake error templates (#5930)
Browse files Browse the repository at this point in the history
Co-authored-by: Pooya Parsa <pooya@pi0.io>
Co-authored-by: Kevin Marrec <kevin@marrec.io>
  • Loading branch information
3 people authored Jul 15, 2022
1 parent a54925f commit dce07e5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
16 changes: 10 additions & 6 deletions packages/nuxt/src/app/components/nuxt-error-page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
</template>

<script setup>
import Error404 from '@nuxt/ui-templates/templates/error-404.vue'
import Error500 from '@nuxt/ui-templates/templates/error-500.vue'
import ErrorDev from '@nuxt/ui-templates/templates/error-dev.vue'
import { defineAsyncComponent } from 'vue'
const props = defineProps({
error: Object
Expand All @@ -25,8 +23,8 @@ const stacktrace = (error.stack || '')
return {
text,
internal: (line.includes('node_modules') && !line.includes('.cache')) ||
line.includes('internal') ||
line.includes('new Promise')
line.includes('internal') ||
line.includes('new Promise')
}
}).map(i => `<span class="stack${i.internal ? ' internal' : ''}">${i.text}</span>`).join('\n')
Expand All @@ -38,5 +36,11 @@ const statusMessage = error.statusMessage ?? (is404 ? 'Page Not Found' : 'Intern
const description = error.message || error.toString()
const stack = process.dev && !is404 ? error.description || `<pre>${stacktrace}</pre>` : undefined
const ErrorTemplate = is404 ? Error404 : process.dev ? ErrorDev : Error500
// TODO: Investigate side-effect issue with imports
const _Error404 = defineAsyncComponent(() => import('@nuxt/ui-templates/templates/error-404.vue'))
const _Error = process.dev
? defineAsyncComponent(() => import('@nuxt/ui-templates/templates/error-dev.vue'))
: defineAsyncComponent(() => import('@nuxt/ui-templates/templates/error-500.vue'))
const ErrorTemplate = is404 ? _Error404 : _Error
</script>
6 changes: 3 additions & 3 deletions packages/nuxt/src/app/components/nuxt-root.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
</template>

<script setup>
import { onErrorCaptured } from 'vue'
import { defineAsyncComponent, onErrorCaptured } from 'vue'
import { callWithNuxt, throwError, useError, useNuxtApp } from '#app'
// @ts-ignore
import ErrorComponent from '#build/error-component.mjs'
const ErrorComponent = defineAsyncComponent(() => import('#build/error-component.mjs'))
const nuxtApp = useNuxtApp()
const onResolve = () => nuxtApp.callHook('app:suspense:resolve')
Expand Down

0 comments on commit dce07e5

Please sign in to comment.