perf: fix race conditions with cache (#2579)

pull/2580/head
Divyansh Singh 1 year ago committed by GitHub
parent faab56f235
commit 32d65d40c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -56,12 +56,12 @@ export async function build(
) as OutputChunk) ) as OutputChunk)
const cssChunk = ( const cssChunk = (
siteConfig.mpa ? serverResult : clientResult siteConfig.mpa ? serverResult : clientResult!
).output.find( ).output.find(
(chunk) => chunk.type === 'asset' && chunk.fileName.endsWith('.css') (chunk) => chunk.type === 'asset' && chunk.fileName.endsWith('.css')
) as OutputAsset ) as OutputAsset
const assets = (siteConfig.mpa ? serverResult : clientResult).output const assets = (siteConfig.mpa ? serverResult : clientResult!).output
.filter( .filter(
(chunk) => chunk.type === 'asset' && !chunk.fileName.endsWith('.css') (chunk) => chunk.type === 'asset' && !chunk.fileName.endsWith('.css')
) )

@ -31,7 +31,7 @@ export async function bundle(
config: SiteConfig, config: SiteConfig,
options: BuildOptions options: BuildOptions
): Promise<{ ): Promise<{
clientResult: RollupOutput clientResult: RollupOutput | null
serverResult: RollupOutput serverResult: RollupOutput
pageToHashMap: Record<string, string> pageToHashMap: Record<string, string>
}> { }> {
@ -142,16 +142,16 @@ export async function bundle(
} }
}) })
let clientResult: RollupOutput let clientResult: RollupOutput | null
let serverResult: RollupOutput let serverResult: RollupOutput
const spinner = ora() const spinner = ora()
spinner.start('building client + server bundles...') spinner.start('building client + server bundles...')
try { try {
;[clientResult, serverResult] = await (Promise.all([ clientResult = config.mpa
config.mpa ? null : build(await resolveViteConfig(false)), ? null
build(await resolveViteConfig(true)) : ((await build(await resolveViteConfig(false))) as RollupOutput)
]) as Promise<[RollupOutput, RollupOutput]>) serverResult = (await build(await resolveViteConfig(true))) as RollupOutput
} catch (e) { } catch (e) {
spinner.stopAndPersist({ spinner.stopAndPersist({
symbol: failMark symbol: failMark

@ -24,8 +24,8 @@ export async function renderPage(
config: SiteConfig, config: SiteConfig,
page: string, // foo.md page: string, // foo.md
result: RollupOutput | null, result: RollupOutput | null,
appChunk: OutputChunk | undefined, appChunk: OutputChunk | null,
cssChunk: OutputAsset | undefined, cssChunk: OutputAsset | null,
assets: string[], assets: string[],
pageToHashMap: Record<string, string>, pageToHashMap: Record<string, string>,
hashMapString: string, hashMapString: string,

Loading…
Cancel
Save