forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes vercel#19399
- Loading branch information
Showing
5 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* eslint-disable camelcase */ | ||
import App from 'next/app' | ||
|
||
if (typeof navigator !== 'undefined') { | ||
window.__BEACONS = window.__BEACONS || [] | ||
|
||
navigator.sendBeacon = async function () { | ||
const args = await Promise.all( | ||
[...arguments].map((v) => { | ||
if (v instanceof Blob) { | ||
return v.text() | ||
} | ||
return v | ||
}) | ||
) | ||
|
||
window.__BEACONS.push(args) | ||
} | ||
} | ||
|
||
export default class MyApp extends App {} | ||
|
||
export function reportWebVitals(data) { | ||
navigator.sendBeacon('/test', new URLSearchParams(data).toString()) | ||
} |
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,15 @@ | ||
import Link from 'next/link' | ||
|
||
const Home = () => { | ||
return ( | ||
<div> | ||
<h1>Foo!</h1> | ||
<h2>bar!</h2> | ||
<Link href="/other"> | ||
<a id="to-other">Other</a> | ||
</Link> | ||
</div> | ||
) | ||
} | ||
|
||
export default Home |
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,11 @@ | ||
const Other = () => { | ||
return ( | ||
<div> | ||
<h1>Foo!</h1> | ||
<h2>bar!</h2> | ||
<div id="on-other"></div> | ||
</div> | ||
) | ||
} | ||
|
||
export default Other |
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,37 @@ | ||
/* eslint-env jest */ | ||
|
||
import { findPort, killApp, nextBuild, nextStart } from 'next-test-utils' | ||
import webdriver from 'next-webdriver' | ||
import { join } from 'path' | ||
|
||
const appDir = join(__dirname, '../') | ||
let appPort | ||
let server | ||
jest.setTimeout(1000 * 60 * 2) | ||
|
||
describe('hydrate/render ordering', () => { | ||
beforeAll(async () => { | ||
appPort = await findPort() | ||
await nextBuild(appDir, [], {}) | ||
server = await nextStart(appDir, appPort) | ||
}) | ||
afterAll(() => killApp(server)) | ||
|
||
it('correctly measures hydrate followed by render', async () => { | ||
const browser = await webdriver(appPort, '/') | ||
await browser.waitForElementByCss('#to-other') | ||
await browser.elementByCss('#to-other').click() | ||
await browser.waitForElementByCss('#on-other') | ||
|
||
const beacons = (await browser.eval('window.__BEACONS')) | ||
.map(([, value]) => Object.fromEntries(new URLSearchParams(value))) | ||
.filter((p) => p.label === 'custom') | ||
expect(beacons).toMatchObject([ | ||
{ name: 'Next.js-hydration' }, | ||
{ name: 'Next.js-render' }, | ||
{ name: 'Next.js-route-change-to-render' }, | ||
]) | ||
|
||
await browser.close() | ||
}) | ||
}) |