mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
'use client'
|
||
|
||
import { useSyncExternalStore } from 'react'
|
||
|
||
const reactServerRequestsServerSnapshot: never[] = []
|
||
const ServerRequestsStore = {
|
||
subscribe:
|
||
typeof window === 'undefined'
|
||
? () => () => {}
|
||
: window.reactServerRequests.subscribe,
|
||
getSnapshot:
|
||
typeof window === 'undefined'
|
||
? () => []
|
||
: window.reactServerRequests.getStoreSnapshot,
|
||
getServerSnapshot: () => reactServerRequestsServerSnapshot,
|
||
}
|
||
|
||
export function ReactServerRequests() {
|
||
const reactServerRequests = useSyncExternalStore(
|
||
ServerRequestsStore.subscribe,
|
||
ServerRequestsStore.getSnapshot,
|
||
ServerRequestsStore.getServerSnapshot
|
||
)
|
||
|
||
return (
|
||
<>
|
||
<p>{reactServerRequests.length} Server Request entries</p>
|
||
<ol>
|
||
{reactServerRequests.map((request, index) => (
|
||
<li key={index}>
|
||
<details>
|
||
<summary>
|
||
<strong>
|
||
{request.type}: {request.name || '<Unnamed>'}
|
||
</strong>
|
||
({Math.round(request.startTime)}ms–
|
||
{Math.round(request.endTime)}ms)
|
||
</summary>
|
||
<pre>{JSON.stringify(request.properties, null, 2)}</pre>
|
||
</details>
|
||
</li>
|
||
))}
|
||
</ol>
|
||
</>
|
||
)
|
||
}
|