Skip to content

馃悰 Prevent duplicate Next.js RUM views from discarded renders - #4940

Draft
BeltranBulbarellaDD wants to merge 1 commit into
mainfrom
beltran.bulbarella/next_js_render_issue
Draft

馃悰 Prevent duplicate Next.js RUM views from discarded renders#4940
BeltranBulbarellaDD wants to merge 1 commit into
mainfrom
beltran.bulbarella/next_js_render_issue

Conversation

@BeltranBulbarellaDD

@BeltranBulbarellaDD BeltranBulbarellaDD commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Motivation

Fixes #4931, where DatadogAppRouter and DatadogPagesRouter could call startNextjsView() during a render that React later discarded. Because the render-phase useRef guard is recreated for discarded fibers, those calls could create duplicate RUM views.

Changes

  • Move the shared view-start logic into useStartNextjsView, which calls startNextjsView() from useLayoutEffect after the render commits.
  • Reuse the hook in both App Router and Pages Router integrations while preserving route-pattern view names and concrete-path navigation detection.
  • Wait for the Pages Router to be ready before starting the initial view.
  • Add unit tests for Strict Mode, route changes, and router readiness.
  • Add an end-to-end regression test covering a discarded App Router render.

Test instructions

  • Run the Next.js router unit tests.
  • Run the Next.js plugin E2E scenario, including should not create a view for a discarded App Router render.

Checklist

  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Tested locally
  • Tested on staging
  • Updated documentation and/or relevant AGENTS.md file

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Aug 12, 2026

Copy link
Copy Markdown

PipelinesTests

鈿狅笍 Warnings

馃殾 1 Pipeline job failed

Lint PR title | lint 聽聽View in DatadogGitHub Actions

See error PR title must start with one of the allowed gitmoji prefixes: current title 'test nextjs rendering issue'.

鈩癸笍 Info

No other issues found (see more)

馃И All tests passed
鉂勶笍 No new flaky tests detected

Useful? React with 馃憤 / 馃憥

This comment will be updated automatically if new data arrives.
馃敆 Commit SHA: 7039343 | Docs | Datadog PR Page | Give us feedback!

@BeltranBulbarellaDD BeltranBulbarellaDD changed the title test nextjs rendering issue 馃悰 Prevent duplicate Next.js RUM views from discarded renders Aug 17, 2026
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.

馃悰 Router components create duplicate RUM views: render-phase startView() guarded only by useRef

1 participant