Skip to content

Commit 27af12e

Browse files
authored
fix(nextjs): Stop accessing sync props in template (#18113)
We need to stop accessing params within our wrapper templates as this can break statically rendered pages and cause cache busts in dynamic pages. Opened #18115 to investigate other ways of handling the functionality we're removing here. closes #18097 closes #17431 Note: There's some unused code in the utils that I did not delete as we might be able to reuse this in #18115
1 parent 296e860 commit 27af12e

File tree

3 files changed

+0
-47
lines changed

3 files changed

+0
-47
lines changed

dev-packages/e2e-tests/test-applications/nextjs-app-dir/tests/server-components.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ test('Sends a transaction for a request to app router', async ({ page }) => {
3939
headers: expect.objectContaining({
4040
'user-agent': expect.any(String),
4141
}),
42-
url: expect.stringContaining('/server-component/parameter/1337/42'),
4342
});
4443

4544
// The transaction should not contain any spans with the same name as the transaction

packages/nextjs/src/common/wrapGenerationFunctionWithSentry.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
captureException,
44
getActiveSpan,
55
getCapturedScopesOnSpan,
6-
getClient,
76
getRootSpan,
87
handleCallbackErrors,
98
propagationContextFromHeaders,
@@ -13,7 +12,6 @@ import {
1312
setCapturedScopesOnSpan,
1413
SPAN_STATUS_ERROR,
1514
SPAN_STATUS_OK,
16-
spanToJSON,
1715
startSpanManual,
1816
winterCGHeadersToDict,
1917
withIsolationScope,
@@ -23,8 +21,6 @@ import type { GenerationFunctionContext } from '../common/types';
2321
import { isNotFoundNavigationError, isRedirectNavigationError } from './nextNavigationErrorUtils';
2422
import { TRANSACTION_ATTR_SENTRY_TRACE_BACKFILL } from './span-attributes-with-logic-attached';
2523
import { commonObjectToIsolationScope, commonObjectToPropagationContext } from './utils/tracingUtils';
26-
import { getSanitizedRequestUrl } from './utils/urls';
27-
import { maybeExtractSynchronousParamsAndSearchParams } from './utils/wrapperUtils';
2824
/**
2925
* Wraps a generation function (e.g. generateMetadata) with Sentry error and performance instrumentation.
3026
*/
@@ -46,43 +42,23 @@ export function wrapGenerationFunctionWithSentry<F extends (...args: any[]) => a
4642
}
4743

4844
const isolationScope = commonObjectToIsolationScope(headers);
49-
let pathname = undefined as string | undefined;
5045

5146
const activeSpan = getActiveSpan();
5247
if (activeSpan) {
5348
const rootSpan = getRootSpan(activeSpan);
5449
const { scope } = getCapturedScopesOnSpan(rootSpan);
5550
setCapturedScopesOnSpan(rootSpan, scope ?? new Scope(), isolationScope);
56-
57-
const spanData = spanToJSON(rootSpan);
58-
59-
if (spanData.data && 'http.target' in spanData.data) {
60-
pathname = spanData.data['http.target'] as string;
61-
}
6251
}
6352

6453
const headersDict = headers ? winterCGHeadersToDict(headers) : undefined;
6554

66-
let data: Record<string, unknown> | undefined = undefined;
67-
if (getClient()?.getOptions().sendDefaultPii) {
68-
const props: unknown = args[0];
69-
const { params, searchParams } = maybeExtractSynchronousParamsAndSearchParams(props);
70-
data = { params, searchParams };
71-
}
72-
7355
return withIsolationScope(isolationScope, () => {
7456
return withScope(scope => {
7557
scope.setTransactionName(`${componentType}.${generationFunctionIdentifier} (${componentRoute})`);
7658

7759
isolationScope.setSDKProcessingMetadata({
7860
normalizedRequest: {
7961
headers: headersDict,
80-
url: getSanitizedRequestUrl(
81-
componentRoute,
82-
data?.params as Record<string, string> | undefined,
83-
headersDict,
84-
pathname,
85-
),
8662
} satisfies RequestEventData,
8763
});
8864

@@ -106,8 +82,6 @@ export function wrapGenerationFunctionWithSentry<F extends (...args: any[]) => a
10682

10783
scope.setPropagationContext(propagationContext);
10884

109-
scope.setExtra('route_data', data);
110-
11185
return startSpanManual(
11286
{
11387
op: 'function.nextjs',

packages/nextjs/src/common/wrapServerComponentWithSentry.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
captureException,
44
getActiveSpan,
55
getCapturedScopesOnSpan,
6-
getClient,
76
getRootSpan,
87
handleCallbackErrors,
98
propagationContextFromHeaders,
@@ -13,7 +12,6 @@ import {
1312
setCapturedScopesOnSpan,
1413
SPAN_STATUS_ERROR,
1514
SPAN_STATUS_OK,
16-
spanToJSON,
1715
startSpanManual,
1816
vercelWaitUntil,
1917
winterCGHeadersToDict,
@@ -25,8 +23,6 @@ import type { ServerComponentContext } from '../common/types';
2523
import { flushSafelyWithTimeout } from '../common/utils/responseEnd';
2624
import { TRANSACTION_ATTR_SENTRY_TRACE_BACKFILL } from './span-attributes-with-logic-attached';
2725
import { commonObjectToIsolationScope, commonObjectToPropagationContext } from './utils/tracingUtils';
28-
import { getSanitizedRequestUrl } from './utils/urls';
29-
import { maybeExtractSynchronousParamsAndSearchParams } from './utils/wrapperUtils';
3026

3127
/**
3228
* Wraps an `app` directory server component with Sentry error instrumentation.
@@ -45,34 +41,18 @@ export function wrapServerComponentWithSentry<F extends (...args: any[]) => any>
4541
const requestTraceId = getActiveSpan()?.spanContext().traceId;
4642
const isolationScope = commonObjectToIsolationScope(context.headers);
4743

48-
let pathname = undefined as string | undefined;
4944
const activeSpan = getActiveSpan();
5045
if (activeSpan) {
5146
const rootSpan = getRootSpan(activeSpan);
5247
const { scope } = getCapturedScopesOnSpan(rootSpan);
5348
setCapturedScopesOnSpan(rootSpan, scope ?? new Scope(), isolationScope);
54-
55-
const spanData = spanToJSON(rootSpan);
56-
57-
if (spanData.data && 'http.target' in spanData.data) {
58-
pathname = spanData.data['http.target']?.toString();
59-
}
6049
}
6150

6251
const headersDict = context.headers ? winterCGHeadersToDict(context.headers) : undefined;
6352

64-
let params: Record<string, string> | undefined = undefined;
65-
66-
if (getClient()?.getOptions().sendDefaultPii) {
67-
const props: unknown = args[0];
68-
const { params: paramsFromProps } = maybeExtractSynchronousParamsAndSearchParams(props);
69-
params = paramsFromProps;
70-
}
71-
7253
isolationScope.setSDKProcessingMetadata({
7354
normalizedRequest: {
7455
headers: headersDict,
75-
url: getSanitizedRequestUrl(componentRoute, params, headersDict, pathname),
7656
} satisfies RequestEventData,
7757
});
7858

0 commit comments

Comments
 (0)