inital commit

This commit is contained in:
2026-01-01 15:25:19 +05:30
commit f0ae49465a
36361 changed files with 4894111 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { PureComponent } from 'react';
import { RuntimeErrorHandler } from '../../errors/runtime-error-handler';
import { ErrorBoundary, GlobalError as DefaultGlobalError } from '../../error-boundary';
function ErroredHtml(param) {
let { globalError: [GlobalError, globalErrorStyles], error } = param;
if (!error) {
return /*#__PURE__*/ _jsxs("html", {
children: [
/*#__PURE__*/ _jsx("head", {}),
/*#__PURE__*/ _jsx("body", {})
]
});
}
return /*#__PURE__*/ _jsxs(ErrorBoundary, {
errorComponent: DefaultGlobalError,
children: [
globalErrorStyles,
/*#__PURE__*/ _jsx(GlobalError, {
error: error
})
]
});
}
export class AppDevOverlayErrorBoundary extends PureComponent {
static getDerivedStateFromError(error) {
if (!error.stack) {
return {
isReactError: false,
reactError: null
};
}
RuntimeErrorHandler.hadRuntimeError = true;
return {
isReactError: true,
reactError: error
};
}
componentDidCatch() {
this.props.onError(this.state.isReactError);
}
render() {
const { children, globalError } = this.props;
const { isReactError, reactError } = this.state;
const fallback = /*#__PURE__*/ _jsx(ErroredHtml, {
globalError: globalError,
error: reactError
});
return isReactError ? fallback : children;
}
constructor(...args){
super(...args), this.state = {
isReactError: false,
reactError: null
};
}
}
//# sourceMappingURL=app-dev-overlay-error-boundary.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/client/components/react-dev-overlay/app/app-dev-overlay-error-boundary.tsx"],"sourcesContent":["import { PureComponent } from 'react'\nimport { RuntimeErrorHandler } from '../../errors/runtime-error-handler'\nimport {\n ErrorBoundary,\n type GlobalErrorComponent,\n GlobalError as DefaultGlobalError,\n} from '../../error-boundary'\n\ntype AppDevOverlayErrorBoundaryProps = {\n children: React.ReactNode\n globalError: [GlobalErrorComponent, React.ReactNode]\n onError: (value: boolean) => void\n}\n\ntype AppDevOverlayErrorBoundaryState = {\n isReactError: boolean\n reactError: unknown\n}\n\nfunction ErroredHtml({\n globalError: [GlobalError, globalErrorStyles],\n error,\n}: {\n globalError: [GlobalErrorComponent, React.ReactNode]\n error: unknown\n}) {\n if (!error) {\n return (\n <html>\n <head />\n <body />\n </html>\n )\n }\n return (\n <ErrorBoundary errorComponent={DefaultGlobalError}>\n {globalErrorStyles}\n <GlobalError error={error} />\n </ErrorBoundary>\n )\n}\n\nexport class AppDevOverlayErrorBoundary extends PureComponent<\n AppDevOverlayErrorBoundaryProps,\n AppDevOverlayErrorBoundaryState\n> {\n state = { isReactError: false, reactError: null }\n\n static getDerivedStateFromError(error: Error) {\n if (!error.stack) {\n return { isReactError: false, reactError: null }\n }\n\n RuntimeErrorHandler.hadRuntimeError = true\n\n return {\n isReactError: true,\n reactError: error,\n }\n }\n\n componentDidCatch() {\n this.props.onError(this.state.isReactError)\n }\n\n render() {\n const { children, globalError } = this.props\n const { isReactError, reactError } = this.state\n\n const fallback = (\n <ErroredHtml globalError={globalError} error={reactError} />\n )\n\n return isReactError ? fallback : children\n }\n}\n"],"names":["PureComponent","RuntimeErrorHandler","ErrorBoundary","GlobalError","DefaultGlobalError","ErroredHtml","globalError","globalErrorStyles","error","html","head","body","errorComponent","AppDevOverlayErrorBoundary","getDerivedStateFromError","stack","isReactError","reactError","hadRuntimeError","componentDidCatch","props","onError","state","render","children","fallback"],"mappings":";AAAA,SAASA,aAAa,QAAQ,QAAO;AACrC,SAASC,mBAAmB,QAAQ,qCAAoC;AACxE,SACEC,aAAa,EAEbC,eAAeC,kBAAkB,QAC5B,uBAAsB;AAa7B,SAASC,YAAY,KAMpB;IANoB,IAAA,EACnBC,aAAa,CAACH,aAAaI,kBAAkB,EAC7CC,KAAK,EAIN,GANoB;IAOnB,IAAI,CAACA,OAAO;QACV,qBACE,MAACC;;8BACC,KAACC;8BACD,KAACC;;;IAGP;IACA,qBACE,MAACT;QAAcU,gBAAgBR;;YAC5BG;0BACD,KAACJ;gBAAYK,OAAOA;;;;AAG1B;AAEA,OAAO,MAAMK,mCAAmCb;IAM9C,OAAOc,yBAAyBN,KAAY,EAAE;QAC5C,IAAI,CAACA,MAAMO,KAAK,EAAE;YAChB,OAAO;gBAAEC,cAAc;gBAAOC,YAAY;YAAK;QACjD;QAEAhB,oBAAoBiB,eAAe,GAAG;QAEtC,OAAO;YACLF,cAAc;YACdC,YAAYT;QACd;IACF;IAEAW,oBAAoB;QAClB,IAAI,CAACC,KAAK,CAACC,OAAO,CAAC,IAAI,CAACC,KAAK,CAACN,YAAY;IAC5C;IAEAO,SAAS;QACP,MAAM,EAAEC,QAAQ,EAAElB,WAAW,EAAE,GAAG,IAAI,CAACc,KAAK;QAC5C,MAAM,EAAEJ,YAAY,EAAEC,UAAU,EAAE,GAAG,IAAI,CAACK,KAAK;QAE/C,MAAMG,yBACJ,KAACpB;YAAYC,aAAaA;YAAaE,OAAOS;;QAGhD,OAAOD,eAAeS,WAAWD;IACnC;;QAhCK,qBAILF,QAAQ;YAAEN,cAAc;YAAOC,YAAY;QAAK;;AA6BlD"}

