Skip to content
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

fix(nextjs): Respect directives in value injection loader #14083

Merged
merged 4 commits into from
Oct 28, 2024

Conversation

lforst
Copy link
Member

@lforst lforst commented Oct 28, 2024

This PR is in preparation for turbopack (#8105).

In the future, sentry.client.config.ts will likely need to be configured with a "use client" directive so that turbopack knows it needs to be treated as a file on the client.

Our value injection loader currently always prepends the sentry.client.config.ts file with statements, rendering any directives in the file useless and crashing turbopack when the file is attempted to be imported somewhere.

This PR detects any comments and directives on top of a file to only inject values after.

@lforst lforst requested a review from chargome October 28, 2024 11:52
Copy link
Member

@chargome chargome left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm – should we cover this with an additional test?

const SKIP_COMMENT_AND_DIRECTIVE_REGEX =
// Note: CodeQL complains that this regex potentially has n^2 runtime. This likely won't affect realistic files.
// biome-ignore lint/nursery/useRegexLiterals: No user input
new RegExp('^(?:\\s*|/\\*(?:.|\\r|\\n)*?\\*/|//.*[\\n\\r])*(?:"[^"]*";|\'[^\']*\';)?');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is wild

@lforst lforst merged commit e68865a into develop Oct 28, 2024
118 checks passed
@lforst lforst deleted the lforst-valinjection-loader-directives branch October 28, 2024 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants