Browse Source

Merge pull request #8701 from nocodb/nc-fix/nuxt-lazy-load-chunk-error

fix: add a nuxt plugin to handle chunk error
pull/8706/head
Pranav C 6 months ago committed by GitHub
parent
commit
7a4659a46a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 17
      packages/nc-gui/plugins/error-handler.ts

17
packages/nc-gui/plugins/error-handler.ts

@ -0,0 +1,17 @@
// ref - https://github.com/nuxt/nuxt/issues/26565
export default defineNuxtPlugin((nuxtApp) => {
const MAX_RETRIES = 2
const QUERY_PARAM_NAME = 'reload_attempt'
// Handle "Failed to fetch dynamically imported module ..." or similar issues
nuxtApp.hook('app:chunkError', () => {
const searchParams = new URLSearchParams(window.location.search)
const currentRetry = Number(searchParams.get(QUERY_PARAM_NAME)) || 0
if (currentRetry < MAX_RETRIES) {
console.log('[nuxt]: Reloading due to chunk error')
searchParams.set(QUERY_PARAM_NAME, (currentRetry + 1).toString())
// Changing the search also causes a refresh
window.location.search = searchParams.toString()
}
})
})
Loading…
Cancel
Save