diff --git a/packages/nuxt/src/app/components/nuxt-island.ts b/packages/nuxt/src/app/components/nuxt-island.ts index 20d1f11cbf..59d0138c1d 100644 --- a/packages/nuxt/src/app/components/nuxt-island.ts +++ b/packages/nuxt/src/app/components/nuxt-island.ts @@ -34,7 +34,8 @@ async function loadComponents (source = appBaseURL, paths: NuxtIslandResponse['c const promises: Array> = [] - for (const [component, item] of Object.entries(paths)) { + for (const component in paths) { + const item = paths[component]! if (!(components!.has(component))) { promises.push((async () => { const chunkSource = join(source, item.chunk) @@ -146,10 +147,10 @@ export default defineComponent({ html = html.replace(ISLAND_SCOPE_ID_RE, full => full + ' ' + props.scopeId) } - if (import.meta.client && !canLoadClientComponent.value) { - for (const [key, value] of Object.entries(payloads.components || {})) { + if (import.meta.client && !canLoadClientComponent.value && payloads.components) { + for (const key in payloads.components) { html = html.replace(new RegExp(` data-island-uid="${uid.value}" data-island-component="${key}"[^>]*>`), (full) => { - return full + value.html + return full + payloads.components![key]!.html }) } } @@ -289,8 +290,8 @@ export default defineComponent({ if (selectiveClient) { if (import.meta.server) { if (payloads.components) { - for (const [id, info] of Object.entries(payloads.components)) { - const { html, slots } = info + for (const id in payloads.components) { + const { html, slots } = payloads.components[id]! let replaced = html.replaceAll('data-island-uid', `data-island-uid="${uid.value}"`) for (const slot in slots) { replaced = replaced.replaceAll(`data-island-slot="${slot}">`, full => full + slots[slot]) @@ -301,8 +302,8 @@ export default defineComponent({ } } } else if (canLoadClientComponent.value && payloads.components) { - for (const [id, info] of Object.entries(payloads.components)) { - const { props, slots } = info + for (const id in payloads.components) { + const { props, slots } = payloads.components[id]! const component = components!.get(id)! // use different selectors for even and odd teleportKey to force trigger the teleport const vnode = createVNode(Teleport, { to: `${isKeyOdd ? 'div' : ''}[data-island-uid='${uid.value}'][data-island-component="${id}"]` }, { diff --git a/packages/nuxt/src/app/composables/fetch.ts b/packages/nuxt/src/app/composables/fetch.ts index 5ce5a87d1f..b6120842ee 100644 --- a/packages/nuxt/src/app/composables/fetch.ts +++ b/packages/nuxt/src/app/composables/fetch.ts @@ -250,8 +250,8 @@ function generateOptionSegments<_ResT, DataT, DefaultT> (opts: UseFetchOptions<_ if (!obj) { continue } const unwrapped: Record = {} - for (const [key, value] of Object.entries(obj)) { - unwrapped[toValue(key)] = toValue(value) + for (const key in obj) { + unwrapped[toValue(key)] = toValue(obj[key]) } segments.push(unwrapped) } diff --git a/packages/nuxt/src/components/module.ts b/packages/nuxt/src/components/module.ts index a2a1d8ca7d..5663b05ac5 100644 --- a/packages/nuxt/src/components/module.ts +++ b/packages/nuxt/src/components/module.ts @@ -144,7 +144,8 @@ export default defineNuxtModule({ nuxt.hook('build:manifest', (manifest) => { const sourceFiles = getComponents().filter(c => c.global).map(c => relative(nuxt.options.srcDir, c.filePath)) - for (const chunk of Object.values(manifest)) { + for (const chunkId in manifest) { + const chunk = manifest[chunkId]! if (chunk.isEntry) { chunk.dynamicImports = chunk.dynamicImports?.filter(i => !sourceFiles.includes(i)) diff --git a/packages/nuxt/src/components/plugins/islands-transform.ts b/packages/nuxt/src/components/plugins/islands-transform.ts index a3e2aba41a..b888b4c5c5 100644 --- a/packages/nuxt/src/components/plugins/islands-transform.ts +++ b/packages/nuxt/src/components/plugins/islands-transform.ts @@ -214,7 +214,8 @@ export const ComponentsChunkPlugin = createUnplugin((options: ComponentChunkOpti async generateBundle (_opts, bundle) { const components = options.getComponents().filter(c => c.mode === 'client' || c.mode === 'all') const pathAssociation: Record = {} - for (const [chunkPath, chunkInfo] of Object.entries(bundle)) { + for (const chunkPath in bundle) { + const chunkInfo = bundle[chunkPath]! if (chunkInfo.type !== 'chunk') { continue } for (const component of components) { diff --git a/packages/nuxt/src/core/nuxt.ts b/packages/nuxt/src/core/nuxt.ts index 835d71c9bd..83c43c08f6 100644 --- a/packages/nuxt/src/core/nuxt.ts +++ b/packages/nuxt/src/core/nuxt.ts @@ -346,7 +346,8 @@ async function initNuxt (nuxt: Nuxt) { // TODO: [Experimental] Avoid emitting assets when flag is enabled if (nuxt.options.features.noScripts && !nuxt.options.dev) { nuxt.hook('build:manifest', async (manifest) => { - for (const chunk of Object.values(manifest)) { + for (const chunkId in manifest) { + const chunk = manifest[chunkId]! if (chunk.resourceType === 'script') { await rm(resolve(nuxt.options.buildDir, 'dist/client', withoutLeadingSlash(nuxt.options.app.buildAssetsDir), chunk.file), { force: true }) chunk.file = '' diff --git a/packages/nuxt/src/core/runtime/nitro/renderer.ts b/packages/nuxt/src/core/runtime/nitro/renderer.ts index 4a7037ae44..fe95a7229e 100644 --- a/packages/nuxt/src/core/runtime/nitro/renderer.ts +++ b/packages/nuxt/src/core/runtime/nitro/renderer.ts @@ -396,7 +396,8 @@ export default defineRenderHandler(async (event): Promise', '') || '' response[clientUid] = { - ...component, + ...ssrContext.islandContext.components[clientUid]!, html, slots: getComponentSlotTeleport(ssrContext.teleports ?? {}), } diff --git a/packages/nuxt/src/pages/module.ts b/packages/nuxt/src/pages/module.ts index 050d1c659d..29950ae975 100644 --- a/packages/nuxt/src/pages/module.ts +++ b/packages/nuxt/src/pages/module.ts @@ -436,7 +436,8 @@ export default defineNuxtModule({ nuxt.hook('pages:extend', (routes) => { const nitro = useNitro() let resolvedRoutes: string[] - for (const [path, rule] of Object.entries(nitro.options.routeRules)) { + for (const path in nitro.options.routeRules) { + const rule = nitro.options.routeRules[path]! if (!rule.redirect) { continue } resolvedRoutes ||= routes.flatMap(route => resolveRoutePaths(route)) // skip if there's already a route matching this path @@ -480,7 +481,8 @@ export default defineNuxtModule({ if (nuxt.options.dev) { return } const sourceFiles = nuxt.apps.default?.pages?.length ? getSources(nuxt.apps.default.pages) : [] - for (const [key, chunk] of Object.entries(manifest)) { + for (const key in manifest) { + const chunk = manifest[key]! if (chunk.src && Object.values(nuxt.apps).some(app => app.pages?.some(page => page.mode === 'server' && page.file === join(nuxt.options.srcDir, chunk.src!)))) { delete manifest[key] continue diff --git a/packages/vite/src/plugins/analyze.ts b/packages/vite/src/plugins/analyze.ts index d5e8e4432e..edecf536c7 100644 --- a/packages/vite/src/plugins/analyze.ts +++ b/packages/vite/src/plugins/analyze.ts @@ -18,7 +18,8 @@ export function analyzePlugin (ctx: ViteBuildContext): Plugin[] { const bundle = outputBundle[_bundleId] if (!bundle || bundle.type !== 'chunk') { continue } const minifiedModuleEntryPromises: Array> = [] - for (const [moduleId, module] of Object.entries(bundle.modules)) { + for (const moduleId in bundle.modules) { + const module = bundle.modules[moduleId]! minifiedModuleEntryPromises.push( transform(module.code || '', { minify: true }) .then(result => [moduleId, { ...module, code: result.code }]), diff --git a/packages/vite/src/plugins/nitro-sourcemap.ts b/packages/vite/src/plugins/nitro-sourcemap.ts index 01c2dc372b..023ffada3f 100644 --- a/packages/vite/src/plugins/nitro-sourcemap.ts +++ b/packages/vite/src/plugins/nitro-sourcemap.ts @@ -14,7 +14,8 @@ export const createSourcemapPreserver = () => { outputDir = config.build.outDir }, async writeBundle (_options, bundle) { - for (const chunk of Object.values(bundle)) { + for (const chunkId in bundle) { + const chunk = bundle[chunkId]! if (chunk.type !== 'chunk' || !chunk.map) { continue } const id = resolve(outputDir, chunk.fileName) diff --git a/packages/vite/src/plugins/public-dirs.ts b/packages/vite/src/plugins/public-dirs.ts index 970bb2af1e..d97f3966aa 100644 --- a/packages/vite/src/plugins/public-dirs.ts +++ b/packages/vite/src/plugins/public-dirs.ts @@ -87,7 +87,8 @@ export const VitePublicDirsPlugin = createUnplugin((options: VitePublicDirsPlugi } }, generateBundle (_outputOptions, bundle) { - for (const [file, chunk] of Object.entries(bundle)) { + for (const file in bundle) { + const chunk = bundle[file]! if (!file.endsWith('.css') || chunk.type !== 'asset') { continue } let css = chunk.source.toString() diff --git a/packages/vite/src/plugins/ssr-styles.ts b/packages/vite/src/plugins/ssr-styles.ts index ce9936699f..d36f195223 100644 --- a/packages/vite/src/plugins/ssr-styles.ts +++ b/packages/vite/src/plugins/ssr-styles.ts @@ -62,7 +62,8 @@ export function ssrStylesPlugin (options: SSRStylePluginOptions): Plugin { if (options.mode === 'client') { return } const emitted: Record = {} - for (const [file, { files, inBundle }] of Object.entries(cssMap)) { + for (const file in cssMap) { + const { files, inBundle } = cssMap[file]! // File has been tree-shaken out of build (or there are no styles to inline) if (!files.length || !inBundle) { continue } const fileName = filename(file) diff --git a/packages/vite/src/vite.ts b/packages/vite/src/vite.ts index 5500f4bed0..cc489be768 100644 --- a/packages/vite/src/vite.ts +++ b/packages/vite/src/vite.ts @@ -201,7 +201,8 @@ export const bundle: NuxtBuilder['bundle'] = async (nuxt) => { // Remove CSS entries for files that will have inlined styles ctx.nuxt.hook('build:manifest', (manifest) => { - for (const [key, entry] of Object.entries(manifest)) { + for (const key in manifest) { + const entry = manifest[key]! const shouldRemoveCSS = chunksWithInlinedCSS.has(key) && !entry.isEntry if (entry.isEntry && chunksWithInlinedCSS.has(key)) { // @ts-expect-error internal key diff --git a/packages/webpack/src/plugins/vue/client.ts b/packages/webpack/src/plugins/vue/client.ts index 3f217f3e1d..ff447dc300 100644 --- a/packages/webpack/src/plugins/vue/client.ts +++ b/packages/webpack/src/plugins/vue/client.ts @@ -33,7 +33,8 @@ export default class VueSSRClientPlugin { const stats = compilation.getStats().toJson() const initialFiles = new Set() - for (const { assets } of Object.values(stats.entrypoints!)) { + for (const assetId in stats.entrypoints!) { + const { assets } = stats.entrypoints[assetId]! if (!assets) { continue } for (const asset of assets) {