Skip to content

Commit

Permalink
Add additional font-loader spans for tracing (vercel#50889)
Browse files Browse the repository at this point in the history
## What?

Adds additional spans for running postcss and fontloader in next-font-loader.
  • Loading branch information
timneutkens authored and hydRAnger committed Jun 12, 2023
1 parent 13c3032 commit eaf357d
Showing 1 changed file with 34 additions and 28 deletions.
62 changes: 34 additions & 28 deletions packages/next/src/build/webpack/loaders/next-font-loader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,24 @@ export default async function nextFontLoader(this: any) {
// The font loader function emits font files and returns @font-faces and fallback font metrics
const fontLoader: FontLoader = require(fontLoaderPath).default
let { css, fallbackFonts, adjustFontFallback, weight, style, variable } =
await fontLoader({
functionName,
variableName,
data,
emitFontFile,
resolve: (src: string) =>
promisify(this.resolve)(
path.dirname(
path.join(this.rootContext, relativeFilePathFromRoot)
await nextFontLoaderSpan.traceChild('font-loader').traceAsyncFn(() =>
fontLoader({
functionName,
variableName,
data,
emitFontFile,
resolve: (src: string) =>
promisify(this.resolve)(
path.dirname(
path.join(this.rootContext, relativeFilePathFromRoot)
),
src.startsWith('.') ? src : `./${src}`
),
src.startsWith('.') ? src : `./${src}`
),
isDev,
isServer,
loaderContext: this,
})
isDev,
isServer,
loaderContext: this,
})
)

const { postcss } = await getPostcss()

Expand All @@ -127,19 +129,23 @@ export default async function nextFontLoader(this: any) {
)

// Add CSS classes, exports and make the font-family locally scoped by turning it unguessable
const result = await postcss(
postcssNextFontPlugin({
exports,
fontFamilyHash,
fallbackFonts,
weight,
style,
adjustFontFallback,
variable,
})
).process(css, {
from: undefined,
})
const result = await nextFontLoaderSpan
.traceChild('postcss')
.traceAsyncFn(() =>
postcss(
postcssNextFontPlugin({
exports,
fontFamilyHash,
fallbackFonts,
weight,
style,
adjustFontFallback,
variable,
})
).process(css, {
from: undefined,
})
)

const ast = {
type: 'postcss',
Expand Down

0 comments on commit eaf357d

Please sign in to comment.