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

Function pageBootstrap

packages/next/src/client/page-bootstrap.ts:19–137  ·  view source on GitHub ↗
(assetPrefix: string)

Source from the content-addressed store, hash-verified

17import { dispatcher } from 'next/dist/compiled/next-devtools'
18
19export function pageBootstrap(assetPrefix: string) {
20 connectHMR({ assetPrefix, path: '/_next/webpack-hmr' })
21
22 return hydrate({ beforeRender: displayContent }).then(() => {
23 initOnDemandEntries()
24
25 let reloading = false
26
27 addMessageListener((message) => {
28 if (reloading) return
29
30 switch (message.type) {
31 case HMR_MESSAGE_SENT_TO_BROWSER.SERVER_ERROR: {
32 const errorObject = JSON.parse(message.errorJSON)
33 const error = new Error(errorObject.message)
34 error.stack = errorObject.stack
35 throw error
36 }
37 case HMR_MESSAGE_SENT_TO_BROWSER.RELOAD_PAGE: {
38 reloading = true
39 window.location.reload()
40 break
41 }
42 case HMR_MESSAGE_SENT_TO_BROWSER.DEV_PAGES_MANIFEST_UPDATE: {
43 fetch(
44 `${assetPrefix}/_next/static/development/_devPagesManifest.json`
45 )
46 .then((res) => res.json())
47 .then((manifest) => {
48 window.__DEV_PAGES_MANIFEST = manifest
49 })
50 .catch((err) => {
51 console.log(`Failed to fetch devPagesManifest`, err)
52 })
53 break
54 }
55 case HMR_MESSAGE_SENT_TO_BROWSER.MIDDLEWARE_CHANGES: {
56 return window.location.reload()
57 }
58 case HMR_MESSAGE_SENT_TO_BROWSER.CLIENT_CHANGES: {
59 // This is used in `../server/dev/turbopack-utils.ts`.
60 const isOnErrorPage = window.next.router.pathname === '/_error'
61 // On the error page we want to reload the page when a page was changed
62 if (isOnErrorPage) {
63 if (RuntimeErrorHandler.hadRuntimeError) {
64 console.warn(REACT_REFRESH_FULL_RELOAD_FROM_ERROR)
65 }
66 reloading = true
67 performFullReload(null)
68 }
69 break
70 }
71 case HMR_MESSAGE_SENT_TO_BROWSER.SERVER_ONLY_CHANGES: {
72 if (RuntimeErrorHandler.hadRuntimeError) {
73 console.warn(REACT_REFRESH_FULL_RELOAD_FROM_ERROR)
74 performFullReload(null)
75 }
76

Callers 2

next-dev.tsFile · 0.90

Calls 15

connectHMRFunction · 0.90
addMessageListenerFunction · 0.90
performFullReloadFunction · 0.90
assignFunction · 0.90
urlQueryToSearchParamsFunction · 0.90
thenMethod · 0.80
includesMethod · 0.80
buildingIndicatorShowMethod · 0.80
finallyMethod · 0.80
hydrateFunction · 0.70
reloadMethod · 0.65
replaceMethod · 0.65

Tested by

no test coverage detected