mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
Merge 16984b7c7e
into 9bf8465806
This commit is contained in:
commit
a1e451a4a1
@ -34,7 +34,8 @@ async function loadComponents (source = appBaseURL, paths: NuxtIslandResponse['c
|
||||
|
||||
const promises: Array<Promise<void>> = []
|
||||
|
||||
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}"]` }, {
|
||||
|
@ -250,8 +250,8 @@ function generateOptionSegments<_ResT, DataT, DefaultT> (opts: UseFetchOptions<_
|
||||
if (!obj) { continue }
|
||||
|
||||
const unwrapped: Record<string, string> = {}
|
||||
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)
|
||||
}
|
||||
|
@ -144,7 +144,8 @@ export default defineNuxtModule<ComponentsOptions>({
|
||||
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))
|
||||
|
@ -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<string, string> = {}
|
||||
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) {
|
||||
|
@ -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 = ''
|
||||
|
@ -396,7 +396,8 @@ export default defineRenderHandler(async (event): Promise<Partial<RenderResponse
|
||||
}
|
||||
if (!isRenderingIsland || import.meta.dev) {
|
||||
const link: Link[] = []
|
||||
for (const resource of Object.values(styles)) {
|
||||
for (const resourceId in styles) {
|
||||
const resource = styles[resourceId]!
|
||||
// Do not add links to resources that are inlined (vite v5+)
|
||||
if (import.meta.dev && 'inline' in getURLQuery(resource.file)) {
|
||||
continue
|
||||
@ -462,7 +463,9 @@ export default defineRenderHandler(async (event): Promise<Partial<RenderResponse
|
||||
if (isRenderingIsland && islandContext) {
|
||||
const islandHead: Head = {}
|
||||
for (const entry of head.headEntries()) {
|
||||
for (const [key, value] of Object.entries(resolveUnrefHeadInput(entry.input) as Head)) {
|
||||
const currentEntry = resolveUnrefHeadInput(entry.input)
|
||||
for (const key in currentEntry as Head) {
|
||||
const value = currentEntry[key]
|
||||
const currentValue = islandHead[key as keyof Head]
|
||||
if (Array.isArray(currentValue)) {
|
||||
currentValue.push(...value)
|
||||
@ -661,9 +664,9 @@ const SSR_CLIENT_SLOT_MARKER = /^island-slot=[^;]*;(.*)$/
|
||||
function getSlotIslandResponse (ssrContext: NuxtSSRContext): NuxtIslandResponse['slots'] {
|
||||
if (!ssrContext.islandContext || !Object.keys(ssrContext.islandContext.slots).length) { return undefined }
|
||||
const response: NuxtIslandResponse['slots'] = {}
|
||||
for (const [name, slot] of Object.entries(ssrContext.islandContext.slots)) {
|
||||
for (const name in ssrContext.islandContext.slots) {
|
||||
response[name] = {
|
||||
...slot,
|
||||
...ssrContext.islandContext.slots[name]!,
|
||||
fallback: ssrContext.teleports?.[`island-fallback=${name}`],
|
||||
}
|
||||
}
|
||||
@ -674,11 +677,11 @@ function getClientIslandResponse (ssrContext: NuxtSSRContext): NuxtIslandRespons
|
||||
if (!ssrContext.islandContext || !Object.keys(ssrContext.islandContext.components).length) { return undefined }
|
||||
const response: NuxtIslandResponse['components'] = {}
|
||||
|
||||
for (const [clientUid, component] of Object.entries(ssrContext.islandContext.components)) {
|
||||
for (const clientUid in ssrContext.islandContext.components) {
|
||||
// remove teleport anchor to avoid hydration issues
|
||||
const html = ssrContext.teleports?.[clientUid]?.replaceAll('<!--teleport start anchor-->', '') || ''
|
||||
response[clientUid] = {
|
||||
...component,
|
||||
...ssrContext.islandContext.components[clientUid]!,
|
||||
html,
|
||||
slots: getComponentSlotTeleport(ssrContext.teleports ?? {}),
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -18,7 +18,8 @@ export function analyzePlugin (ctx: ViteBuildContext): Plugin[] {
|
||||
const bundle = outputBundle[_bundleId]
|
||||
if (!bundle || bundle.type !== 'chunk') { continue }
|
||||
const minifiedModuleEntryPromises: Array<Promise<[string, RenderedModule]>> = []
|
||||
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 }]),
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -62,7 +62,8 @@ export function ssrStylesPlugin (options: SSRStylePluginOptions): Plugin {
|
||||
if (options.mode === 'client') { return }
|
||||
|
||||
const emitted: Record<string, string> = {}
|
||||
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)
|
||||
|
@ -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
|
||||
|
@ -33,7 +33,8 @@ export default class VueSSRClientPlugin {
|
||||
const stats = compilation.getStats().toJson()
|
||||
|
||||
const initialFiles = new Set<string>()
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user