Repository navigation
feat(nextjs): Wait for the resumed part of a document before starting the pageload #25142
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
Changes from all commits
2301860
ca7dc2d
2a16984
40dbd17
724b444
7a4cf16
f46ce6b
320309e
26d7f2a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { headers } from 'next/headers'; | ||
|
|
||
| // Opts out of the static shell: the whole page renders on the server for every request, so the | ||
| // trace meta tags land in <head> like in a classic dynamic render. | ||
| export const instant = false; | ||
|
|
||
| export default async function Page() { | ||
| const requestHeaders = await headers(); | ||
| return <h1 id="blocking">Blocking render for {requestHeaders.get('user-agent') ? 'a browser' : 'nobody'}</h1>; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| // No request data anywhere, so the whole page is a static shell and nothing renders per request. | ||
| export default function Page() { | ||
| return <h1 id="static-shell">Static shell</h1>; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { headers } from 'next/headers'; | ||
|
|
||
| // Opts out of the static shell: the whole page renders on the server for every request, so the | ||
| // trace meta tags land in <head> like in a classic dynamic render. | ||
| export const instant = false; | ||
|
|
||
| export default async function Page() { | ||
| const requestHeaders = await headers(); | ||
| return <h1 id="blocking">Blocking render for {requestHeaders.get('user-agent') ? 'a browser' : 'nobody'}</h1>; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { headers } from 'next/headers'; | ||
| import Link from 'next/link'; | ||
| import { Suspense } from 'react'; | ||
|
|
||
| // The dynamic part, and with it the trace meta tag, streams in seconds after the shell, so a test | ||
| // can navigate while the pageload still waits for the tag. | ||
| async function SlowContent() { | ||
| await headers(); | ||
| await new Promise(resolve => setTimeout(resolve, 4000)); | ||
| return <p id="slow-content">Slow content</p>; | ||
| } | ||
|
|
||
| export default function Page() { | ||
| return ( | ||
| <> | ||
| <Link id="navigate" href="/static-shell"> | ||
| Static shell | ||
| </Link> | ||
| <Suspense fallback={<p id="slow-fallback">Loading...</p>}> | ||
| <SlowContent /> | ||
| </Suspense> | ||
| </> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| // No request data anywhere, so the whole page is a static shell and nothing renders per request. | ||
| export default function Page() { | ||
| return <h1 id="static-shell">Static shell</h1>; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import type { Integration } from '@sentry/core'; | ||
| import { browserTracingIntegration as originalBrowserTracingIntegration, isBotUserAgent } from '@sentry/react'; | ||
| import { settlePendingPageloadWait } from './routing/appRouterRoutingInstrumentation'; | ||
| import { nextRouterInstrumentNavigation, nextRouterInstrumentPageLoad } from './routing/nextRoutingInstrumentation'; | ||
|
|
||
| /** | ||
|
|
@@ -41,6 +42,13 @@ export function browserTracingIntegration( | |
| nextRouterInstrumentNavigation(client); | ||
| } | ||
|
|
||
| // A pageload that is still waiting for its trace meta tag has to exist before the navigation span, | ||
| // so the navigation ends it like any pageload it interrupts. Started later, the pageload would end | ||
| // the navigation span instead. | ||
| if (instrumentPageLoad) { | ||
| client.on('beforeStartNavigationSpan', settlePendingPageloadWait); | ||
| } | ||
|
Comment on lines
+48
to
+50
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. M: this hook is registered in Can we add an E2E test that clicks a link during a slow dynamic hole? I think that would catch it. |
||
|
|
||
| browserTracingIntegrationInstance.afterAllSetup(client); | ||
|
|
||
| if (instrumentPageLoad) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.