fix(nextjs): skip custom browser tracing setup for bot user agents#20263
Open
fix(nextjs): skip custom browser tracing setup for bot user agents#20263
Conversation
Expose isBotUserAgent from the browser tracing integration and use it in the Next.js wrapper so bot user agents also skip the Next.js-specific router instrumentation path. This is the smallest change to validate the fix. Longer term, we probably want a more general mechanism for integrations to skip their own setup and make that skip decision easy to downstream through wrappers and variants. Co-Authored-By: GPT-5.4 <noreply@anthropic.com>
Contributor
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Cloudflare
Core
Deps
Other
Bug Fixes 🐛Deno
Other
Internal Changes 🔧Ci
Deps
Other
🤖 This preview updates automatically when you update the PR. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses bot-rendering issues in Next.js by ensuring bot user agents (e.g. Googlebot) don’t trigger Next.js-specific router instrumentation (notably the router polling timer), by reusing a shared bot user-agent predicate from the browser tracing integration.
Changes:
- Export
isBotUserAgent()from the Browser Tracing integration (and re-export it via@sentry/browserbundles). - Use
isBotUserAgent()in the Next.js Browser Tracing wrapper to skip Next.js router instrumentation for bots. - Add a Next.js unit regression test to ensure Googlebot doesn’t start the router polling interval.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/nextjs/src/client/browserTracingIntegration.ts | Skips Next.js router instrumentation in afterAllSetup for bot user agents. |
| packages/nextjs/test/clientSdk.test.ts | Adds regression test asserting no setInterval polling starts for Googlebot. |
| packages/browser/src/tracing/browserTracingIntegration.ts | Makes bot UA detection helper public (isBotUserAgent) and uses it internally. |
| packages/browser/src/index.ts | Re-exports isBotUserAgent from the browser package entrypoint. |
| packages/browser/src/index.bundle.tracing.ts | Re-exports isBotUserAgent in tracing bundle. |
| packages/browser/src/index.bundle.tracing.replay.ts | Re-exports isBotUserAgent in tracing+replay bundle. |
| packages/browser/src/index.bundle.tracing.replay.logs.metrics.ts | Re-exports isBotUserAgent in tracing+replay+logs+metrics bundle. |
| packages/browser/src/index.bundle.tracing.replay.feedback.ts | Re-exports isBotUserAgent in tracing+replay+feedback bundle. |
| packages/browser/src/index.bundle.tracing.replay.feedback.logs.metrics.ts | Re-exports isBotUserAgent in tracing+replay+feedback+logs+metrics bundle. |
| packages/browser/src/index.bundle.tracing.logs.metrics.ts | Re-exports isBotUserAgent in tracing+logs+metrics bundle. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+178
to
+183
| init({ | ||
| dsn: TEST_DSN, | ||
| tracesSampleRate: 1.0, | ||
| }); | ||
|
|
||
| expect(setIntervalSpy).not.toHaveBeenCalled(); |
Contributor
size-limit report 📦
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Exposes
isBotUserAgent()from the browser tracing integration to use it in the Next.js browser tracing wrapper so bot user agents also skip Next.js-specific router instrumentation which adds its own interval timer.This is intentionally the smallest change to test whether this fixes the Googlebot rendering issue.
Longer term, we probably want a more general mechanism for integrations to skip their own setup, with a skip decision that can be downstreamed easily through wrappers and integration variants instead of checking the bot predicate ad hoc in each package.
closes #19670