Unverified Commit ecd77cfe authored by vercel[bot]'s avatar vercel[bot] Committed by GitHub

Optimize app render asset set allocation

Co-Authored-By: 's avatarMarcos Hernanz <96699542+marcoshernanz@users.noreply.github.com>
parent cf10c50a
import type { CssResource } from '../../build/webpack/plugins/flight-manifest-plugin' import type { CssResource } from '../../build/webpack/plugins/flight-manifest-plugin'
import { getClientReferenceManifest } from './manifests-singleton' import { getClientReferenceManifest } from './manifests-singleton'
const EMPTY_SET: ReadonlySet<never> = new Set()
/** /**
* Get external stylesheet link hrefs based on server CSS manifest. * Get external stylesheet link hrefs based on server CSS manifest.
*/ */
...@@ -11,8 +13,8 @@ export function getLinkAndScriptTags( ...@@ -11,8 +13,8 @@ export function getLinkAndScriptTags(
collectNewImports?: boolean collectNewImports?: boolean
): { styles: ReadonlySet<CssResource>; scripts: ReadonlySet<string> } { ): { styles: ReadonlySet<CssResource>; scripts: ReadonlySet<string> } {
const filePathWithoutExt = filePath.replace(/\.[^.]+$/, '') const filePathWithoutExt = filePath.replace(/\.[^.]+$/, '')
const cssChunks = new Set<CssResource>() let cssChunks: Set<CssResource> | undefined
const jsChunks = new Set<string>() let jsChunks: Set<string> | undefined
const { entryCSSFiles, entryJSFiles } = getClientReferenceManifest() const { entryCSSFiles, entryJSFiles } = getClientReferenceManifest()
const cssFiles = entryCSSFiles[filePathWithoutExt] const cssFiles = entryCSSFiles[filePathWithoutExt]
const jsFiles = entryJSFiles?.[filePathWithoutExt] const jsFiles = entryJSFiles?.[filePathWithoutExt]
...@@ -23,6 +25,9 @@ export function getLinkAndScriptTags( ...@@ -23,6 +25,9 @@ export function getLinkAndScriptTags(
if (collectNewImports) { if (collectNewImports) {
injectedCSS.add(css.path) injectedCSS.add(css.path)
} }
if (!cssChunks) {
cssChunks = new Set()
}
cssChunks.add(css) cssChunks.add(css)
} }
} }
...@@ -34,10 +39,16 @@ export function getLinkAndScriptTags( ...@@ -34,10 +39,16 @@ export function getLinkAndScriptTags(
if (collectNewImports) { if (collectNewImports) {
injectedScripts.add(file) injectedScripts.add(file)
} }
if (!jsChunks) {
jsChunks = new Set()
}
jsChunks.add(file) jsChunks.add(file)
} }
} }
} }
return { styles: cssChunks, scripts: jsChunks } return {
styles: cssChunks ?? EMPTY_SET,
scripts: jsChunks ?? EMPTY_SET,
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment