From d52acbffd828e399e698f50df66cd0adab2a9796 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 1 Dec 2021 11:58:07 +0000 Subject: [PATCH] fix(bridge, kit): don't modify template array whilst traversing it (#2244) --- packages/kit/src/module/define.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/kit/src/module/define.ts b/packages/kit/src/module/define.ts index 01fc9ebd04..0129b57da1 100644 --- a/packages/kit/src/module/define.ts +++ b/packages/kit/src/module/define.ts @@ -69,13 +69,10 @@ export function defineNuxtModule (input: NuxtMod // Support virtual templates with getContents() by writing them to .nuxt directory let virtualTemplates: NuxtTemplate[] nuxt.hook('builder:prepared', (_builder, buildOptions) => { - virtualTemplates = [] - buildOptions.templates.forEach((template, index, arr) => { - if (!template.getContents) { return } - // Remove template from template array to handle it ourselves - arr.splice(index, 1) - virtualTemplates.push(template) - }) + virtualTemplates = buildOptions.templates.filter(t => t.getContents) + for (const template of virtualTemplates) { + buildOptions.templates.splice(buildOptions.templates.indexOf(template), 1) + } }) nuxt.hook('build:templates', async (templates) => { const context = {