View File

@@ -0,0 +1,79 @@
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { useEffect, useState } from 'react';
import { AppDevOverlayErrorBoundary } from './app-dev-overlay-error-boundary';
import { FontStyles } from '../font/font-styles';
import { DevOverlay } from '../ui/dev-overlay';
import { handleClientError } from '../../errors/use-error-handler';
import { isNextRouterError } from '../../is-next-router-error';
function readSsrError() {
if (typeof document === 'undefined') {
return null;
}
const ssrErrorTemplateTag = document.querySelector('template[data-next-error-message]');
if (ssrErrorTemplateTag) {
const message = ssrErrorTemplateTag.getAttribute('data-next-error-message');
const stack = ssrErrorTemplateTag.getAttribute('data-next-error-stack');
const digest = ssrErrorTemplateTag.getAttribute('data-next-error-digest');
const error = Object.defineProperty(new Error(message), "__NEXT_ERROR_CODE", {
value: "E394",
enumerable: false,
configurable: true
});
if (digest) {
;
error.digest = digest;
}
// Skip Next.js SSR'd internal errors that which will be handled by the error boundaries.
if (isNextRouterError(error)) {
return null;
}
error.stack = stack || '';
return error;
}
return null;
}
// Needs to be in the same error boundary as the shell.
// If it commits, we know we recovered from an SSR error.
// If it doesn't commit, we errored again and React will take care of error reporting.
function ReplaySsrOnlyErrors() {
if (process.env.NODE_ENV !== 'production') {
// Need to read during render. The attributes will be gone after commit.
const ssrError = readSsrError();
// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(()=>{
if (ssrError !== null) {
// TODO(veil): Produces wrong Owner Stack
// TODO(veil): Mark as recoverable error
// TODO(veil): console.error
handleClientError(ssrError, []);
}
}, [
ssrError
]);
}
return null;
}
export function AppDevOverlay(param) {
let { state, globalError, children } = param;
const [isErrorOverlayOpen, setIsErrorOverlayOpen] = useState(false);
return /*#__PURE__*/ _jsxs(_Fragment, {
children: [
/*#__PURE__*/ _jsxs(AppDevOverlayErrorBoundary, {
globalError: globalError,
onError: setIsErrorOverlayOpen,
children: [
/*#__PURE__*/ _jsx(ReplaySsrOnlyErrors, {}),
children
]
}),
/*#__PURE__*/ _jsx(FontStyles, {}),
/*#__PURE__*/ _jsx(DevOverlay, {
state: state,
isErrorOverlayOpen: isErrorOverlayOpen,
setIsErrorOverlayOpen: setIsErrorOverlayOpen
})
]
});
}
//# sourceMappingURL=app-dev-overlay.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/client/components/react-dev-overlay/app/app-dev-overlay.tsx"],"sourcesContent":["import type { OverlayState } from '../shared'\nimport type { GlobalErrorComponent } from '../../error-boundary'\n\nimport { useEffect, useState } from 'react'\nimport { AppDevOverlayErrorBoundary } from './app-dev-overlay-error-boundary'\nimport { FontStyles } from '../font/font-styles'\nimport { DevOverlay } from '../ui/dev-overlay'\nimport { handleClientError } from '../../errors/use-error-handler'\nimport { isNextRouterError } from '../../is-next-router-error'\n\nfunction readSsrError(): Error | null {\n if (typeof document === 'undefined') {\n return null\n }\n\n const ssrErrorTemplateTag = document.querySelector(\n 'template[data-next-error-message]'\n )\n if (ssrErrorTemplateTag) {\n const message: string = ssrErrorTemplateTag.getAttribute(\n 'data-next-error-message'\n )!\n const stack = ssrErrorTemplateTag.getAttribute('data-next-error-stack')\n const digest = ssrErrorTemplateTag.getAttribute('data-next-error-digest')\n const error = new Error(message)\n if (digest) {\n ;(error as any).digest = digest\n }\n // Skip Next.js SSR'd internal errors that which will be handled by the error boundaries.\n if (isNextRouterError(error)) {\n return null\n }\n error.stack = stack || ''\n return error\n }\n\n return null\n}\n\n// Needs to be in the same error boundary as the shell.\n// If it commits, we know we recovered from an SSR error.\n// If it doesn't commit, we errored again and React will take care of error reporting.\nfunction ReplaySsrOnlyErrors() {\n if (process.env.NODE_ENV !== 'production') {\n // Need to read during render. The attributes will be gone after commit.\n const ssrError = readSsrError()\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useEffect(() => {\n if (ssrError !== null) {\n // TODO(veil): Produces wrong Owner Stack\n // TODO(veil): Mark as recoverable error\n // TODO(veil): console.error\n handleClientError(ssrError, [])\n }\n }, [ssrError])\n }\n\n return null\n}\n\nexport function AppDevOverlay({\n state,\n globalError,\n children,\n}: {\n state: OverlayState\n globalError: [GlobalErrorComponent, React.ReactNode]\n children: React.ReactNode\n}) {\n const [isErrorOverlayOpen, setIsErrorOverlayOpen] = useState(false)\n\n return (\n <>\n <AppDevOverlayErrorBoundary\n globalError={globalError}\n onError={setIsErrorOverlayOpen}\n >\n <ReplaySsrOnlyErrors />\n {children}\n </AppDevOverlayErrorBoundary>\n\n {/* Fonts can only be loaded outside the Shadow DOM. */}\n <FontStyles />\n <DevOverlay\n state={state}\n isErrorOverlayOpen={isErrorOverlayOpen}\n setIsErrorOverlayOpen={setIsErrorOverlayOpen}\n />\n </>\n )\n}\n"],"names":["useEffect","useState","AppDevOverlayErrorBoundary","FontStyles","DevOverlay","handleClientError","isNextRouterError","readSsrError","document","ssrErrorTemplateTag","querySelector","message","getAttribute","stack","digest","error","Error","ReplaySsrOnlyErrors","process","env","NODE_ENV","ssrError","AppDevOverlay","state","globalError","children","isErrorOverlayOpen","setIsErrorOverlayOpen","onError"],"mappings":";AAGA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAC3C,SAASC,0BAA0B,QAAQ,mCAAkC;AAC7E,SAASC,UAAU,QAAQ,sBAAqB;AAChD,SAASC,UAAU,QAAQ,oBAAmB;AAC9C,SAASC,iBAAiB,QAAQ,iCAAgC;AAClE,SAASC,iBAAiB,QAAQ,6BAA4B;AAE9D,SAASC;IACP,IAAI,OAAOC,aAAa,aAAa;QACnC,OAAO;IACT;IAEA,MAAMC,sBAAsBD,SAASE,aAAa,CAChD;IAEF,IAAID,qBAAqB;QACvB,MAAME,UAAkBF,oBAAoBG,YAAY,CACtD;QAEF,MAAMC,QAAQJ,oBAAoBG,YAAY,CAAC;QAC/C,MAAME,SAASL,oBAAoBG,YAAY,CAAC;QAChD,MAAMG,QAAQ,qBAAkB,CAAlB,IAAIC,MAAML,UAAV,qBAAA;mBAAA;wBAAA;0BAAA;QAAiB;QAC/B,IAAIG,QAAQ;;YACRC,MAAcD,MAAM,GAAGA;QAC3B;QACA,yFAAyF;QACzF,IAAIR,kBAAkBS,QAAQ;YAC5B,OAAO;QACT;QACAA,MAAMF,KAAK,GAAGA,SAAS;QACvB,OAAOE;IACT;IAEA,OAAO;AACT;AAEA,uDAAuD;AACvD,yDAAyD;AACzD,sFAAsF;AACtF,SAASE;IACP,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,wEAAwE;QACxE,MAAMC,WAAWd;QACjB,sDAAsD;QACtDP,UAAU;YACR,IAAIqB,aAAa,MAAM;gBACrB,yCAAyC;gBACzC,wCAAwC;gBACxC,4BAA4B;gBAC5BhB,kBAAkBgB,UAAU,EAAE;YAChC;QACF,GAAG;YAACA;SAAS;IACf;IAEA,OAAO;AACT;AAEA,OAAO,SAASC,cAAc,KAQ7B;IAR6B,IAAA,EAC5BC,KAAK,EACLC,WAAW,EACXC,QAAQ,EAKT,GAR6B;IAS5B,MAAM,CAACC,oBAAoBC,sBAAsB,GAAG1B,SAAS;IAE7D,qBACE;;0BACE,MAACC;gBACCsB,aAAaA;gBACbI,SAASD;;kCAET,KAACV;oBACAQ;;;0BAIH,KAACtB;0BACD,KAACC;gBACCmB,OAAOA;gBACPG,oBAAoBA;gBACpBC,uBAAuBA;;;;AAI/B"}

