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

Pass only required props to NonIndex #77685

Merged
merged 2 commits into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions packages/next/src/server/app-render/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -433,13 +433,20 @@ function makeGetDynamicParamFromSegment(
}
}

function NonIndex({ ctx }: { ctx: AppRenderContext }) {
const is404Page = ctx.pagePath === '/404'
const isInvalidStatusCode =
typeof ctx.res.statusCode === 'number' && ctx.res.statusCode > 400
function NonIndex({
pagePath,
statusCode,
isAction,
}: {
pagePath: string
statusCode: number | undefined
isAction: boolean
}) {
const is404Page = pagePath === '/404'
const isInvalidStatusCode = typeof statusCode === 'number' && statusCode > 400

// Only render noindex for page request, skip for server actions
if (!ctx.isAction && (is404Page || isInvalidStatusCode)) {
if (!isAction && (is404Page || isInvalidStatusCode)) {
return <meta name="robots" content="noindex" />
}
return null
Expand Down Expand Up @@ -527,7 +534,11 @@ async function generateDynamicRSCPayload(
rscHead: (
<React.Fragment key={flightDataPathHeadKey}>
{/* noindex needs to be blocking */}
<NonIndex ctx={ctx} />
<NonIndex
pagePath={ctx.pagePath}
statusCode={ctx.res.statusCode}
isAction={ctx.isAction}
/>
{/* Adding requestId as react key to make metadata remount for each render */}
<ViewportTree key={requestId} />
{StreamingMetadata ? <StreamingMetadata /> : null}
Expand Down Expand Up @@ -859,7 +870,11 @@ async function getRSCPayload(

const initialHead = (
<React.Fragment key={flightDataPathHeadKey}>
<NonIndex ctx={ctx} />
<NonIndex
pagePath={ctx.pagePath}
statusCode={ctx.res.statusCode}
isAction={ctx.isAction}
/>
<ViewportTree key={ctx.requestId} />
<StaticMetadata />
</React.Fragment>
Expand Down Expand Up @@ -961,7 +976,11 @@ async function getErrorRSCPayload(

const initialHead = (
<React.Fragment key={flightDataPathHeadKey}>
<NonIndex ctx={ctx} />
<NonIndex
pagePath={ctx.pagePath}
statusCode={ctx.res.statusCode}
isAction={ctx.isAction}
/>
{/* Adding requestId as react key to make metadata remount for each render */}
<ViewportTree key={requestId} />
{process.env.NODE_ENV === 'development' && (
Expand Down
8 changes: 2 additions & 6 deletions test/e2e/opentelemetry/instrumentation/opentelemetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const EXTERNAL = {
const COLLECTOR_PORT = 9001

describe('opentelemetry', () => {
const { next, skipped, isNextDev } = nextTestSetup({
const { next, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
dependencies: require('./package.json').dependencies,
Expand Down Expand Up @@ -169,11 +169,7 @@ describe('opentelemetry', () => {
},
{
attributes: {
'next.clientComponentLoadCount': isNextDev
? // In dev, additional client components are being loaded
// due to RSC props being deserialized.
11
: 8,
'next.clientComponentLoadCount': 8,
'next.span_type':
'NextNodeServer.clientComponentLoading',
},
Expand Down
Loading