Skip to content

nextjs: Turbopack applicationKey rule also tags server modules, slowing cold starts #25544

Closed

Description

@JasonLovesDoggo

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/browser

SDK Version

10.64.0 (the same rule ships in 11.8.0 and on develop)

Framework Version

16.4.0

Link to Sentry event

No response

Reproduction Example/SDK Setup

// next.config.ts
export default withSentryConfig(nextConfig, {
  applicationKey: "my-app",
})

// instrumentation-client.ts
Sentry.init({
  dsn: "...",
  integrations: [
    Sentry.thirdPartyErrorFilterIntegration({
      filterKeys: ["my-app"],
      behaviour: "apply-tag-if-exclusively-contains-third-party-frames",
    }),
  ],
})

Steps to Reproduce

  1. Set applicationKey in withSentryConfig on a Next 16 app that builds with Turbopack.
  2. Run next build.
  3. Search the output for _sentryBundlerPluginAppKey:my-app in .next/static and in .next/server.
  4. Start next start and time the first request to a route on a fresh process.

Expected Result

Only browser modules carry the metadata snippet. thirdPartyErrorFilterIntegration only runs in the browser, and @sentry/node does not export it, so nothing on the server reads the tags.

Actual Result

constructTurbopackConfig adds a *.{ts,tsx,js,jsx,mjs,cjs} rule whose only condition is { not: { path: /next\/dist\/build\/polyfills/ } }. Turbopack applies it to server and edge modules too. Each snippet evaluates new Error().stack twice when its module loads, so every cold start pays for it.

In our app:

Default rule Same rule with a "browser" condition
Snippets in server output 15,353 5
Snippets in browser output 4,840 4,840
Cold first request, next start on a laptop, median of 7 (three routes) 757 / 816 / 829 ms 650 / 697 / 786 ms
Cold first request, Vercel preview (1 vCPU) ~2.7 s ~2.15 s

On Vercel's slower CPU the snippets cost 0.4 to 0.5 s per cold start.

Additional Context

Suggested fix, in constructTurbopackConfig:

condition: { all: ["browser", { not: { path: /next\/dist\/build\/polyfills/ } }] },

We ran exactly this as our own turbopack.rules entry pointing at build/cjs/config/loaders/moduleMetadataInjectionLoader.js. The browser output was unchanged.

Related: #19320 (Turbopack applicationKey support), #23402 (same loader, for moduleMetadata), #14041.

Priority

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.

Activity

  1. linear-code commented on Oct 19, 2026

    @linear-code
  2. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Oct 19, 2026
  3. self-assigned this
    on Oct 20, 2026
  4. logaretm commented on Oct 20, 2026

    @logaretm
    Member

    Thanks for the report, I got a PR out for it.

  5. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Oct 20, 2026
  6. added a commit that references this issue on Oct 20, 2026
    afb4282
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions