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,27 @@
import { PureComponent } from 'react';
import { type GlobalErrorComponent } from '../../error-boundary';
type AppDevOverlayErrorBoundaryProps = {
children: React.ReactNode;
globalError: [GlobalErrorComponent, React.ReactNode];
onError: (value: boolean) => void;
};
type AppDevOverlayErrorBoundaryState = {
isReactError: boolean;
reactError: unknown;
};
export declare class AppDevOverlayErrorBoundary extends PureComponent<AppDevOverlayErrorBoundaryProps, AppDevOverlayErrorBoundaryState> {
state: {
isReactError: boolean;
reactError: null;
};
static getDerivedStateFromError(error: Error): {
isReactError: boolean;
reactError: null;
} | {
isReactError: boolean;
reactError: Error;
};
componentDidCatch(): void;
render(): string | number | bigint | boolean | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | import("react").ReactPortal | Iterable<import("react").ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null | undefined;
}
export {};

View File

@@ -0,0 +1,75 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "AppDevOverlayErrorBoundary", {
enumerable: true,
get: function() {
return AppDevOverlayErrorBoundary;
}
});
const _jsxruntime = require("react/jsx-runtime");
const _react = require("react");
const _runtimeerrorhandler = require("../../errors/runtime-error-handler");
const _errorboundary = require("../../error-boundary");
function ErroredHtml(param) {
let { globalError: [GlobalError, globalErrorStyles], error } = param;
if (!error) {
return /*#__PURE__*/ (0, _jsxruntime.jsxs)("html", {
children: [
/*#__PURE__*/ (0, _jsxruntime.jsx)("head", {}),
/*#__PURE__*/ (0, _jsxruntime.jsx)("body", {})
]
});
}
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_errorboundary.ErrorBoundary, {
errorComponent: _errorboundary.GlobalError,
children: [
globalErrorStyles,
/*#__PURE__*/ (0, _jsxruntime.jsx)(GlobalError, {
error: error
})
]
});
}
class AppDevOverlayErrorBoundary extends _react.PureComponent {
static getDerivedStateFromError(error) {
if (!error.stack) {
return {
isReactError: false,
reactError: null
};
}
_runtimeerrorhandler.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__*/ (0, _jsxruntime.jsx)(ErroredHtml, {
globalError: globalError,
error: reactError
});
return isReactError ? fallback : children;
}
constructor(...args){
super(...args), this.state = {
isReactError: false,
reactError: null
};
}
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# 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":["AppDevOverlayErrorBoundary","ErroredHtml","globalError","GlobalError","globalErrorStyles","error","html","head","body","ErrorBoundary","errorComponent","DefaultGlobalError","PureComponent","getDerivedStateFromError","stack","isReactError","reactError","RuntimeErrorHandler","hadRuntimeError","componentDidCatch","props","onError","state","render","children","fallback"],"mappings":";;;;+BA0CaA;;;eAAAA;;;;uBA1CiB;qCACM;+BAK7B;AAaP,SAASC,YAAY,KAMpB;IANoB,IAAA,EACnBC,aAAa,CAACC,aAAaC,kBAAkB,EAC7CC,KAAK,EAIN,GANoB;IAOnB,IAAI,CAACA,OAAO;QACV,qBACE,sBAACC;;8BACC,qBAACC;8BACD,qBAACC;;;IAGP;IACA,qBACE,sBAACC,4BAAa;QAACC,gBAAgBC,0BAAkB;;YAC9CP;0BACD,qBAACD;gBAAYE,OAAOA;;;;AAG1B;AAEO,MAAML,mCAAmCY,oBAAa;IAM3D,OAAOC,yBAAyBR,KAAY,EAAE;QAC5C,IAAI,CAACA,MAAMS,KAAK,EAAE;YAChB,OAAO;gBAAEC,cAAc;gBAAOC,YAAY;YAAK;QACjD;QAEAC,wCAAmB,CAACC,eAAe,GAAG;QAEtC,OAAO;YACLH,cAAc;YACdC,YAAYX;QACd;IACF;IAEAc,oBAAoB;QAClB,IAAI,CAACC,KAAK,CAACC,OAAO,CAAC,IAAI,CAACC,KAAK,CAACP,YAAY;IAC5C;IAEAQ,SAAS;QACP,MAAM,EAAEC,QAAQ,EAAEtB,WAAW,EAAE,GAAG,IAAI,CAACkB,KAAK;QAC5C,MAAM,EAAEL,YAAY,EAAEC,UAAU,EAAE,GAAG,IAAI,CAACM,KAAK;QAE/C,MAAMG,yBACJ,qBAACxB;YAAYC,aAAaA;YAAaG,OAAOW;;QAGhD,OAAOD,eAAeU,WAAWD;IACnC;;QAhCK,qBAILF,QAAQ;YAAEP,cAAc;YAAOC,YAAY;QAAK;;AA6BlD"}

View File

@@ -0,0 +1,7 @@
import type { OverlayState } from '../shared';
import type { GlobalErrorComponent } from '../../error-boundary';
export declare function AppDevOverlay({ state, globalError, children, }: {
state: OverlayState;
globalError: [GlobalErrorComponent, React.ReactNode];
children: React.ReactNode;
}): import("react/jsx-runtime").JSX.Element;

View File

@@ -0,0 +1,95 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "AppDevOverlay", {
enumerable: true,
get: function() {
return AppDevOverlay;
}
});
const _jsxruntime = require("react/jsx-runtime");
const _react = require("react");
const _appdevoverlayerrorboundary = require("./app-dev-overlay-error-boundary");
const _fontstyles = require("../font/font-styles");
const _devoverlay = require("../ui/dev-overlay");
const _useerrorhandler = require("../../errors/use-error-handler");
const _isnextroutererror = require("../../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 ((0, _isnextroutererror.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
(0, _react.useEffect)(()=>{
if (ssrError !== null) {
// TODO(veil): Produces wrong Owner Stack
// TODO(veil): Mark as recoverable error
// TODO(veil): console.error
(0, _useerrorhandler.handleClientError)(ssrError, []);
}
}, [
ssrError
]);
}
return null;
}
function AppDevOverlay(param) {
let { state, globalError, children } = param;
const [isErrorOverlayOpen, setIsErrorOverlayOpen] = (0, _react.useState)(false);
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
children: [
/*#__PURE__*/ (0, _jsxruntime.jsxs)(_appdevoverlayerrorboundary.AppDevOverlayErrorBoundary, {
globalError: globalError,
onError: setIsErrorOverlayOpen,
children: [
/*#__PURE__*/ (0, _jsxruntime.jsx)(ReplaySsrOnlyErrors, {}),
children
]
}),
/*#__PURE__*/ (0, _jsxruntime.jsx)(_fontstyles.FontStyles, {}),
/*#__PURE__*/ (0, _jsxruntime.jsx)(_devoverlay.DevOverlay, {
state: state,
isErrorOverlayOpen: isErrorOverlayOpen,
setIsErrorOverlayOpen: setIsErrorOverlayOpen
})
]
});
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# 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":["AppDevOverlay","readSsrError","document","ssrErrorTemplateTag","querySelector","message","getAttribute","stack","digest","error","Error","isNextRouterError","ReplaySsrOnlyErrors","process","env","NODE_ENV","ssrError","useEffect","handleClientError","state","globalError","children","isErrorOverlayOpen","setIsErrorOverlayOpen","useState","AppDevOverlayErrorBoundary","onError","FontStyles","DevOverlay"],"mappings":";;;;+BA4DgBA;;;eAAAA;;;;uBAzDoB;4CACO;4BAChB;4BACA;iCACO;mCACA;AAElC,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,IAAIG,IAAAA,oCAAiB,EAACF,QAAQ;YAC5B,OAAO;QACT;QACAA,MAAMF,KAAK,GAAGA,SAAS;QACvB,OAAOE;IACT;IAEA,OAAO;AACT;AAEA,uDAAuD;AACvD,yDAAyD;AACzD,sFAAsF;AACtF,SAASG;IACP,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,wEAAwE;QACxE,MAAMC,WAAWf;QACjB,sDAAsD;QACtDgB,IAAAA,gBAAS,EAAC;YACR,IAAID,aAAa,MAAM;gBACrB,yCAAyC;gBACzC,wCAAwC;gBACxC,4BAA4B;gBAC5BE,IAAAA,kCAAiB,EAACF,UAAU,EAAE;YAChC;QACF,GAAG;YAACA;SAAS;IACf;IAEA,OAAO;AACT;AAEO,SAAShB,cAAc,KAQ7B;IAR6B,IAAA,EAC5BmB,KAAK,EACLC,WAAW,EACXC,QAAQ,EAKT,GAR6B;IAS5B,MAAM,CAACC,oBAAoBC,sBAAsB,GAAGC,IAAAA,eAAQ,EAAC;IAE7D,qBACE;;0BACE,sBAACC,sDAA0B;gBACzBL,aAAaA;gBACbM,SAASH;;kCAET,qBAACX;oBACAS;;;0BAIH,qBAACM,sBAAU;0BACX,qBAACC,sBAAU;gBACTT,OAAOA;gBACPG,oBAAoBA;gBACpBC,uBAAuBA;;;;AAI/B"}

