From ba78b0d4eb98fead2e34397fac377183b088e20b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Fri, 22 Dec 2023 14:19:49 +0900 Subject: [PATCH] Add tests --- .../fixture/next/next-59834/163/input.js | 4250 +++++++++ .../fixture/next/next-59834/388/input.js | 2115 +++++ .../fixture/next/next-59834/917/input.js | 1684 ++++ .../next/next-59834/pages/[post]/input.js | 253 + .../next/next-59834/pages/_app/input.js | 263 + .../next/next-59834/pages/_document/input.js | 39 + .../next/next-59834/pages/_error/input.js | 700 ++ .../dynamic-route-mismatch-manual/input.js | 148 + .../pages/dynamic-route-mismatch/input.js | 148 + .../next/next-59834/pages/first/input.js | 190 + .../next/next-59834/pages/index/input.js | 266 + .../pages/invalid-relative/input.js | 148 + .../next/next-59834/pages/second/input.js | 190 + .../next/next-59834/pages/third/input.js | 148 + .../server/middleware-build-manifest/input.js | 1 + .../input.js | 1 + .../server/next-font-manifest/input.js | 1 + .../chunks/664-0d0022ae4032b943/input.js | 535 ++ .../framework-b5c497ced4b4c57f/input.js | 496 ++ .../chunks/main-3a3784d955d6397c/input.js | 7561 +++++++++++++++++ .../pages/[post]-bd0a8b07b9f163e4/input.js | 40 + .../pages/_app-7d7f1804b56c88ac/input.js | 25 + .../pages/_error-35ebaceb99327551/input.js | 25 + .../input.js | 50 + .../input.js | 50 + .../pages/first-de5a63778db3eddb/input.js | 72 + .../pages/index-5eb6053a0fe6fcd5/input.js | 45 + .../input.js | 50 + .../pages/second-43ccf1981ad5bed7/input.js | 72 + .../pages/third-6185f37c18ca753e/input.js | 50 + .../chunks/webpack-d8d0d5dfdfeffdbf/input.js | 177 + .../_buildManifest/input.js | 1 + .../_ssgManifest/input.js | 1 + .../next/next-59834/webpack-runtime/input.js | 160 + 34 files changed, 19955 insertions(+) create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/163/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/388/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/917/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/pages/[post]/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/pages/_app/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/pages/_document/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/pages/_error/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/pages/dynamic-route-mismatch-manual/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/pages/dynamic-route-mismatch/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/pages/first/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/pages/index/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/pages/invalid-relative/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/pages/second/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/pages/third/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/server/middleware-build-manifest/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/server/middleware-react-loadable-manifest/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/server/next-font-manifest/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/static/chunks/664-0d0022ae4032b943/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/static/chunks/framework-b5c497ced4b4c57f/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/static/chunks/main-3a3784d955d6397c/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/static/chunks/pages/[post]-bd0a8b07b9f163e4/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/static/chunks/pages/_app-7d7f1804b56c88ac/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/static/chunks/pages/_error-35ebaceb99327551/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/static/chunks/pages/dynamic-route-mismatch-295bd901a3a97747/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/static/chunks/pages/dynamic-route-mismatch-manual-0a448df602b06096/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/static/chunks/pages/first-de5a63778db3eddb/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/static/chunks/pages/index-5eb6053a0fe6fcd5/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/static/chunks/pages/invalid-relative-22ea63e3840ab640/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/static/chunks/pages/second-43ccf1981ad5bed7/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/static/chunks/pages/third-6185f37c18ca753e/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/static/chunks/webpack-d8d0d5dfdfeffdbf/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/static/nMQ6aZcQON59MGq0ZfpFL/_buildManifest/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/static/nMQ6aZcQON59MGq0ZfpFL/_ssgManifest/input.js create mode 100644 crates/swc_ecma_minifier/tests/fixture/next/next-59834/webpack-runtime/input.js diff --git a/crates/swc_ecma_minifier/tests/fixture/next/next-59834/163/input.js b/crates/swc_ecma_minifier/tests/fixture/next/next-59834/163/input.js new file mode 100644 index 0000000000000..7878c4a025fdb --- /dev/null +++ b/crates/swc_ecma_minifier/tests/fixture/next/next-59834/163/input.js @@ -0,0 +1,4250 @@ +exports.id = 163; +exports.ids = [163]; +exports.modules = { + +/***/ 4878: +/***/ ((__unused_webpack_module, exports) => { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ + value: true +})); +Object.defineProperty(exports, "getDeploymentIdQueryOrEmptyString", ({ + enumerable: true, + get: function() { + return getDeploymentIdQueryOrEmptyString; + } +})); +function getDeploymentIdQueryOrEmptyString() { + if (false) {} + return ""; +} + +//# sourceMappingURL=deployment-id.js.map + +/***/ }), + +/***/ 580: +/***/ ((module, exports) => { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ + value: true +})); +0 && (0); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); +} +_export(exports, { + RSC_HEADER: function() { + return RSC_HEADER; + }, + ACTION: function() { + return ACTION; + }, + NEXT_ROUTER_STATE_TREE: function() { + return NEXT_ROUTER_STATE_TREE; + }, + NEXT_ROUTER_PREFETCH_HEADER: function() { + return NEXT_ROUTER_PREFETCH_HEADER; + }, + NEXT_URL: function() { + return NEXT_URL; + }, + RSC_CONTENT_TYPE_HEADER: function() { + return RSC_CONTENT_TYPE_HEADER; + }, + RSC_VARY_HEADER: function() { + return RSC_VARY_HEADER; + }, + FLIGHT_PARAMETERS: function() { + return FLIGHT_PARAMETERS; + }, + NEXT_RSC_UNION_QUERY: function() { + return NEXT_RSC_UNION_QUERY; + }, + NEXT_DID_POSTPONE_HEADER: function() { + return NEXT_DID_POSTPONE_HEADER; + } +}); +const RSC_HEADER = "RSC"; +const ACTION = "Next-Action"; +const NEXT_ROUTER_STATE_TREE = "Next-Router-State-Tree"; +const NEXT_ROUTER_PREFETCH_HEADER = "Next-Router-Prefetch"; +const NEXT_URL = "Next-Url"; +const RSC_CONTENT_TYPE_HEADER = "text/x-component"; +const RSC_VARY_HEADER = RSC_HEADER + ", " + NEXT_ROUTER_STATE_TREE + ", " + NEXT_ROUTER_PREFETCH_HEADER + ", " + NEXT_URL; +const FLIGHT_PARAMETERS = [ + [ + RSC_HEADER + ], + [ + NEXT_ROUTER_STATE_TREE + ], + [ + NEXT_ROUTER_PREFETCH_HEADER + ] +]; +const NEXT_RSC_UNION_QUERY = "_rsc"; +const NEXT_DID_POSTPONE_HEADER = "x-nextjs-postponed"; +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-router-headers.js.map + + +/***/ }), + +/***/ 8137: +/***/ ((module, exports) => { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ + value: true +})); +Object.defineProperty(exports, "detectDomainLocale", ({ + enumerable: true, + get: function() { + return detectDomainLocale; + } +})); +const detectDomainLocale = function() { + for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){ + args[_key] = arguments[_key]; + } + if (false) {} +}; +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=detect-domain-locale.js.map + + +/***/ }), + +/***/ 8914: +/***/ ((module, exports) => { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ + value: true +})); +0 && (0); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); +} +_export(exports, { + DOMAttributeNames: function() { + return DOMAttributeNames; + }, + isEqualNode: function() { + return isEqualNode; + }, + default: function() { + return initHeadManager; + } +}); +const DOMAttributeNames = { + acceptCharset: "accept-charset", + className: "class", + htmlFor: "for", + httpEquiv: "http-equiv", + noModule: "noModule" +}; +function reactElementToDOM(param) { + let { type, props } = param; + const el = document.createElement(type); + for(const p in props){ + if (!props.hasOwnProperty(p)) continue; + if (p === "children" || p === "dangerouslySetInnerHTML") continue; + // we don't render undefined props to the DOM + if (props[p] === undefined) continue; + const attr = DOMAttributeNames[p] || p.toLowerCase(); + if (type === "script" && (attr === "async" || attr === "defer" || attr === "noModule")) { + el[attr] = !!props[p]; + } else { + el.setAttribute(attr, props[p]); + } + } + const { children, dangerouslySetInnerHTML } = props; + if (dangerouslySetInnerHTML) { + el.innerHTML = dangerouslySetInnerHTML.__html || ""; + } else if (children) { + el.textContent = typeof children === "string" ? children : Array.isArray(children) ? children.join("") : ""; + } + return el; +} +function isEqualNode(oldTag, newTag) { + if (oldTag instanceof HTMLElement && newTag instanceof HTMLElement) { + const nonce = newTag.getAttribute("nonce"); + // Only strip the nonce if `oldTag` has had it stripped. An element's nonce attribute will not + // be stripped if there is no content security policy response header that includes a nonce. + if (nonce && !oldTag.getAttribute("nonce")) { + const cloneTag = newTag.cloneNode(true); + cloneTag.setAttribute("nonce", ""); + cloneTag.nonce = nonce; + return nonce === oldTag.nonce && oldTag.isEqualNode(cloneTag); + } + } + return oldTag.isEqualNode(newTag); +} +let updateElements; +if (false) {} else { + updateElements = (type, components)=>{ + const headEl = document.getElementsByTagName("head")[0]; + const headCountEl = headEl.querySelector("meta[name=next-head-count]"); + if (false) {} + const headCount = Number(headCountEl.content); + const oldTags = []; + for(let i = 0, j = headCountEl.previousElementSibling; i < headCount; i++, j = (j == null ? void 0 : j.previousElementSibling) || null){ + var _j_tagName; + if ((j == null ? void 0 : (_j_tagName = j.tagName) == null ? void 0 : _j_tagName.toLowerCase()) === type) { + oldTags.push(j); + } + } + const newTags = components.map(reactElementToDOM).filter((newTag)=>{ + for(let k = 0, len = oldTags.length; k < len; k++){ + const oldTag = oldTags[k]; + if (isEqualNode(oldTag, newTag)) { + oldTags.splice(k, 1); + return false; + } + } + return true; + }); + oldTags.forEach((t)=>{ + var _t_parentNode; + return (_t_parentNode = t.parentNode) == null ? void 0 : _t_parentNode.removeChild(t); + }); + newTags.forEach((t)=>headEl.insertBefore(t, headCountEl)); + headCountEl.content = (headCount - oldTags.length + newTags.length).toString(); + }; +} +function initHeadManager() { + return { + mountedInstances: new Set(), + updateHead: (head)=>{ + const tags = {}; + head.forEach((h)=>{ + if (// it won't be inlined. In this case revert to the original behavior + h.type === "link" && h.props["data-optimized-fonts"]) { + if (document.querySelector('style[data-href="' + h.props["data-href"] + '"]')) { + return; + } else { + h.props.href = h.props["data-href"]; + h.props["data-href"] = undefined; + } + } + const components = tags[h.type] || []; + components.push(h); + tags[h.type] = components; + }); + const titleComponent = tags.title ? tags.title[0] : null; + let title = ""; + if (titleComponent) { + const { children } = titleComponent.props; + title = typeof children === "string" ? children : Array.isArray(children) ? children.join("") : ""; + } + if (title !== document.title) document.title = title; + [ + "meta", + "base", + "link", + "style", + "script" + ].forEach((type)=>{ + updateElements(type, tags[type] || []); + }); + } + }; +} +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=head-manager.js.map + + +/***/ }), + +/***/ 9798: +/***/ ((module, exports, __webpack_require__) => { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ + value: true +})); +Object.defineProperty(exports, "removeBasePath", ({ + enumerable: true, + get: function() { + return removeBasePath; + } +})); +const _hasbasepath = __webpack_require__(3400); +const basePath = false || ""; +function removeBasePath(path) { + if (false) {} + // Can't trim the basePath if it has zero length! + if (basePath.length === 0) return path; + path = path.slice(basePath.length); + if (!path.startsWith("/")) path = "/" + path; + return path; +} +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=remove-base-path.js.map + + +/***/ }), + +/***/ 835: +/***/ ((module, exports, __webpack_require__) => { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ + value: true +})); +Object.defineProperty(exports, "removeLocale", ({ + enumerable: true, + get: function() { + return removeLocale; + } +})); +const _parsepath = __webpack_require__(8945); +function removeLocale(path, locale) { + if (false) {} + return path; +} +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=remove-locale.js.map + + +/***/ }), + +/***/ 5541: +/***/ ((module, exports, __webpack_require__) => { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ + value: true +})); +0 && (0); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); +} +_export(exports, { + markAssetError: function() { + return markAssetError; + }, + isAssetError: function() { + return isAssetError; + }, + getClientBuildManifest: function() { + return getClientBuildManifest; + }, + createRouteLoader: function() { + return createRouteLoader; + } +}); +const _interop_require_default = __webpack_require__(167); +const _getassetpathfromroute = /*#__PURE__*/ _interop_require_default._(__webpack_require__(471)); +const _trustedtypes = __webpack_require__(4182); +const _requestidlecallback = __webpack_require__(6231); +const _deploymentid = __webpack_require__(4878); +// 3.8s was arbitrarily chosen as it's what https://web.dev/interactive +// considers as "Good" time-to-interactive. We must assume something went +// wrong beyond this point, and then fall-back to a full page transition to +// show the user something of value. +const MS_MAX_IDLE_DELAY = 3800; +function withFuture(key, map, generator) { + let entry = map.get(key); + if (entry) { + if ("future" in entry) { + return entry.future; + } + return Promise.resolve(entry); + } + let resolver; + const prom = new Promise((resolve)=>{ + resolver = resolve; + }); + map.set(key, entry = { + resolve: resolver, + future: prom + }); + return generator ? generator() // eslint-disable-next-line no-sequences + .then((value)=>(resolver(value), value)).catch((err)=>{ + map.delete(key); + throw err; + }) : prom; +} +const ASSET_LOAD_ERROR = Symbol("ASSET_LOAD_ERROR"); +function markAssetError(err) { + return Object.defineProperty(err, ASSET_LOAD_ERROR, {}); +} +function isAssetError(err) { + return err && ASSET_LOAD_ERROR in err; +} +function hasPrefetch(link) { + try { + link = document.createElement("link"); + return(// with relList.support + !!window.MSInputMethodContext && !!document.documentMode || link.relList.supports("prefetch")); + } catch (e) { + return false; + } +} +const canPrefetch = hasPrefetch(); +const getAssetQueryString = ()=>{ + return (0, _deploymentid.getDeploymentIdQueryOrEmptyString)(); +}; +function prefetchViaDom(href, as, link) { + return new Promise((resolve, reject)=>{ + const selector = '\n link[rel="prefetch"][href^="' + href + '"],\n link[rel="preload"][href^="' + href + '"],\n script[src^="' + href + '"]'; + if (document.querySelector(selector)) { + return resolve(); + } + link = document.createElement("link"); + // The order of property assignment here is intentional: + if (as) link.as = as; + link.rel = "prefetch"; + link.crossOrigin = undefined; + link.onload = resolve; + link.onerror = ()=>reject(markAssetError(new Error("Failed to prefetch: " + href))); + // `href` should always be last: + link.href = href; + document.head.appendChild(link); + }); +} +function appendScript(src, script) { + return new Promise((resolve, reject)=>{ + script = document.createElement("script"); + // The order of property assignment here is intentional. + // 1. Setup success/failure hooks in case the browser synchronously + // executes when `src` is set. + script.onload = resolve; + script.onerror = ()=>reject(markAssetError(new Error("Failed to load script: " + src))); + // 2. Configure the cross-origin attribute before setting `src` in case the + // browser begins to fetch. + script.crossOrigin = undefined; + // 3. Finally, set the source and inject into the DOM in case the child + // must be appended for fetching to start. + script.src = src; + document.body.appendChild(script); + }); +} +// We wait for pages to be built in dev before we start the route transition +// timeout to prevent an un-necessary hard navigation in development. +let devBuildPromise; +// Resolve a promise that times out after given amount of milliseconds. +function resolvePromiseWithTimeout(p, ms, err) { + return new Promise((resolve, reject)=>{ + let cancelled = false; + p.then((r)=>{ + // Resolved, cancel the timeout + cancelled = true; + resolve(r); + }).catch(reject); + // We wrap these checks separately for better dead-code elimination in + // production bundles. + if (false) {} + if (true) { + (0, _requestidlecallback.requestIdleCallback)(()=>setTimeout(()=>{ + if (!cancelled) { + reject(err); + } + }, ms)); + } + }); +} +function getClientBuildManifest() { + if (self.__BUILD_MANIFEST) { + return Promise.resolve(self.__BUILD_MANIFEST); + } + const onBuildManifest = new Promise((resolve)=>{ + // Mandatory because this is not concurrent safe: + const cb = self.__BUILD_MANIFEST_CB; + self.__BUILD_MANIFEST_CB = ()=>{ + resolve(self.__BUILD_MANIFEST); + cb && cb(); + }; + }); + return resolvePromiseWithTimeout(onBuildManifest, MS_MAX_IDLE_DELAY, markAssetError(new Error("Failed to load client build manifest"))); +} +function getFilesForRoute(assetPrefix, route) { + if (false) {} + return getClientBuildManifest().then((manifest)=>{ + if (!(route in manifest)) { + throw markAssetError(new Error("Failed to lookup route: " + route)); + } + const allFiles = manifest[route].map((entry)=>assetPrefix + "/_next/" + encodeURI(entry)); + return { + scripts: allFiles.filter((v)=>v.endsWith(".js")).map((v)=>(0, _trustedtypes.__unsafeCreateTrustedScriptURL)(v) + getAssetQueryString()), + css: allFiles.filter((v)=>v.endsWith(".css")).map((v)=>v + getAssetQueryString()) + }; + }); +} +function createRouteLoader(assetPrefix) { + const entrypoints = new Map(); + const loadedScripts = new Map(); + const styleSheets = new Map(); + const routes = new Map(); + function maybeExecuteScript(src) { + // With HMR we might need to "reload" scripts when they are + // disposed and readded. Executing scripts twice has no functional + // differences + if (true) { + let prom = loadedScripts.get(src.toString()); + if (prom) { + return prom; + } + // Skip executing script if it's already in the DOM: + if (document.querySelector('script[src^="' + src + '"]')) { + return Promise.resolve(); + } + loadedScripts.set(src.toString(), prom = appendScript(src)); + return prom; + } else {} + } + function fetchStyleSheet(href) { + let prom = styleSheets.get(href); + if (prom) { + return prom; + } + styleSheets.set(href, prom = fetch(href).then((res)=>{ + if (!res.ok) { + throw new Error("Failed to load stylesheet: " + href); + } + return res.text().then((text)=>({ + href: href, + content: text + })); + }).catch((err)=>{ + throw markAssetError(err); + })); + return prom; + } + return { + whenEntrypoint (route) { + return withFuture(route, entrypoints); + }, + onEntrypoint (route, execute) { + (execute ? Promise.resolve().then(()=>execute()).then((exports1)=>({ + component: exports1 && exports1.default || exports1, + exports: exports1 + }), (err)=>({ + error: err + })) : Promise.resolve(undefined)).then((input)=>{ + const old = entrypoints.get(route); + if (old && "resolve" in old) { + if (input) { + entrypoints.set(route, input); + old.resolve(input); + } + } else { + if (input) { + entrypoints.set(route, input); + } else { + entrypoints.delete(route); + } + // when this entrypoint has been resolved before + // the route is outdated and we want to invalidate + // this cache entry + routes.delete(route); + } + }); + }, + loadRoute (route, prefetch) { + return withFuture(route, routes, ()=>{ + let devBuildPromiseResolve; + if (false) {} + return resolvePromiseWithTimeout(getFilesForRoute(assetPrefix, route).then((param)=>{ + let { scripts, css } = param; + return Promise.all([ + entrypoints.has(route) ? [] : Promise.all(scripts.map(maybeExecuteScript)), + Promise.all(css.map(fetchStyleSheet)) + ]); + }).then((res)=>{ + return this.whenEntrypoint(route).then((entrypoint)=>({ + entrypoint, + styles: res[1] + })); + }), MS_MAX_IDLE_DELAY, markAssetError(new Error("Route did not complete loading: " + route))).then((param)=>{ + let { entrypoint, styles } = param; + const res = Object.assign({ + styles: styles + }, entrypoint); + return "error" in entrypoint ? entrypoint : res; + }).catch((err)=>{ + if (prefetch) { + // we don't want to cache errors during prefetch + throw err; + } + return { + error: err + }; + }).finally(()=>devBuildPromiseResolve == null ? void 0 : devBuildPromiseResolve()); + }); + }, + prefetch (route) { + // https://github.com/GoogleChromeLabs/quicklink/blob/453a661fa1fa940e2d2e044452398e38c67a98fb/src/index.mjs#L115-L118 + // License: Apache 2.0 + let cn; + if (cn = navigator.connection) { + // Don't prefetch if using 2G or if Save-Data is enabled. + if (cn.saveData || /2g/.test(cn.effectiveType)) return Promise.resolve(); + } + return getFilesForRoute(assetPrefix, route).then((output)=>Promise.all(canPrefetch ? output.scripts.map((script)=>prefetchViaDom(script.toString(), "script")) : [])).then(()=>{ + (0, _requestidlecallback.requestIdleCallback)(()=>this.loadRoute(route, true).catch(()=>{})); + }).catch(()=>{}); + } + }; +} +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=route-loader.js.map + + +/***/ }), + +/***/ 2937: +/***/ ((module, exports, __webpack_require__) => { + +"use strict"; +/* global window */ +Object.defineProperty(exports, "__esModule", ({ + value: true +})); +0 && (0); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); +} +_export(exports, { + Router: function() { + return _router.default; + }, + // Export the singletonRouter and this is the public API. + default: function() { + return _default; + }, + withRouter: function() { + return _withrouter.default; + }, + useRouter: function() { + return useRouter; + }, + createRouter: function() { + return createRouter; + }, + makePublicRouterInstance: function() { + return makePublicRouterInstance; + } +}); +const _interop_require_default = __webpack_require__(167); +const _react = /*#__PURE__*/ _interop_require_default._(__webpack_require__(6689)); +const _router = /*#__PURE__*/ _interop_require_default._(__webpack_require__(1575)); +const _routercontextsharedruntime = __webpack_require__(5469); +const _iserror = /*#__PURE__*/ _interop_require_default._(__webpack_require__(676)); +const _withrouter = /*#__PURE__*/ _interop_require_default._(__webpack_require__(8980)); +const singletonRouter = { + router: null, + readyCallbacks: [], + ready (callback) { + if (this.router) return callback(); + if (false) {} + } +}; +// Create public properties and methods of the router in the singletonRouter +const urlPropertyFields = [ + "pathname", + "route", + "query", + "asPath", + "components", + "isFallback", + "basePath", + "locale", + "locales", + "defaultLocale", + "isReady", + "isPreview", + "isLocaleDomain", + "domainLocales" +]; +const routerEvents = [ + "routeChangeStart", + "beforeHistoryChange", + "routeChangeComplete", + "routeChangeError", + "hashChangeStart", + "hashChangeComplete" +]; +const coreMethodFields = [ + "push", + "replace", + "reload", + "back", + "prefetch", + "beforePopState" +]; +// Events is a static property on the router, the router doesn't have to be initialized to use it +Object.defineProperty(singletonRouter, "events", { + get () { + return _router.default.events; + } +}); +function getRouter() { + if (!singletonRouter.router) { + const message = "No router instance found.\n" + 'You should only use "next/router" on the client side of your app.\n'; + throw new Error(message); + } + return singletonRouter.router; +} +urlPropertyFields.forEach((field)=>{ + // Here we need to use Object.defineProperty because we need to return + // the property assigned to the actual router + // The value might get changed as we change routes and this is the + // proper way to access it + Object.defineProperty(singletonRouter, field, { + get () { + const router = getRouter(); + return router[field]; + } + }); +}); +coreMethodFields.forEach((field)=>{ + singletonRouter[field] = function() { + for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){ + args[_key] = arguments[_key]; + } + const router = getRouter(); + return router[field](...args); + }; +}); +routerEvents.forEach((event)=>{ + singletonRouter.ready(()=>{ + _router.default.events.on(event, function() { + for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){ + args[_key] = arguments[_key]; + } + const eventField = "on" + event.charAt(0).toUpperCase() + event.substring(1); + const _singletonRouter = singletonRouter; + if (_singletonRouter[eventField]) { + try { + _singletonRouter[eventField](...args); + } catch (err) { + console.error("Error when running the Router event: " + eventField); + console.error((0, _iserror.default)(err) ? err.message + "\n" + err.stack : err + ""); + } + } + }); + }); +}); +const _default = singletonRouter; +function useRouter() { + const router = _react.default.useContext(_routercontextsharedruntime.RouterContext); + if (!router) { + throw new Error("NextRouter was not mounted. https://nextjs.org/docs/messages/next-router-not-mounted"); + } + return router; +} +function createRouter() { + for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){ + args[_key] = arguments[_key]; + } + singletonRouter.router = new _router.default(...args); + singletonRouter.readyCallbacks.forEach((cb)=>cb()); + singletonRouter.readyCallbacks = []; + return singletonRouter.router; +} +function makePublicRouterInstance(router) { + const scopedRouter = router; + const instance = {}; + for (const property of urlPropertyFields){ + if (typeof scopedRouter[property] === "object") { + instance[property] = Object.assign(Array.isArray(scopedRouter[property]) ? [] : {}, scopedRouter[property]) // makes sure query is not stateful + ; + continue; + } + instance[property] = scopedRouter[property]; + } + // Events is a static property on the router, the router doesn't have to be initialized to use it + instance.events = _router.default.events; + coreMethodFields.forEach((field)=>{ + instance[field] = function() { + for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){ + args[_key] = arguments[_key]; + } + return scopedRouter[field](...args); + }; + }); + return instance; +} +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=router.js.map + + +/***/ }), + +/***/ 3773: +/***/ ((module, exports, __webpack_require__) => { + +"use strict"; +/* __next_internal_client_entry_do_not_use__ cjs */ +Object.defineProperty(exports, "__esModule", ({ + value: true +})); +0 && (0); +function _export(target, all) { + for(var name in all)Object.defineProperty(target, name, { + enumerable: true, + get: all[name] + }); +} +_export(exports, { + handleClientScriptLoad: function() { + return handleClientScriptLoad; + }, + initScriptLoader: function() { + return initScriptLoader; + }, + default: function() { + return _default; + } +}); +const _interop_require_default = __webpack_require__(167); +const _interop_require_wildcard = __webpack_require__(8760); +const _reactdom = /*#__PURE__*/ _interop_require_default._(__webpack_require__(6405)); +const _react = /*#__PURE__*/ _interop_require_wildcard._(__webpack_require__(6689)); +const _headmanagercontextsharedruntime = __webpack_require__(1988); +const _headmanager = __webpack_require__(8914); +const _requestidlecallback = __webpack_require__(6231); +const ScriptCache = new Map(); +const LoadCache = new Set(); +const ignoreProps = [ + "onLoad", + "onReady", + "dangerouslySetInnerHTML", + "children", + "onError", + "strategy", + "stylesheets" +]; +const insertStylesheets = (stylesheets)=>{ + // Case 1: Styles for afterInteractive/lazyOnload with appDir injected via handleClientScriptLoad + // + // Using ReactDOM.preinit to feature detect appDir and inject styles + // Stylesheets might have already been loaded if initialized with Script component + // Re-inject styles here to handle scripts loaded via handleClientScriptLoad + // ReactDOM.preinit handles dedup and ensures the styles are loaded only once + if (_reactdom.default.preinit) { + stylesheets.forEach((stylesheet)=>{ + _reactdom.default.preinit(stylesheet, { + as: "style" + }); + }); + return; + } + // Case 2: Styles for afterInteractive/lazyOnload with pages injected via handleClientScriptLoad + // + // We use this function to load styles when appdir is not detected + // TODO: Use React float APIs to load styles once available for pages dir + if (false) {} +}; +const loadScript = (props)=>{ + const { src, id, onLoad = ()=>{}, onReady = null, dangerouslySetInnerHTML, children = "", strategy = "afterInteractive", onError, stylesheets } = props; + const cacheKey = id || src; + // Script has already loaded + if (cacheKey && LoadCache.has(cacheKey)) { + return; + } + // Contents of this script are already loading/loaded + if (ScriptCache.has(src)) { + LoadCache.add(cacheKey); + // It is possible that multiple `next/script` components all have same "src", but has different "onLoad" + // This is to make sure the same remote script will only load once, but "onLoad" are executed in order + ScriptCache.get(src).then(onLoad, onError); + return; + } + /** Execute after the script first loaded */ const afterLoad = ()=>{ + // Run onReady for the first time after load event + if (onReady) { + onReady(); + } + // add cacheKey to LoadCache when load successfully + LoadCache.add(cacheKey); + }; + const el = document.createElement("script"); + const loadPromise = new Promise((resolve, reject)=>{ + el.addEventListener("load", function(e) { + resolve(); + if (onLoad) { + onLoad.call(this, e); + } + afterLoad(); + }); + el.addEventListener("error", function(e) { + reject(e); + }); + }).catch(function(e) { + if (onError) { + onError(e); + } + }); + if (dangerouslySetInnerHTML) { + // Casting since lib.dom.d.ts doesn't have TrustedHTML yet. + el.innerHTML = dangerouslySetInnerHTML.__html || ""; + afterLoad(); + } else if (children) { + el.textContent = typeof children === "string" ? children : Array.isArray(children) ? children.join("") : ""; + afterLoad(); + } else if (src) { + el.src = src; + // do not add cacheKey into LoadCache for remote script here + // cacheKey will be added to LoadCache when it is actually loaded (see loadPromise above) + ScriptCache.set(src, loadPromise); + } + for (const [k, value] of Object.entries(props)){ + if (value === undefined || ignoreProps.includes(k)) { + continue; + } + const attr = _headmanager.DOMAttributeNames[k] || k.toLowerCase(); + el.setAttribute(attr, value); + } + if (strategy === "worker") { + el.setAttribute("type", "text/partytown"); + } + el.setAttribute("data-nscript", strategy); + // Load styles associated with this script + if (stylesheets) { + insertStylesheets(stylesheets); + } + document.body.appendChild(el); +}; +function handleClientScriptLoad(props) { + const { strategy = "afterInteractive" } = props; + if (strategy === "lazyOnload") { + window.addEventListener("load", ()=>{ + (0, _requestidlecallback.requestIdleCallback)(()=>loadScript(props)); + }); + } else { + loadScript(props); + } +} +function loadLazyScript(props) { + if (document.readyState === "complete") { + (0, _requestidlecallback.requestIdleCallback)(()=>loadScript(props)); + } else { + window.addEventListener("load", ()=>{ + (0, _requestidlecallback.requestIdleCallback)(()=>loadScript(props)); + }); + } +} +function addBeforeInteractiveToCache() { + const scripts = [ + ...document.querySelectorAll('[data-nscript="beforeInteractive"]'), + ...document.querySelectorAll('[data-nscript="beforePageRender"]') + ]; + scripts.forEach((script)=>{ + const cacheKey = script.id || script.getAttribute("src"); + LoadCache.add(cacheKey); + }); +} +function initScriptLoader(scriptLoaderItems) { + scriptLoaderItems.forEach(handleClientScriptLoad); + addBeforeInteractiveToCache(); +} +function Script(props) { + const { id, src = "", onLoad = ()=>{}, onReady = null, strategy = "afterInteractive", onError, stylesheets, ...restProps } = props; + // Context is available only during SSR + const { updateScripts, scripts, getIsSsr, appDir, nonce } = (0, _react.useContext)(_headmanagercontextsharedruntime.HeadManagerContext); + /** + * - First mount: + * 1. The useEffect for onReady executes + * 2. hasOnReadyEffectCalled.current is false, but the script hasn't loaded yet (not in LoadCache) + * onReady is skipped, set hasOnReadyEffectCalled.current to true + * 3. The useEffect for loadScript executes + * 4. hasLoadScriptEffectCalled.current is false, loadScript executes + * Once the script is loaded, the onLoad and onReady will be called by then + * [If strict mode is enabled / is wrapped in component] + * 5. The useEffect for onReady executes again + * 6. hasOnReadyEffectCalled.current is true, so entire effect is skipped + * 7. The useEffect for loadScript executes again + * 8. hasLoadScriptEffectCalled.current is true, so entire effect is skipped + * + * - Second mount: + * 1. The useEffect for onReady executes + * 2. hasOnReadyEffectCalled.current is false, but the script has already loaded (found in LoadCache) + * onReady is called, set hasOnReadyEffectCalled.current to true + * 3. The useEffect for loadScript executes + * 4. The script is already loaded, loadScript bails out + * [If strict mode is enabled / is wrapped in component] + * 5. The useEffect for onReady executes again + * 6. hasOnReadyEffectCalled.current is true, so entire effect is skipped + * 7. The useEffect for loadScript executes again + * 8. hasLoadScriptEffectCalled.current is true, so entire effect is skipped + */ const hasOnReadyEffectCalled = (0, _react.useRef)(false); + (0, _react.useEffect)(()=>{ + const cacheKey = id || src; + if (!hasOnReadyEffectCalled.current) { + // Run onReady if script has loaded before but component is re-mounted + if (onReady && cacheKey && LoadCache.has(cacheKey)) { + onReady(); + } + hasOnReadyEffectCalled.current = true; + } + }, [ + onReady, + id, + src + ]); + const hasLoadScriptEffectCalled = (0, _react.useRef)(false); + (0, _react.useEffect)(()=>{ + if (!hasLoadScriptEffectCalled.current) { + if (strategy === "afterInteractive") { + loadScript(props); + } else if (strategy === "lazyOnload") { + loadLazyScript(props); + } + hasLoadScriptEffectCalled.current = true; + } + }, [ + props, + strategy + ]); + if (strategy === "beforeInteractive" || strategy === "worker") { + if (updateScripts) { + scripts[strategy] = (scripts[strategy] || []).concat([ + { + id, + src, + onLoad, + onReady, + onError, + ...restProps + } + ]); + updateScripts(scripts); + } else if (getIsSsr && getIsSsr()) { + // Script has already loaded during SSR + LoadCache.add(id || src); + } else if (getIsSsr && !getIsSsr()) { + loadScript(props); + } + } + // For the app directory, we need React Float to preload these scripts. + if (appDir) { + // Injecting stylesheets here handles beforeInteractive and worker scripts correctly + // For other strategies injecting here ensures correct stylesheet order + // ReactDOM.preinit handles loading the styles in the correct order, + // also ensures the stylesheet is loaded only once and in a consistent manner + // + // Case 1: Styles for beforeInteractive/worker with appDir - handled here + // Case 2: Styles for beforeInteractive/worker with pages dir - Not handled yet + // Case 3: Styles for afterInteractive/lazyOnload with appDir - handled here + // Case 4: Styles for afterInteractive/lazyOnload with pages dir - handled in insertStylesheets function + if (stylesheets) { + stylesheets.forEach((styleSrc)=>{ + _reactdom.default.preinit(styleSrc, { + as: "style" + }); + }); + } + // Before interactive scripts need to be loaded by Next.js' runtime instead + // of native