Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
ref(nextjs): Invert serverside injection criteria#6206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lobsterkatie
merged 2 commits into
master
from
kmclb-nextjs-invert-serverside-injection-criteriaNov 15, 2022
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -380,11 +380,37 @@ function checkWebpackPluginOverrides( | ||
| * @returns `true` if sentry code should be injected, and `false` otherwise | ||
| */ | ||
| function shouldAddSentryToEntryPoint(entryPointName: string, isServer: boolean): boolean { | ||
| return ( | ||
| entryPointName === 'pages/_app' || | ||
| (entryPointName.includes('pages/api') && !entryPointName.includes('_middleware')) || | ||
| (isServer && entryPointName === 'pages/_error') | ||
| ); | ||
| // On the server side, by default we inject the `Sentry.init()` code into every page (with a few exceptions). | ||
| if (isServer) { | ||
| const entryPointRoute = entryPointName.replace(/^pages/, ''); | ||
| if ( | ||
| // All non-API pages contain both of these components, and we don't want to inject more than once, so as long as | ||
| // we're doing the individual pages, it's fine to skip these. (Note: Even if a given user doesn't have either or | ||
| // both of these in their `pages/` folder, they'll exist as entrypoints because nextjs will supply default | ||
| // versions.) | ||
| entryPointRoute === '/_app' || | ||
| entryPointRoute === '/_document' || | ||
| // While middleware was in beta, it could be anywhere (at any level) in the `pages` directory, and would be called | ||
| // `_middleware.js`. Until the SDK runs successfully in the lambda edge environment, we have to exclude these. | ||
| entryPointName.includes('_middleware') || | ||
lobsterkatie marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| // Newer versions of nextjs are starting to introduce things outside the `pages/` folder (middleware, an `app/` | ||
| // directory, etc), but until those features are stable and we know how we want to support them, the safest bet is | ||
| // not to inject anywhere but inside `pages/`. | ||
| !entryPointName.startsWith('pages/') | ||
| ) { | ||
| return false; | ||
| } | ||
| // We want to inject Sentry into all other pages | ||
| return true; | ||
| } | ||
| // On the client side, we only want to inject into `_app`, because that guarantees there'll be only one copy of the | ||
| // SDK in the eventual bundle. Since `_app` is the (effectively) the root component for every nextjs app, inclusing | ||
| // Sentry there means it will be available for every front end page. | ||
| else { | ||
| return entryPointName === 'pages/_app'; | ||
lobsterkatie marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| } | ||
| /** | ||
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
47 changes: 28 additions & 19 deletions
47 packages/nextjs/test/config/webpack/constructWebpackConfig.test.ts
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
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.
Uh oh!
There was an error while loading. Please reload this page.