View File

@@ -0,0 +1,2 @@
import React from 'react';
export declare function createRootLevelDevOverlayElement(reactEl: React.ReactElement): import("react/jsx-runtime").JSX.Element;

View File

@@ -0,0 +1,69 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "createRootLevelDevOverlayElement", {
enumerable: true,
get: function() {
return createRootLevelDevOverlayElement;
}
});
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
const _jsxruntime = require("react/jsx-runtime");
const _react = /*#__PURE__*/ _interop_require_default._(require("react"));
const _appdevoverlay = require("./app-dev-overlay");
const _getsocketurl = require("../utils/get-socket-url");
const _shared = require("../shared");
const _hotreloadertypes = require("../../../../server/dev/hot-reloader-types");
const _errorboundary = /*#__PURE__*/ _interop_require_default._(require("../../error-boundary"));
function createRootLevelDevOverlayElement(reactEl) {
const rootLayoutMissingTags = window.__next_root_layout_missing_tags;
const hasMissingTags = !!(rootLayoutMissingTags == null ? void 0 : rootLayoutMissingTags.length);
const socketUrl = (0, _getsocketurl.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 === _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.SERVER_COMPONENT_CHANGES) {
window.location.reload();
}
};
socket.addEventListener('message', handler);
const FallbackLayout = hasMissingTags ? (param)=>{
let { children } = param;
return /*#__PURE__*/ (0, _jsxruntime.jsx)("html", {
id: "__next_error__",
children: /*#__PURE__*/ (0, _jsxruntime.jsx)("body", {
children: children
})
});
} : _react.default.Fragment;
return /*#__PURE__*/ (0, _jsxruntime.jsx)(FallbackLayout, {
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_appdevoverlay.AppDevOverlay, {
state: {
..._shared.INITIAL_OVERLAY_STATE,
rootLayoutMissingTags,
routerType: 'app'
},
globalError: [
_errorboundary.default,
null
],
children: reactEl
})
});
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# 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":["createRootLevelDevOverlayElement","reactEl","rootLayoutMissingTags","window","__next_root_layout_missing_tags","hasMissingTags","length","socketUrl","getSocketUrl","process","env","__NEXT_ASSET_PREFIX","socket","WebSocket","handler","event","obj","JSON","parse","data","action","HMR_ACTIONS_SENT_TO_BROWSER","SERVER_COMPONENT_CHANGES","location","reload","addEventListener","FallbackLayout","children","html","id","body","React","Fragment","AppDevOverlay","state","INITIAL_OVERLAY_STATE","routerType","globalError","GlobalError"],"mappings":";;;;+BASgBA;;;eAAAA;;;;;gEATE;+BACY;8BACD;wBACS;kCACM;wEACpB;AAIjB,SAASA,iCAAiCC,OAA2B;IAC1E,MAAMC,wBAAwBC,OAAOC,+BAA+B;IACpE,MAAMC,iBAAiB,CAAC,EAACH,yCAAAA,sBAAuBI,MAAM;IACtD,MAAMC,YAAYC,IAAAA,0BAAY,EAACC,QAAQC,GAAG,CAACC,mBAAmB,IAAI;IAClE,MAAMC,SAAS,IAAIT,OAAOU,SAAS,CAAC,AAAC,KAAEN,YAAU;IAEjD,kDAAkD;IAClD,MAAMO,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,KAAKC,6CAA2B,CAACC,wBAAwB,EAAE;YACvEnB,OAAOoB,QAAQ,CAACC,MAAM;QACxB;IACF;IAEAZ,OAAOa,gBAAgB,CAAC,WAAWX;IAEnC,MAAMY,iBAAiBrB,iBACnB;YAAC,EAAEsB,QAAQ,EAAiC;6BAC1C,qBAACC;YAAKC,IAAG;sBACP,cAAA,qBAACC;0BAAMH;;;QAGXI,cAAK,CAACC,QAAQ;IAElB,qBACE,qBAACN;kBACC,cAAA,qBAACO,4BAAa;YACZC,OAAO;gBACL,GAAGC,6BAAqB;gBACxBjC;gBACAkC,YAAY;YACd;YACAC,aAAa;gBAACC,sBAAW;gBAAE;aAAK;sBAE/BrC;;;AAIT"}

