MCPcopy
hub / github.com/vercel/next.js / hydrate

Function hydrate

packages/next/src/client/index.tsx:832–995  ·  view source on GitHub ↗
(opts?: { beforeRender?: () => Promise<void> })

Source from the content-addressed store, hash-verified

830}
831
832export async function hydrate(opts?: { beforeRender?: () => Promise<void> }) {
833 let initialErr = initialData.err
834
835 try {
836 const appEntrypoint = await pageLoader.routeLoader.whenEntrypoint('/_app')
837 if ('error' in appEntrypoint) {
838 throw appEntrypoint.error
839 }
840
841 const { component: app, exports: mod } = appEntrypoint
842 CachedApp = app as AppComponent
843 if (mod && mod.reportWebVitals) {
844 onPerfEntry = ({
845 id,
846 name,
847 startTime,
848 value,
849 duration,
850 entryType,
851 entries,
852 attribution,
853 }: any): void => {
854 // Combines timestamp with random number for unique ID
855 const uniqueID: string = `${Date.now()}-${
856 Math.floor(Math.random() * (9e12 - 1)) + 1e12
857 }`
858 let perfStartEntry: string | undefined
859
860 if (entries && entries.length) {
861 perfStartEntry = entries[0].startTime
862 }
863
864 const webVitals: NextWebVitalsMetric = {
865 id: id || uniqueID,
866 name,
867 startTime: startTime || perfStartEntry,
868 value: value == null ? duration : value,
869 label:
870 entryType === 'mark' || entryType === 'measure'
871 ? 'custom'
872 : 'web-vital',
873 }
874 if (attribution) {
875 webVitals.attribution = attribution
876 }
877 mod.reportWebVitals(webVitals)
878 }
879 }
880
881 const pageEntrypoint =
882 // The dev server fails to serve script assets when there's a hydration
883 // error, so we need to skip waiting for the entrypoint.
884 process.env.NODE_ENV === 'development' && initialData.err
885 ? { error: initialData.err }
886 : await pageLoader.routeLoader.whenEntrypoint(initialData.page)
887 if ('error' in pageEntrypoint) {
888 throw pageEntrypoint.error
889 }

Callers 8

next.tsFile · 0.70
app-next.tsFile · 0.70
next-turbopack.tsFile · 0.70
app-next-dev.tsFile · 0.70
loadScriptsInSequenceFunction · 0.70
appBootstrapFunction · 0.70
pageBootstrapFunction · 0.70

Calls 10

getProperErrorFunction · 0.90
isNextRouterErrorFunction · 0.90
createRouterFunction · 0.90
getServerErrorFunction · 0.85
whenEntrypointMethod · 0.80
assignMethod · 0.80
renderFunction · 0.70
requireFunction · 0.50
setTimeoutFunction · 0.50
nowMethod · 0.45

Tested by

no test coverage detected