View File

@@ -0,0 +1,54 @@
import { jsx as _jsx } from "react/jsx-runtime";
import React from 'react';
import { AppDevOverlay } from './app-dev-overlay';
import { getSocketUrl } from '../utils/get-socket-url';
import { INITIAL_OVERLAY_STATE } from '../shared';
import { HMR_ACTIONS_SENT_TO_BROWSER } from '../../../../server/dev/hot-reloader-types';
import GlobalError from '../../error-boundary';
// if an error is thrown while rendering an RSC stream, this will catch it in dev
// and show the error overlay
export function createRootLevelDevOverlayElement(reactEl) {
const rootLayoutMissingTags = window.__next_root_layout_missing_tags;
const hasMissingTags = !!(rootLayoutMissingTags == null ? void 0 : rootLayoutMissingTags.length);
const socketUrl = getSocketUrl(process.env.__NEXT_ASSET_PREFIX || '');
const socket = new window.WebSocket("" + socketUrl + "/_next/webpack-hmr");
// add minimal "hot reload" support for RSC errors
const handler = (event)=>{
let obj;
try {
obj = JSON.parse(event.data);
} catch (e) {}
if (!obj || !('action' in obj)) {
return;
}
if (obj.action === HMR_ACTIONS_SENT_TO_BROWSER.SERVER_COMPONENT_CHANGES) {
window.location.reload();
}
};
socket.addEventListener('message', handler);
const FallbackLayout = hasMissingTags ? (param)=>{
let { children } = param;
return /*#__PURE__*/ _jsx("html", {
id: "__next_error__",
children: /*#__PURE__*/ _jsx("body", {
children: children
})
});
} : React.Fragment;
return /*#__PURE__*/ _jsx(FallbackLayout, {
children: /*#__PURE__*/ _jsx(AppDevOverlay, {
state: {
...INITIAL_OVERLAY_STATE,
rootLayoutMissingTags,
routerType: 'app'
},
globalError: [
GlobalError,
null
],
children: reactEl
})
});
}
//# sourceMappingURL=client-entry.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/client/components/react-dev-overlay/app/client-entry.tsx"],"sourcesContent":["import React from 'react'\nimport { AppDevOverlay } from './app-dev-overlay'\nimport { getSocketUrl } from '../utils/get-socket-url'\nimport { INITIAL_OVERLAY_STATE } from '../shared'\nimport { HMR_ACTIONS_SENT_TO_BROWSER } from '../../../../server/dev/hot-reloader-types'\nimport GlobalError from '../../error-boundary'\n\n// if an error is thrown while rendering an RSC stream, this will catch it in dev\n// and show the error overlay\nexport function createRootLevelDevOverlayElement(reactEl: React.ReactElement) {\n const rootLayoutMissingTags = window.__next_root_layout_missing_tags\n const hasMissingTags = !!rootLayoutMissingTags?.length\n const socketUrl = getSocketUrl(process.env.__NEXT_ASSET_PREFIX || '')\n const socket = new window.WebSocket(`${socketUrl}/_next/webpack-hmr`)\n\n // add minimal \"hot reload\" support for RSC errors\n const handler = (event: MessageEvent) => {\n let obj\n try {\n obj = JSON.parse(event.data)\n } catch {}\n\n if (!obj || !('action' in obj)) {\n return\n }\n\n if (obj.action === HMR_ACTIONS_SENT_TO_BROWSER.SERVER_COMPONENT_CHANGES) {\n window.location.reload()\n }\n }\n\n socket.addEventListener('message', handler)\n\n const FallbackLayout = hasMissingTags\n ? ({ children }: { children: React.ReactNode }) => (\n <html id=\"__next_error__\">\n <body>{children}</body>\n </html>\n )\n : React.Fragment\n\n return (\n <FallbackLayout>\n <AppDevOverlay\n state={{\n ...INITIAL_OVERLAY_STATE,\n rootLayoutMissingTags,\n routerType: 'app',\n }}\n globalError={[GlobalError, null]}\n >\n {reactEl}\n </AppDevOverlay>\n </FallbackLayout>\n )\n}\n"],"names":["React","AppDevOverlay","getSocketUrl","INITIAL_OVERLAY_STATE","HMR_ACTIONS_SENT_TO_BROWSER","GlobalError","createRootLevelDevOverlayElement","reactEl","rootLayoutMissingTags","window","__next_root_layout_missing_tags","hasMissingTags","length","socketUrl","process","env","__NEXT_ASSET_PREFIX","socket","WebSocket","handler","event","obj","JSON","parse","data","action","SERVER_COMPONENT_CHANGES","location","reload","addEventListener","FallbackLayout","children","html","id","body","Fragment","state","routerType","globalError"],"mappings":";AAAA,OAAOA,WAAW,QAAO;AACzB,SAASC,aAAa,QAAQ,oBAAmB;AACjD,SAASC,YAAY,QAAQ,0BAAyB;AACtD,SAASC,qBAAqB,QAAQ,YAAW;AACjD,SAASC,2BAA2B,QAAQ,4CAA2C;AACvF,OAAOC,iBAAiB,uBAAsB;AAE9C,iFAAiF;AACjF,6BAA6B;AAC7B,OAAO,SAASC,iCAAiCC,OAA2B;IAC1E,MAAMC,wBAAwBC,OAAOC,+BAA+B;IACpE,MAAMC,iBAAiB,CAAC,EAACH,yCAAAA,sBAAuBI,MAAM;IACtD,MAAMC,YAAYX,aAAaY,QAAQC,GAAG,CAACC,mBAAmB,IAAI;IAClE,MAAMC,SAAS,IAAIR,OAAOS,SAAS,CAAC,AAAC,KAAEL,YAAU;IAEjD,kDAAkD;IAClD,MAAMM,UAAU,CAACC;QACf,IAAIC;QACJ,IAAI;YACFA,MAAMC,KAAKC,KAAK,CAACH,MAAMI,IAAI;QAC7B,EAAE,UAAM,CAAC;QAET,IAAI,CAACH,OAAO,CAAE,CAAA,YAAYA,GAAE,GAAI;YAC9B;QACF;QAEA,IAAIA,IAAII,MAAM,KAAKrB,4BAA4BsB,wBAAwB,EAAE;YACvEjB,OAAOkB,QAAQ,CAACC,MAAM;QACxB;IACF;IAEAX,OAAOY,gBAAgB,CAAC,WAAWV;IAEnC,MAAMW,iBAAiBnB,iBACnB;YAAC,EAAEoB,QAAQ,EAAiC;6BAC1C,KAACC;YAAKC,IAAG;sBACP,cAAA,KAACC;0BAAMH;;;QAGX/B,MAAMmC,QAAQ;IAElB,qBACE,KAACL;kBACC,cAAA,KAAC7B;YACCmC,OAAO;gBACL,GAAGjC,qBAAqB;gBACxBK;gBACA6B,YAAY;YACd;YACAC,aAAa;gBAACjC;gBAAa;aAAK;sBAE/BE;;;AAIT"}

