-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(nextjs): Add auto-wrapping for server components #6953
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
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
efa8c02
Add simple wrapper
lforst d639de8
Refactor initialization of loaders a bit
lforst 9c24ebb
Fix build
lforst f0f6d4a
Call wrapping loader for server components
lforst 6b3f13a
Auto wrap server components
lforst bd4d8c8
Whoopsie
lforst 57b44df
🤯
lforst c588f78
Wrap under the assumption that server components may return promises …
lforst 1f398ae
Add escape hatch
lforst 7624607
Add integration test
lforst 2c89413
Wait wtf
lforst ec9f668
Testing the integration tests
lforst fdf9300
Run server tests for app dir
lforst 5aa6cf5
Fix
lforst cb0e21f
fix(nextjs): Don't modify require calls
lforst 09377e1
Merge remote-tracking branch 'origin/master' into lforst-add-app-dire…
lforst 9df4971
Merge branch 'lforst-fix-cjs-imports' into lforst-add-app-directory-c…
lforst 82fae38
...
lforst 4e204a5
Merge remote-tracking branch 'origin/develop' into lforst-add-app-dir…
lforst e94ac42
rm rf tests because they're broken
lforst b24868a
Merge branch 'develop' into lforst-add-app-directory-component-wrappers
lforst 2948f0b
Use proxy
lforst 6631195
Merge branch 'develop' into lforst-add-app-directory-component-wrappers
lforst 1e34bda
Merge branch 'develop' into lforst-add-app-directory-component-wrappers
lforst 990ff58
Remove leftover
lforst 9401d66
Add tests
lforst 0674a9d
Fix typo
lforst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* Currently just a pass-through to provide isomorphism for the client. May be used in the future to add instrumentation | ||
* for client components. | ||
*/ | ||
export function wrapAppDirComponentWithSentry(wrappingTarget: any): any { | ||
return wrappingTarget; | ||
} |
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
36 changes: 36 additions & 0 deletions
36
packages/nextjs/src/config/templates/serverComponentWrapperTemplate.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* This file is a template for the code which will be substituted when our webpack loader handles non-API files in the | ||
* `pages/` directory. | ||
* | ||
* We use `__SENTRY_WRAPPING_TARGET_FILE__` as a placeholder for the path to the file being wrapped. Because it's not a real package, | ||
* this causes both TS and ESLint to complain, hence the pragma comments below. | ||
*/ | ||
|
||
// @ts-ignore See above | ||
// eslint-disable-next-line import/no-unresolved | ||
import * as wrapee from '__SENTRY_WRAPPING_TARGET_FILE__'; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import * as Sentry from '@sentry/nextjs'; | ||
|
||
type ServerComponentModule = { | ||
default: unknown; | ||
}; | ||
|
||
const serverComponentModule = wrapee as ServerComponentModule; | ||
|
||
const serverComponent = serverComponentModule.default; | ||
|
||
let wrappedServerComponent; | ||
if (typeof serverComponent === 'function') { | ||
wrappedServerComponent = Sentry.wrapAppDirComponentWithSentry(serverComponent); | ||
} else { | ||
wrappedServerComponent = serverComponent; | ||
} | ||
|
||
// Re-export anything exported by the page module we're wrapping. When processing this code, Rollup is smart enough to | ||
// not include anything whose name matchs something we've explicitly exported above. | ||
// @ts-ignore See above | ||
// eslint-disable-next-line import/no-unresolved | ||
export * from '__SENTRY_WRAPPING_TARGET_FILE__'; | ||
|
||
export default wrappedServerComponent; |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was an oversight from before