|
|
import type { CssResource } from '../../build/webpack/plugins/flight-manifest-plugin' |
|
|
import { encodeURIPath } from '../../shared/lib/encode-uri-path' |
|
|
import type { AppRenderContext } from './app-render' |
|
|
import { getAssetQueryString } from './get-asset-query-string' |
|
|
import type { PreloadCallbacks } from './types' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function renderCssResource( |
|
|
entryCssFiles: CssResource[], |
|
|
ctx: AppRenderContext, |
|
|
preloadCallbacks?: PreloadCallbacks |
|
|
) { |
|
|
return entryCssFiles.map((entryCssFile, index) => { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const precedence = |
|
|
process.env.NODE_ENV === 'development' |
|
|
? 'next_' + entryCssFile.path |
|
|
: 'next' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const fullHref = `${ctx.assetPrefix}/_next/${encodeURIPath( |
|
|
entryCssFile.path |
|
|
)}${getAssetQueryString(ctx, true)}` |
|
|
|
|
|
if (entryCssFile.inlined && !ctx.parsedRequestHeaders.isRSCRequest) { |
|
|
return ( |
|
|
<style |
|
|
key={index} |
|
|
nonce={ctx.nonce} |
|
|
// @ts-ignore |
|
|
precedence={precedence} |
|
|
href={fullHref} |
|
|
> |
|
|
{entryCssFile.content} |
|
|
</style> |
|
|
) |
|
|
} |
|
|
|
|
|
preloadCallbacks?.push(() => { |
|
|
ctx.componentMod.preloadStyle( |
|
|
fullHref, |
|
|
ctx.renderOpts.crossOrigin, |
|
|
ctx.nonce |
|
|
) |
|
|
}) |
|
|
|
|
|
return ( |
|
|
<link |
|
|
key={index} |
|
|
rel="stylesheet" |
|
|
href={fullHref} |
|
|
// @ts-ignore |
|
|
precedence={precedence} |
|
|
crossOrigin={ctx.renderOpts.crossOrigin} |
|
|
nonce={ctx.nonce} |
|
|
/> |
|
|
) |
|
|
}) |
|
|
} |
|
|
|