sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

@sentry/nextjs `autoInstrumentServerFunctions` breaks next.js' font optimization

Open klaasman opened this issue 2 years ago • 9 comments

Is there an existing issue for this?

  • [X] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
  • [X] I have reviewed the documentation https://docs.sentry.io/
  • [X] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

7.54.0

Framework Version

7.54.0

Link to Sentry event

No response

SDK Setup

Sentry.init({ dsn: SENTRY_DSN, tracesSampleRate: 1.0, });

Steps to Reproduce

Clone the following repository: https://github.com/klaasman/sentry-nextjs-font-inlining-bug

  1. npm install
  2. npm run build
  3. open ./.next/server/pages/index.html, you will see that the font-loading is inlined (search for @font-face)
  4. now open next.config.js and comment out the autoInstrumentServerFunctions line
  5. npm run build
  6. open ./.next/server/pages/index.html, you will see that the font-loading is not inlined anymore (search for @font-face)

Expected Result

I expected next.js font optimization feature to work.

Actual Result

The autoInstrumentServerFunctions somehow disables next.js' font inlining feature. This setting is turned on by default, in this repository it is turned off in the next.config.js file.

klaasman avatar Jun 13 '23 14:06 klaasman

Thanks for writing in! We'll take a look at this!

lforst avatar Jun 20 '23 06:06 lforst

Thanks - you can find more info in the README of the reproduction github repository.

klaasman avatar Jun 20 '23 08:06 klaasman

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

github-actions[bot] avatar Jul 12 '23 00:07 github-actions[bot]

Go ahead and reset the clock as this isn't resolved yet

klaasman avatar Jul 12 '23 05:07 klaasman

Hi @klaasman thanks for bumping. This is on our backlog, we'll take a look at it.

Lms24 avatar Aug 03 '23 09:08 Lms24

I took a look at how Next.js implements this font optimization. It seems like Next.js does static code analysis to build a font a font manifest and the SDK breaks the manifest generation. I believe a fix is not that straight forward so it might take a while until we get to this.

lforst avatar Aug 03 '23 10:08 lforst

Thanks for diving into it. What parts of the sentry <-> next.js integration will be turned off if I disable sentry's autoInstrumentServerFunctions option? (and maybe any guidance on how to manually implement the missing parts?)

klaasman avatar Aug 03 '23 13:08 klaasman

Thanks for diving into it. What parts of the sentry <-> next.js integration will be turned off if I disable sentry's autoInstrumentServerFunctions option?

@klaasman unfortunately quite a bit. autoInstrumentServerFunctions controls basically all of the serverside instrumentation for errors and performance. Without it you need to instrument all API routes, data fetchers, and server components, by yourself: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#opt-in-to-auto-instrumentation-on-specific-routes

lforst avatar Aug 03 '23 13:08 lforst

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

getsantry[bot] avatar May 02 '24 07:05 getsantry[bot]