fix(bridge, kit): don't modify template array whilst traversing it (#2244)

This commit is contained in:
Daniel Roe 2021-12-01 11:58:07 +00:00 committed by GitHub
parent 6e719d6977
commit d52acbffd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -69,13 +69,10 @@ export function defineNuxtModule<OptionsT extends ModuleOptions> (input: NuxtMod
// Support virtual templates with getContents() by writing them to .nuxt directory // Support virtual templates with getContents() by writing them to .nuxt directory
let virtualTemplates: NuxtTemplate[] let virtualTemplates: NuxtTemplate[]
nuxt.hook('builder:prepared', (_builder, buildOptions) => { nuxt.hook('builder:prepared', (_builder, buildOptions) => {
virtualTemplates = [] virtualTemplates = buildOptions.templates.filter(t => t.getContents)
buildOptions.templates.forEach((template, index, arr) => { for (const template of virtualTemplates) {
if (!template.getContents) { return } buildOptions.templates.splice(buildOptions.templates.indexOf(template), 1)
// Remove template from template array to handle it ourselves }
arr.splice(index, 1)
virtualTemplates.push(template)
})
}) })
nuxt.hook('build:templates', async (templates) => { nuxt.hook('build:templates', async (templates) => {
const context = { const context = {