View File

@@ -0,0 +1,21 @@
import type { ReactNode } from 'react';
import type { VersionInfo } from '../../../../server/dev/parse-version-info';
import type { DebugInfo } from '../types';
import type { GlobalErrorComponent } from '../../error-boundary';
import type { DevIndicatorServerState } from '../../../../server/dev/dev-indicator-server-state';
export interface Dispatcher {
onBuildOk(): void;
onBuildError(message: string): void;
onVersionInfo(versionInfo: VersionInfo): void;
onDebugInfo(debugInfo: DebugInfo): void;
onBeforeRefresh(): void;
onRefresh(): void;
onStaticIndicator(status: boolean): void;
onDevIndicator(devIndicator: DevIndicatorServerState): void;
}
export declare function waitForWebpackRuntimeHotUpdate(): Promise<void>;
export default function HotReload({ assetPrefix, children, globalError, }: {
assetPrefix: string;
children: ReactNode;
globalError: [GlobalErrorComponent, React.ReactNode];
}): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | import("react").ReactPortal | Iterable<ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null | undefined;

View File

@@ -0,0 +1,584 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
default: null,
waitForWebpackRuntimeHotUpdate: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
default: function() {
return HotReload;
},
waitForWebpackRuntimeHotUpdate: function() {
return waitForWebpackRuntimeHotUpdate;
}
});
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
const _jsxruntime = require("react/jsx-runtime");
const _react = require("react");
const _stripansi = /*#__PURE__*/ _interop_require_default._(require("next/dist/compiled/strip-ansi"));
const _formatwebpackmessages = /*#__PURE__*/ _interop_require_default._(require("../utils/format-webpack-messages"));
const _navigation = require("../../navigation");
const _shared = require("../shared");
const _parsestack = require("../utils/parse-stack");
const _appdevoverlay = require("./app-dev-overlay");
const _useerrorhandler = require("../../errors/use-error-handler");
const _runtimeerrorhandler = require("../../errors/runtime-error-handler");
const _usewebsocket = require("../utils/use-websocket");
const _parsecomponentstack = require("../utils/parse-component-stack");
const _hotreloadertypes = require("../../../../server/dev/hot-reloader-types");
const _extractmodulesfromturbopackmessage = require("../../../../server/dev/extract-modules-from-turbopack-message");
const _navigationuntracked = require("../../navigation-untracked");
const _stitchederror = require("../../errors/stitched-error");
const _iserrorthrownwhilerenderingrsc = require("../../../lib/is-error-thrown-while-rendering-rsc");
const _handledevbuildindicatorhmrevents = require("../../../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();
};
});
}
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.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.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.RuntimeErrorHandler.hadRuntimeError) {
console.warn(_shared.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 = (0, _formatwebpackmessages.default)({
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((0, _stripansi.default)(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 _hotreloadertypes.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 _hotreloadertypes.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 _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.BUILT:
case _hotreloadertypes.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 = (0, _formatwebpackmessages.default)({
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((0, _stripansi.default)(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 === _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.BUILT) {
// Handle hot updates
handleHotUpdate();
}
return;
}
case _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_CONNECTED:
{
processTurbopackMessage({
type: _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_CONNECTED,
data: {
sessionId: obj.data.sessionId
}
});
break;
}
case _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_MESSAGE:
{
dispatcher.onBeforeRefresh();
processTurbopackMessage({
type: _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.TURBOPACK_MESSAGE,
data: obj.data
});
dispatcher.onRefresh();
if (_runtimeerrorhandler.RuntimeErrorHandler.hadRuntimeError) {
console.warn(_shared.REACT_REFRESH_FULL_RELOAD_FROM_ERROR);
performFullReload(null, sendMessage);
}
for (const module1 of (0, _extractmodulesfromturbopackmessage.extractModulesFromTurbopackMessage)(obj.data)){
turbopackUpdatedModules.add(module1);
}
turbopackLastUpdateLatency = Date.now();
break;
}
// TODO-APP: make server component change more granular
case _hotreloadertypes.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.RuntimeErrorHandler.hadRuntimeError) {
if (reloading) return;
reloading = true;
return window.location.reload();
}
(0, _react.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 _hotreloadertypes.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 _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.ADDED_PAGE:
case _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.REMOVED_PAGE:
{
// TODO-APP: potentially only refresh if the currently viewed page was added/removed.
return router.hmrRefresh();
}
case _hotreloadertypes.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 _hotreloadertypes.HMR_ACTIONS_SENT_TO_BROWSER.DEV_PAGES_MANIFEST_UPDATE:
{
return;
}
default:
{}
}
}
function HotReload(param) {
let { assetPrefix, children, globalError } = param;
const [state, dispatch] = (0, _shared.useErrorOverlayReducer)('app');
const dispatcher = (0, _react.useMemo)(()=>{
return {
onBuildOk () {
dispatch({
type: _shared.ACTION_BUILD_OK
});
},
onBuildError (message) {
dispatch({
type: _shared.ACTION_BUILD_ERROR,
message
});
},
onBeforeRefresh () {
dispatch({
type: _shared.ACTION_BEFORE_REFRESH
});
},
onRefresh () {
dispatch({
type: _shared.ACTION_REFRESH
});
},
onVersionInfo (versionInfo) {
dispatch({
type: _shared.ACTION_VERSION_INFO,
versionInfo
});
},
onStaticIndicator (status) {
dispatch({
type: _shared.ACTION_STATIC_INDICATOR,
staticIndicator: status
});
},
onDebugInfo (debugInfo) {
dispatch({
type: _shared.ACTION_DEBUG_INFO,
debugInfo
});
},
onDevIndicator (devIndicator) {
dispatch({
type: _shared.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 = (0, _react.useSyncExternalStore)(()=>()=>{}, ()=>!(0, _iserrorthrownwhilerenderingrsc.shouldRenderRootLevelErrorOverlay)(), ()=>true);
const handleOnUnhandledError = (0, _react.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: _shared.ACTION_UNHANDLED_ERROR,
reason: error,
frames: (0, _parsestack.parseStack)(error.stack || ''),
componentStackFrames: typeof componentStackTrace === 'string' ? (0, _parsecomponentstack.parseComponentStack)(componentStackTrace) : undefined,
warning
});
}, [
dispatch
]);
const handleOnUnhandledRejection = (0, _react.useCallback)((reason)=>{
const stitchedError = (0, _stitchederror.getReactStitchedError)(reason);
dispatch({
type: _shared.ACTION_UNHANDLED_REJECTION,
reason: stitchedError,
frames: (0, _parsestack.parseStack)(stitchedError.stack || '')
});
}, [
dispatch
]);
(0, _useerrorhandler.useErrorHandler)(handleOnUnhandledError, handleOnUnhandledRejection);
const webSocketRef = (0, _usewebsocket.useWebsocket)(assetPrefix);
(0, _usewebsocket.useWebsocketPing)(webSocketRef);
const sendMessage = (0, _usewebsocket.useSendMessage)(webSocketRef);
const processTurbopackMessage = (0, _usewebsocket.useTurbopack)(sendMessage, (err)=>performFullReload(err, sendMessage));
const router = (0, _navigation.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 = (0, _navigationuntracked.useUntrackedPathname)();
const appIsrManifestRef = (0, _react.useRef)({});
const pathnameRef = (0, _react.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
(0, _react.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
]);
}
(0, _react.useEffect)(()=>{
const websocket = webSocketRef.current;
if (!websocket) return;
const handler = (event)=>{
try {
const obj = JSON.parse(event.data);
(0, _handledevbuildindicatorhmrevents.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__*/ (0, _jsxruntime.jsx)(_appdevoverlay.AppDevOverlay, {
state: state,
globalError: globalError,
children: children
});
}
return children;
}
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
Object.defineProperty(exports.default, '__esModule', { value: true });
Object.assign(exports.default, exports);
module.exports = exports.default;
}
//# sourceMappingURL=hot-reloader-client.js.map

File diff suppressed because one or more lines are too long