Skip to content

Commit

Permalink
Add additional font-loader spans for tracing (#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 committed Jun 7, 2023
1 parent a24c607 commit 9a1db5f
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

1 comment on commit 9a1db5f

@masterkain
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An error occured in `next/font`.

Error: Cannot find module '../dist/google/loader'
Require stack:
- /app/node_modules/next/dist/compiled/@next/font/google/loader.js
- /app/node_modules/next/dist/build/webpack/loaders/next-font-loader/index.js
- /app/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js
- /app/node_modules/next/dist/compiled/webpack/bundle5.js
- /app/node_modules/next/dist/compiled/webpack/webpack.js
- /app/node_modules/next/dist/server/config-utils.js
- /app/node_modules/next/dist/server/config.js
- /app/node_modules/next/dist/server/next.js
- /app/node_modules/next/dist/server/lib/render-server.js
- /app/node_modules/next/dist/compiled/jest-worker/processChild.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1070:15)
    at /app/node_modules/next/dist/server/require-hook.js:188:36
    at Module._load (node:internal/modules/cjs/loader:923:27)
    at Module.require (node:internal/modules/cjs/loader:1137:19)
    at require (node:internal/modules/helpers:121:18)
    at Object.<anonymous> (/app/node_modules/next/dist/compiled/@next/font/google/loader.js:1:18)
    at Module._compile (node:internal/modules/cjs/loader:1255:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1309:10)
    at Module.load (node:internal/modules/cjs/loader:1113:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1137:19)
    at require (node:internal/modules/helpers:121:18)
    at /app/node_modules/next/dist/build/webpack/loaders/next-font-loader/index.js:75:32
    at Span.traceAsyncFn (/app/node_modules/next/dist/trace/trace.js:103:26)
    at Object.nextFontLoader (/app/node_modules/next/dist/build/webpack/loaders/next-font-loader/index.js:23:31)
    at LOADER_EXECUTION (/app/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:4134)
    at runSyncOrAsync (/app/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:4145)
    at iterateNormalLoaders (/app/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:5782)
    at /app/node_modules/next/dist/compiled/loader-runner/LoaderRunner.js:1:5426
    at /app/node_modules/next/dist/compiled/webpack/bundle5.js:28:395994
    at eval (eval at create (/app/node_modules/next/dist/compiled/webpack/bundle5.js:13:28771), <anonymous>:14:1)
    at Array.<anonymous> (/app/node_modules/next/dist/build/webpack/plugins/profiling-plugin.js:168:29)
    at runCallbacks (/app/node_modules/next/dist/compiled/webpack/bundle5.js:1:152096)
    at /app/node_modules/next/dist/compiled/webpack/bundle5.js:1:154008
    at /app/node_modules/next/dist/compiled/webpack/bundle5.js:1:252119
    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3)
- wait compiling /_error (client and server)...
- error app/layout.tsx
An error occured in `next/font`.

Please sign in to comment.