-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref(nextjs): Improve app router routing instrumentation accuracy (#13695
) Improves the Next.js routing instrumentation by patching the Next.js router and instrumenting window popstates. A few details on this PR that might explain weird-looking logic: - The patching of the router is in a setInterval because Next.js may take a while to write the router to the window object and we don't have a cue when that has happened. - We are using a combination of patching `router.back`/`router.forward` and the `popstate` event to emit a properly named transaction, because `router.back` and `router.forward` aren't passed any useful strings we could use as txn names. - Because there is a slight delay between the `router.back`/`router.forward` calls and the `popstate` event, we temporarily give the navigation span an invalid name that we use as an indicator to drop if one may leak through.
- Loading branch information
Showing
14 changed files
with
352 additions
and
229 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
...s/e2e-tests/test-applications/nextjs-app-dir/app/navigation/[param]/browser-back/page.tsx
This file contains 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 @@ | ||
import Link from 'next/link'; | ||
|
||
export const dynamic = 'force-dynamic'; | ||
|
||
export default function Page() { | ||
return <Link href="/navigation">Go back home</Link>; | ||
} |
7 changes: 7 additions & 0 deletions
7
...s/e2e-tests/test-applications/nextjs-app-dir/app/navigation/[param]/link-replace/page.tsx
This file contains 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 @@ | ||
import Link from 'next/link'; | ||
|
||
export const dynamic = 'force-dynamic'; | ||
|
||
export default function Page() { | ||
return <Link href="/navigation">Go back home</Link>; | ||
} |
7 changes: 7 additions & 0 deletions
7
dev-packages/e2e-tests/test-applications/nextjs-app-dir/app/navigation/[param]/link/page.tsx
This file contains 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 @@ | ||
import Link from 'next/link'; | ||
|
||
export const dynamic = 'force-dynamic'; | ||
|
||
export default function Page() { | ||
return <Link href="/navigation">Go back home</Link>; | ||
} |
7 changes: 7 additions & 0 deletions
7
...es/e2e-tests/test-applications/nextjs-app-dir/app/navigation/[param]/router-back/page.tsx
This file contains 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 @@ | ||
import Link from 'next/link'; | ||
|
||
export const dynamic = 'force-dynamic'; | ||
|
||
export default function Page() { | ||
return <Link href="/navigation">Go back home</Link>; | ||
} |
5 changes: 5 additions & 0 deletions
5
...es/e2e-tests/test-applications/nextjs-app-dir/app/navigation/[param]/router-push/page.tsx
This file contains 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,5 @@ | ||
export const dynamic = 'force-dynamic'; | ||
|
||
export default function Page() { | ||
return <p>hello world</p>; | ||
} |
5 changes: 5 additions & 0 deletions
5
...e2e-tests/test-applications/nextjs-app-dir/app/navigation/[param]/router-replace/page.tsx
This file contains 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,5 @@ | ||
export const dynamic = 'force-dynamic'; | ||
|
||
export default function Page() { | ||
return <p>hello world</p>; | ||
} |
57 changes: 57 additions & 0 deletions
57
dev-packages/e2e-tests/test-applications/nextjs-app-dir/app/navigation/page.tsx
This file contains 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,57 @@ | ||
'use client'; | ||
|
||
import Link from 'next/link'; | ||
import { useRouter } from 'next/navigation'; | ||
|
||
export default function Page() { | ||
const router = useRouter(); | ||
|
||
return ( | ||
<ul> | ||
<li> | ||
<button | ||
onClick={() => { | ||
router.push('/navigation/42/router-push'); | ||
}} | ||
> | ||
router.push() | ||
</button> | ||
</li> | ||
<li> | ||
<button | ||
onClick={() => { | ||
router.replace('/navigation/42/router-replace'); | ||
}} | ||
> | ||
router.replace() | ||
</button> | ||
</li> | ||
<li> | ||
<button | ||
onClick={() => { | ||
router.forward(); | ||
}} | ||
> | ||
router.forward() | ||
</button> | ||
</li> | ||
<li> | ||
<button | ||
onClick={() => { | ||
router.back(); | ||
}} | ||
> | ||
router.back() | ||
</button> | ||
</li> | ||
<li> | ||
<Link href="/navigation/42/link">Normal Link</Link> | ||
</li> | ||
<li> | ||
<Link href="/navigation/42/link-replace" replace> | ||
Link Replace | ||
</Link> | ||
</li> | ||
</ul> | ||
); | ||
} |
This file contains 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 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 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 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.