(opts?: { beforeRender?: () => Promise<void> })
| 830 | } |
| 831 | |
| 832 | export 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 | } |
no test coverage detected