View File

@@ -0,0 +1,556 @@
import { jsx as _jsx } from "react/jsx-runtime";
import { useCallback, useEffect, startTransition, useMemo, useRef, useSyncExternalStore } from 'react';
import stripAnsi from 'next/dist/compiled/strip-ansi';
import formatWebpackMessages from '../utils/format-webpack-messages';
import { useRouter } from '../../navigation';
import { ACTION_BEFORE_REFRESH, ACTION_BUILD_ERROR, ACTION_BUILD_OK, ACTION_DEBUG_INFO, ACTION_DEV_INDICATOR, ACTION_REFRESH, ACTION_STATIC_INDICATOR, ACTION_UNHANDLED_ERROR, ACTION_UNHANDLED_REJECTION, ACTION_VERSION_INFO, useErrorOverlayReducer } from '../shared';
import { parseStack } from '../utils/parse-stack';
import { AppDevOverlay } from './app-dev-overlay';
import { useErrorHandler } from '../../errors/use-error-handler';
import { RuntimeErrorHandler } from '../../errors/runtime-error-handler';
import { useSendMessage, useTurbopack, useWebsocket, useWebsocketPing } from '../utils/use-websocket';
import { parseComponentStack } from '../utils/parse-component-stack';
import { HMR_ACTIONS_SENT_TO_BROWSER } from '../../../../server/dev/hot-reloader-types';
import { extractModulesFromTurbopackMessage } from '../../../../server/dev/extract-modules-from-turbopack-message';
import { REACT_REFRESH_FULL_RELOAD_FROM_ERROR } from '../shared';
import { useUntrackedPathname } from '../../navigation-untracked';
import { getReactStitchedError } from '../../errors/stitched-error';
import { shouldRenderRootLevelErrorOverlay } from '../../../lib/is-error-thrown-while-rendering-rsc';
import { handleDevBuildIndicatorHmrEvents } from '../../../dev/dev-build-indicator/internal/handle-dev-build-indicator-hmr-events';
let mostRecentCompilationHash = null;
let __nextDevClientId = Math.round(Math.random() * 100 + Date.now());
let reloading = false;
let startLatency = null;
let turbopackLastUpdateLatency = null;
let turbopackUpdatedModules = new Set();
let pendingHotUpdateWebpack = Promise.resolve();
let resolvePendingHotUpdateWebpack = ()=>{};
function setPendingHotUpdateWebpack() {
pendingHotUpdateWebpack = new Promise((resolve)=>{
resolvePendingHotUpdateWebpack = ()=>{
resolve();
};
});
}
export function waitForWebpackRuntimeHotUpdate() {
return pendingHotUpdateWebpack;
}
function handleBeforeHotUpdateWebpack(dispatcher, hasUpdates) {
if (hasUpdates) {
dispatcher.onBeforeRefresh();
}
}
function handleSuccessfulHotUpdateWebpack(dispatcher, sendMessage, updatedModules) {
resolvePendingHotUpdateWebpack();
dispatcher.onBuildOk();
reportHmrLatency(sendMessage, updatedModules);
dispatcher.onRefresh();
}
function reportHmrLatency(sendMessage, updatedModules) {
if (!startLatency) return;
// turbopack has a debounce for the "built" event which we don't want to
// incorrectly show in this number, use the last TURBOPACK_MESSAGE time
let endLatency = turbopackLastUpdateLatency != null ? turbopackLastUpdateLatency : Date.now();
const latency = endLatency - startLatency;
console.log("[Fast Refresh] done in " + latency + "ms");
sendMessage(JSON.stringify({
event: 'client-hmr-latency',
id: window.__nextDevClientId,
startTime: startLatency,
endTime: endLatency,
page: window.location.pathname,
updatedModules,
// Whether the page (tab) was hidden at the time the event occurred.
// This can impact the accuracy of the event's timing.
isPageHidden: document.visibilityState === 'hidden'
}));
}
// There is a newer version of the code available.
function handleAvailableHash(hash) {
// Update last known compilation hash.
mostRecentCompilationHash = hash;
}
/**
* Is there a newer version of this code available?
* For webpack: Check if the hash changed compared to __webpack_hash__
* For Turbopack: Always true because it doesn't have __webpack_hash__
*/ function isUpdateAvailable() {
if (process.env.TURBOPACK) {
return true;
}
/* globals __webpack_hash__ */ // __webpack_hash__ is the hash of the current compilation.
// It's a global variable injected by Webpack.
return mostRecentCompilationHash !== __webpack_hash__;
}
// Webpack disallows updates in other states.
function canApplyUpdates() {
// @ts-expect-error module.hot exists
return module.hot.status() === 'idle';
}
function afterApplyUpdates(fn) {
if (canApplyUpdates()) {
fn();
} else {
function handler(status) {
if (status === 'idle') {
// @ts-expect-error module.hot exists
module.hot.removeStatusHandler(handler);
fn();
}
}
// @ts-expect-error module.hot exists
module.hot.addStatusHandler(handler);
}
}
function performFullReload(err, sendMessage) {
const stackTrace = err && (err.stack && err.stack.split('\n').slice(0, 5).join('\n') || err.message || err + '');
sendMessage(JSON.stringify({
event: 'client-full-reload',
stackTrace,
hadRuntimeError: !!RuntimeErrorHandler.hadRuntimeError,
dependencyChain: err ? err.dependencyChain : undefined
}));
if (reloading) return;
reloading = true;
window.location.reload();
}
// Attempt to update code on the fly, fall back to a hard reload.
function tryApplyUpdates(onBeforeUpdate, onHotUpdateSuccess, sendMessage, dispatcher) {
if (!isUpdateAvailable() || !canApplyUpdates()) {
resolvePendingHotUpdateWebpack();
dispatcher.onBuildOk();
reportHmrLatency(sendMessage, []);
return;
}
function handleApplyUpdates(err, updatedModules) {
if (err || RuntimeErrorHandler.hadRuntimeError || !updatedModules) {
if (err) {
console.warn('[Fast Refresh] performing full reload\n\n' + "Fast Refresh will perform a full reload when you edit a file that's imported by modules outside of the React rendering tree.\n" + 'You might have a file which exports a React component but also exports a value that is imported by a non-React component file.\n' + 'Consider migrating the non-React component export to a separate file and importing it into both files.\n\n' + 'It is also possible the parent component of the component you edited is a class component, which disables Fast Refresh.\n' + 'Fast Refresh requires at least one parent function component in your React tree.');
} else if (RuntimeErrorHandler.hadRuntimeError) {
console.warn(REACT_REFRESH_FULL_RELOAD_FROM_ERROR);
}
performFullReload(err, sendMessage);
return;
}
const hasUpdates = Boolean(updatedModules.length);
if (typeof onHotUpdateSuccess === 'function') {
// Maybe we want to do something.
onHotUpdateSuccess(updatedModules);
}
if (isUpdateAvailable()) {
// While we were updating, there was a new update! Do it again.
tryApplyUpdates(hasUpdates ? ()=>{} : onBeforeUpdate, hasUpdates ? ()=>dispatcher.onBuildOk() : onHotUpdateSuccess, sendMessage, dispatcher);
} else {
dispatcher.onBuildOk();
if (process.env.__NEXT_TEST_MODE) {
afterApplyUpdates(()=>{
if (self.__NEXT_HMR_CB) {
self.__NEXT_HMR_CB();
self.__NEXT_HMR_CB = null;
}
});
}
}
}
// https://webpack.js.org/api/hot-module-replacement/#check
// @ts-expect-error module.hot exists
module.hot.check(/* autoApply */ false).then((updatedModules)=>{
if (!updatedModules) {
return null;
}
if (typeof onBeforeUpdate === 'function') {
const hasUpdates = Boolean(updatedModules.length);
onBeforeUpdate(hasUpdates);
}
// https://webpack.js.org/api/hot-module-replacement/#apply
// @ts-expect-error module.hot exists
return module.hot.apply();
}).then((updatedModules)=>{
handleApplyUpdates(null, updatedModules);
}, (err)=>{
handleApplyUpdates(err, null);
});
}
/** Handles messages from the sevrer for the App Router. */ function processMessage(obj, sendMessage, processTurbopackMessage, router, dispatcher, appIsrManifestRef, pathnameRef) {
if (!('action' in obj)) {
return;
}
function handleErrors(errors) {
// "Massage" webpack messages.
const formatted = formatWebpackMessages({
errors: errors,
warnings: []
});
// Only show the first error.
dispatcher.onBuildError(formatted.errors[0]);
// Also log them to the console.
for(let i = 0; i < formatted.errors.length; i++){
console.error(stripAnsi(formatted.errors[i]));
}
// Do not attempt to reload now.
// We will reload on next success instead.
if (process.env.__NEXT_TEST_MODE) {
if (self.__NEXT_HMR_CB) {
self.__NEXT_HMR_CB(formatted.errors[0]);
self.__NEXT_HMR_CB = null;
}
}
}
function handleHotUpdate() {
if (process.env.TURBOPACK) {
dispatcher.onBuildOk();
reportHmrLatency(sendMessage, [
...turbopackUpdatedModules
]);
} else {
tryApplyUpdates(function onBeforeHotUpdate(hasUpdates) {
handleBeforeHotUpdateWebpack(dispatcher, hasUpdates);
}, function onSuccessfulHotUpdate(webpackUpdatedModules) {
// Only dismiss it when we're sure it's a hot update.
// Otherwise it would flicker right before the reload.
handleSuccessfulHotUpdateWebpack(dispatcher, sendMessage, webpackUpdatedModules);
}, sendMessage, dispatcher);
}
}
switch(obj.action){
case HMR_ACTIONS_SENT_TO_BROWSER.ISR_MANIFEST:
{
if (process.env.__NEXT_DEV_INDICATOR) {
if (appIsrManifestRef) {
appIsrManifestRef.current = obj.data;
// handle initial status on receiving manifest
// navigation is handled in useEffect for pathname changes
// as we'll receive the updated manifest before usePathname
// triggers for new value
if (pathnameRef.current in obj.data) {
dispatcher.onStaticIndicator(true);
} else {
dispatcher.onStaticIndicator(false);
}
}
}
break;
}
case HMR_ACTIONS_SENT_TO_BROWSER.BUILDING:
{
startLatency = Date.now();
turbopackLastUpdateLatency = null;
turbopackUpdatedModules.clear();
if (!process.env.TURBOPACK) {
setPendingHotUpdateWebpack();
}
console.log('[Fast Refresh] rebuilding');
break;
}
case HMR_ACTIONS_SENT_TO_BROWSER.BUILT:
case HMR_ACTIONS_SENT_TO_BROWSER.SYNC:
{
if (obj.hash) {
handleAvailableHash(obj.hash);
}
const { errors, warnings } = obj;
// Is undefined when it's a 'built' event
if ('versionInfo' in obj) dispatcher.onVersionInfo(obj.versionInfo);
if ('debug' in obj && obj.debug) dispatcher.onDebugInfo(obj.debug);
if ('devIndicator' in obj) dispatcher.onDevIndicator(obj.devIndicator);
const hasErrors = Boolean(errors && errors.length);
// Compilation with errors (e.g. syntax error or missing modules).
if (hasErrors) {
sendMessage(JSON.stringify({
event: 'client-error',
errorCount: errors.length,
clientId: __nextDevClientId
}));
handleErrors(errors);
return;
}
const hasWarnings = Boolean(warnings && warnings.length);
if (hasWarnings) {
sendMessage(JSON.stringify({
event: 'client-warning',
warningCount: warnings.length,
clientId: __nextDevClientId
}));
// Print warnings to the console.
const formattedMessages = formatWebpackMessages({
warnings: warnings,
errors: []
});
for(let i = 0; i < formattedMessages.warnings.length; i++){
if (i === 5) {
console.warn('There were more warnings in other files.\n' + 'You can find a complete log in the terminal.');
break;
}
console.warn(stripAnsi(formattedMessages.warnings[i]));
}
// No early return here as we need to apply modules in the same way between warnings only and compiles without warnings
}
sendMessage(JSON.stringify({
event: 'client-success',
clientId: __nextDevClientId
}));
if (obj.action === HMR_ACTIONS_SENT_TO_BROWSER.BUILT) {
// Handle hot updates
handleHotUpdate();
}
return;
}
case HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_CONNECTED:
{
processTurbopackMessage({
type: HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_CONNECTED,
data: {
sessionId: obj.data.sessionId
}
});
break;
}
case HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_MESSAGE:
{
dispatcher.onBeforeRefresh();
processTurbopackMessage({
type: HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_MESSAGE,
data: obj.data
});
dispatcher.onRefresh();
if (RuntimeErrorHandler.hadRuntimeError) {
console.warn(REACT_REFRESH_FULL_RELOAD_FROM_ERROR);
performFullReload(null, sendMessage);
}
for (const module1 of extractModulesFromTurbopackMessage(obj.data)){
turbopackUpdatedModules.add(module1);
}
turbopackLastUpdateLatency = Date.now();
break;
}
// TODO-APP: make server component change more granular
case HMR_ACTIONS_SENT_TO_BROWSER.SERVER_COMPONENT_CHANGES:
{
sendMessage(JSON.stringify({
event: 'server-component-reload-page',
clientId: __nextDevClientId,
hash: obj.hash
}));
// Store the latest hash in a session cookie so that it's sent back to the
// server with any subsequent requests.
document.cookie = "__next_hmr_refresh_hash__=" + obj.hash;
if (RuntimeErrorHandler.hadRuntimeError) {
if (reloading) return;
reloading = true;
return window.location.reload();
}
startTransition(()=>{
router.hmrRefresh();
dispatcher.onRefresh();
});
if (process.env.__NEXT_TEST_MODE) {
if (self.__NEXT_HMR_CB) {
self.__NEXT_HMR_CB();
self.__NEXT_HMR_CB = null;
}
}
return;
}
case HMR_ACTIONS_SENT_TO_BROWSER.RELOAD_PAGE:
{
sendMessage(JSON.stringify({
event: 'client-reload-page',
clientId: __nextDevClientId
}));
if (reloading) return;
reloading = true;
return window.location.reload();
}
case HMR_ACTIONS_SENT_TO_BROWSER.ADDED_PAGE:
case HMR_ACTIONS_SENT_TO_BROWSER.REMOVED_PAGE:
{
// TODO-APP: potentially only refresh if the currently viewed page was added/removed.
return router.hmrRefresh();
}
case HMR_ACTIONS_SENT_TO_BROWSER.SERVER_ERROR:
{
const { errorJSON } = obj;
if (errorJSON) {
const { message, stack } = JSON.parse(errorJSON);
const error = Object.defineProperty(new Error(message), "__NEXT_ERROR_CODE", {
value: "E394",
enumerable: false,
configurable: true
});
error.stack = stack;
handleErrors([
error
]);
}
return;
}
case HMR_ACTIONS_SENT_TO_BROWSER.DEV_PAGES_MANIFEST_UPDATE:
{
return;
}
default:
{}
}
}
export default function HotReload(param) {
let { assetPrefix, children, globalError } = param;
const [state, dispatch] = useErrorOverlayReducer('app');
const dispatcher = useMemo(()=>{
return {
onBuildOk () {
dispatch({
type: ACTION_BUILD_OK
});
},
onBuildError (message) {
dispatch({
type: ACTION_BUILD_ERROR,
message
});
},
onBeforeRefresh () {
dispatch({
type: ACTION_BEFORE_REFRESH
});
},
onRefresh () {
dispatch({
type: ACTION_REFRESH
});
},
onVersionInfo (versionInfo) {
dispatch({
type: ACTION_VERSION_INFO,
versionInfo
});
},
onStaticIndicator (status) {
dispatch({
type: ACTION_STATIC_INDICATOR,
staticIndicator: status
});
},
onDebugInfo (debugInfo) {
dispatch({
type: ACTION_DEBUG_INFO,
debugInfo
});
},
onDevIndicator (devIndicator) {
dispatch({
type: ACTION_DEV_INDICATOR,
devIndicator
});
}
};
}, [
dispatch
]);
// We render a separate error overlay at the root when an error is thrown from rendering RSC, so
// we should not render an additional error overlay in the descendent. However, we need to
// keep rendering these hooks to ensure HMR works when the error is addressed.
const shouldRenderErrorOverlay = useSyncExternalStore(()=>()=>{}, ()=>!shouldRenderRootLevelErrorOverlay(), ()=>true);
const handleOnUnhandledError = useCallback((error)=>{
const errorDetails = error.details;
// Component stack is added to the error in use-error-handler in case there was a hydration error
const componentStackTrace = error._componentStack || (errorDetails == null ? void 0 : errorDetails.componentStack);
const warning = errorDetails == null ? void 0 : errorDetails.warning;
dispatch({
type: ACTION_UNHANDLED_ERROR,
reason: error,
frames: parseStack(error.stack || ''),
componentStackFrames: typeof componentStackTrace === 'string' ? parseComponentStack(componentStackTrace) : undefined,
warning
});
}, [
dispatch
]);
const handleOnUnhandledRejection = useCallback((reason)=>{
const stitchedError = getReactStitchedError(reason);
dispatch({
type: ACTION_UNHANDLED_REJECTION,
reason: stitchedError,
frames: parseStack(stitchedError.stack || '')
});
}, [
dispatch
]);
useErrorHandler(handleOnUnhandledError, handleOnUnhandledRejection);
const webSocketRef = useWebsocket(assetPrefix);
useWebsocketPing(webSocketRef);
const sendMessage = useSendMessage(webSocketRef);
const processTurbopackMessage = useTurbopack(sendMessage, (err)=>performFullReload(err, sendMessage));
const router = useRouter();
// We don't want access of the pathname for the dev tools to trigger a dynamic
// access (as the dev overlay will never be present in production).
const pathname = useUntrackedPathname();
const appIsrManifestRef = useRef({});
const pathnameRef = useRef(pathname);
if (process.env.__NEXT_DEV_INDICATOR) {
// this conditional is only for dead-code elimination which
// isn't a runtime conditional only build-time so ignore hooks rule
// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(()=>{
pathnameRef.current = pathname;
const appIsrManifest = appIsrManifestRef.current;
if (appIsrManifest) {
if (pathname && pathname in appIsrManifest) {
try {
dispatcher.onStaticIndicator(true);
} catch (reason) {
let message = '';
if (reason instanceof DOMException) {
var _reason_stack;
// Most likely a SecurityError, because of an unavailable localStorage
message = (_reason_stack = reason.stack) != null ? _reason_stack : reason.message;
} else if (reason instanceof Error) {
var _reason_stack1;
message = 'Error: ' + reason.message + '\n' + ((_reason_stack1 = reason.stack) != null ? _reason_stack1 : '');
} else {
message = 'Unexpected Exception: ' + reason;
}
console.warn('[HMR] ' + message);
}
} else {
dispatcher.onStaticIndicator(false);
}
}
}, [
pathname,
dispatcher
]);
}
useEffect(()=>{
const websocket = webSocketRef.current;
if (!websocket) return;
const handler = (event)=>{
try {
const obj = JSON.parse(event.data);
handleDevBuildIndicatorHmrEvents(obj);
processMessage(obj, sendMessage, processTurbopackMessage, router, dispatcher, appIsrManifestRef, pathnameRef);
} catch (err) {
var _err_stack;
console.warn('[HMR] Invalid message: ' + JSON.stringify(event.data) + '\n' + ((_err_stack = err == null ? void 0 : err.stack) != null ? _err_stack : ''));
}
};
websocket.addEventListener('message', handler);
return ()=>websocket.removeEventListener('message', handler);
}, [
sendMessage,
router,
webSocketRef,
dispatcher,
processTurbopackMessage,
appIsrManifestRef
]);
if (shouldRenderErrorOverlay) {
return /*#__PURE__*/ _jsx(AppDevOverlay, {
state: state,
globalError: globalError,
children: children
});
}
return children;
}
//# sourceMappingURL=hot-reloader-client.js.map

File diff suppressed because one or more lines are too long