@scrabble-solver/scrabble-solver 2.10.1 → 2.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/build-manifest.json +26 -26
  3. package/.next/cache/.tsbuildinfo +1 -1
  4. package/.next/cache/eslint/.cache_8dgz12 +1 -1
  5. package/.next/cache/next-server.js.nft.json +1 -1
  6. package/.next/cache/webpack/client-development/7.pack_ +0 -0
  7. package/.next/cache/webpack/client-production/0.pack +0 -0
  8. package/.next/cache/webpack/client-production/index.pack +0 -0
  9. package/.next/cache/webpack/edge-server-production/0.pack +0 -0
  10. package/.next/cache/webpack/edge-server-production/index.pack +0 -0
  11. package/.next/cache/webpack/server-production/0.pack +0 -0
  12. package/.next/cache/webpack/server-production/index.pack +0 -0
  13. package/.next/images-manifest.json +1 -1
  14. package/.next/next-server.js.nft.json +1 -1
  15. package/.next/prerender-manifest.json +1 -1
  16. package/.next/required-server-files.json +1 -1
  17. package/.next/routes-manifest.json +1 -1
  18. package/.next/server/chunks/131.js +1399 -117
  19. package/.next/server/chunks/{515.js → 176.js} +771 -679
  20. package/.next/server/chunks/210.js +122 -0
  21. package/.next/server/chunks/{939.js → 290.js} +3 -3
  22. package/.next/server/chunks/44.js +33 -33
  23. package/.next/server/chunks/50.js +5 -9
  24. package/.next/server/chunks/{413.js → 579.js} +136 -87
  25. package/.next/server/chunks/664.js +537 -350
  26. package/.next/server/chunks/859.js +56 -23
  27. package/.next/server/chunks/865.js +1 -1
  28. package/.next/server/middleware-build-manifest.js +1 -1
  29. package/.next/server/pages/404.html +2 -2
  30. package/.next/server/pages/404.js.nft.json +1 -1
  31. package/.next/server/pages/500.html +2 -2
  32. package/.next/server/pages/_app.js +23 -5
  33. package/.next/server/pages/_app.js.nft.json +1 -1
  34. package/.next/server/pages/_document.js +2 -2
  35. package/.next/server/pages/_error.js +206 -25
  36. package/.next/server/pages/_error.js.nft.json +1 -1
  37. package/.next/server/pages/api/dictionary/[locale]/[word].js +12 -11
  38. package/.next/server/pages/api/dictionary/[locale]/[word].js.nft.json +1 -1
  39. package/.next/server/pages/api/dictionary/[locale].js +10 -10
  40. package/.next/server/pages/api/dictionary/[locale].js.nft.json +1 -1
  41. package/.next/server/pages/api/solve.js +14 -13
  42. package/.next/server/pages/api/solve.js.nft.json +1 -1
  43. package/.next/server/pages/api/verify.js +10 -10
  44. package/.next/server/pages/api/verify.js.nft.json +1 -1
  45. package/.next/server/pages/api/visit.js +3 -3
  46. package/.next/server/pages/api/visit.js.nft.json +1 -1
  47. package/.next/server/pages/index.html +2 -2
  48. package/.next/server/pages/index.js +44 -128
  49. package/.next/server/pages/index.js.nft.json +1 -1
  50. package/.next/server/pages/index.json +1 -1
  51. package/.next/server/pages-manifest.json +4 -4
  52. package/.next/static/FJkPF91uL-OCAJKTTpVSP/_buildManifest.js +1 -0
  53. package/.next/static/{hf94cues-LcXZRCpAzQ6w → FJkPF91uL-OCAJKTTpVSP}/_ssgManifest.js +0 -0
  54. package/.next/static/chunks/361-d16f336a9752a55a.js +1 -0
  55. package/.next/static/chunks/724-eb48df4d1ba3df8b.js +5 -0
  56. package/.next/static/chunks/framework-2c79e2a64abdb08b.js +33 -0
  57. package/.next/static/chunks/main-f11614d8aa7ee555.js +1 -0
  58. package/.next/static/chunks/pages/404-24f9617eeb8d6dc1.js +1 -0
  59. package/.next/static/chunks/pages/_app-959e495f0f221247.js +24 -0
  60. package/.next/static/chunks/pages/_error-8353112a01355ec2.js +1 -0
  61. package/.next/static/chunks/pages/index-1e30dafa41bddb80.js +1 -0
  62. package/.next/static/chunks/webpack-59c5c889f52620d6.js +1 -0
  63. package/.next/static/css/aafd07997120f1e4.css +1 -0
  64. package/.next/static/css/cb5b206454513f3c.css +1 -0
  65. package/.next/static/css/eb9d57f7103525ab.css +1 -0
  66. package/.next/trace +52 -52
  67. package/package.json +21 -21
  68. package/public/og.png +0 -0
  69. package/src/components/Board/Board.module.scss +1 -2
  70. package/src/components/Board/BoardPure.tsx +2 -0
  71. package/src/components/Board/components/Cell/Cell.module.scss +77 -54
  72. package/src/components/Board/components/Cell/Cell.tsx +9 -0
  73. package/src/components/Board/components/Cell/CellPure.tsx +11 -2
  74. package/src/components/NavButtons/NavButtons.tsx +11 -1
  75. package/src/components/Rack/RackTile.tsx +10 -1
  76. package/src/components/RemainingTiles/Character.module.scss +0 -1
  77. package/src/components/RemainingTiles/Character.tsx +1 -0
  78. package/src/components/Solver/Solver.module.scss +85 -0
  79. package/src/components/Solver/Solver.tsx +75 -0
  80. package/src/components/Solver/index.ts +1 -0
  81. package/src/components/Tile/Tile.module.scss +51 -7
  82. package/src/components/Tile/Tile.tsx +3 -0
  83. package/src/components/Tile/TilePure.tsx +8 -1
  84. package/src/components/index.ts +1 -0
  85. package/src/hooks/index.ts +1 -0
  86. package/src/hooks/useIsTouchDevice.ts +7 -0
  87. package/src/icons/ExclamationSquareFill.svg +4 -0
  88. package/src/icons/index.ts +1 -0
  89. package/src/pages/api/dictionary/[locale]/[word].ts +2 -1
  90. package/src/pages/index.module.scss +1 -75
  91. package/src/pages/index.tsx +11 -73
  92. package/src/parameters/index.ts +2 -0
  93. package/src/service-worker/average.ts +9 -0
  94. package/src/service-worker/routeSolveRequests.ts +46 -7
  95. package/src/state/selectors.ts +20 -0
  96. package/src/state/slices/boardInitialState.ts +27 -0
  97. package/src/styles/mixins.scss +6 -1
  98. package/src/styles/variables.scss +6 -3
  99. package/.next/InjectManifest.js.nft.json +0 -1
  100. package/.next/static/chunks/368-8b386c3106556f62.js +0 -1
  101. package/.next/static/chunks/546-447e243fc9de2c59.js +0 -1
  102. package/.next/static/chunks/framework-4556c45dd113b893.js +0 -1
  103. package/.next/static/chunks/main-a75cf611e061d8f8.js +0 -1
  104. package/.next/static/chunks/pages/404-932294135c3206dd.js +0 -1
  105. package/.next/static/chunks/pages/_app-8f0df20f771045ed.js +0 -1
  106. package/.next/static/chunks/pages/_error-a4ba2246ff8fb532.js +0 -1
  107. package/.next/static/chunks/pages/index-8af7a9d7a2cd98a7.js +0 -1
  108. package/.next/static/chunks/webpack-5752944655d749a0.js +0 -1
  109. package/.next/static/css/6b1833fd19d3a74a.css +0 -1
  110. package/.next/static/css/a6154e4ca046ca13.css +0 -1
  111. package/.next/static/css/bad53af6f8616677.css +0 -1
  112. package/.next/static/hf94cues-LcXZRCpAzQ6w/_buildManifest.js +0 -1
@@ -11,22 +11,12 @@ var __webpack_unused_export__;
11
11
  __webpack_unused_export__ = ({
12
12
  value: true
13
13
  });
14
- exports.Z = _asyncToGenerator;
15
- function _asyncToGenerator(fn) {
16
- return function() {
17
- var self = this, args = arguments;
18
- return new Promise(function(resolve, reject) {
19
- var gen = fn.apply(self, args);
20
- function _next(value) {
21
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
- }
23
- function _throw(err) {
24
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
- }
26
- _next(undefined);
27
- });
28
- };
29
- }
14
+ Object.defineProperty(exports, "Z", ({
15
+ enumerable: true,
16
+ get: function() {
17
+ return _asyncToGenerator;
18
+ }
19
+ }));
30
20
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
31
21
  try {
32
22
  var info = gen[key](arg);
@@ -41,108 +31,20 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
41
31
  Promise.resolve(value).then(_next, _throw);
42
32
  }
43
33
  }
44
-
45
-
46
- /***/ }),
47
-
48
- /***/ 6495:
49
- /***/ ((__unused_webpack_module, exports) => {
50
-
51
- "use strict";
52
- var __webpack_unused_export__;
53
-
54
- __webpack_unused_export__ = ({
55
- value: true
56
- });
57
- exports.Z = _extends;
58
- function _extends() {
59
- return extends_.apply(this, arguments);
60
- }
61
- function extends_() {
62
- extends_ = Object.assign || function(target) {
63
- for(var i = 1; i < arguments.length; i++){
64
- var source = arguments[i];
65
- for(var key in source){
66
- if (Object.prototype.hasOwnProperty.call(source, key)) {
67
- target[key] = source[key];
68
- }
34
+ function _asyncToGenerator(fn) {
35
+ return function() {
36
+ var self = this, args = arguments;
37
+ return new Promise(function(resolve, reject) {
38
+ var gen = fn.apply(self, args);
39
+ function _next(value) {
40
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
69
41
  }
70
- }
71
- return target;
72
- };
73
- return extends_.apply(this, arguments);
74
- }
75
-
76
-
77
- /***/ }),
78
-
79
- /***/ 92648:
80
- /***/ ((__unused_webpack_module, exports) => {
81
-
82
- "use strict";
83
- var __webpack_unused_export__;
84
-
85
- __webpack_unused_export__ = ({
86
- value: true
87
- });
88
- exports.Z = _interopRequireDefault;
89
- function _interopRequireDefault(obj) {
90
- return obj && obj.__esModule ? obj : {
91
- default: obj
92
- };
93
- }
94
-
95
-
96
- /***/ }),
97
-
98
- /***/ 91598:
99
- /***/ ((__unused_webpack_module, exports) => {
100
-
101
- "use strict";
102
- var __webpack_unused_export__;
103
-
104
- __webpack_unused_export__ = ({
105
- value: true
106
- });
107
- exports.Z = _interopRequireWildcard;
108
- function _interopRequireWildcard(obj, nodeInterop) {
109
- if (!nodeInterop && obj && obj.__esModule) {
110
- return obj;
111
- }
112
- if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
113
- return {
114
- default: obj
115
- };
116
- }
117
- var cache = _getRequireWildcardCache(nodeInterop);
118
- if (cache && cache.has(obj)) {
119
- return cache.get(obj);
120
- }
121
- var newObj = {};
122
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
123
- for(var key in obj){
124
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
125
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
126
- if (desc && (desc.get || desc.set)) {
127
- Object.defineProperty(newObj, key, desc);
128
- } else {
129
- newObj[key] = obj[key];
42
+ function _throw(err) {
43
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
130
44
  }
131
- }
132
- }
133
- newObj.default = obj;
134
- if (cache) {
135
- cache.set(obj, newObj);
136
- }
137
- return newObj;
138
- }
139
- function _getRequireWildcardCache(nodeInterop1) {
140
- if (typeof WeakMap !== "function") return null;
141
- var cacheBabelInterop = new WeakMap();
142
- var cacheNodeInterop = new WeakMap();
143
- return (_getRequireWildcardCache = function(nodeInterop) {
144
- return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
145
- })(nodeInterop1);
45
+ _next(undefined);
46
+ });
47
+ };
146
48
  }
147
49
 
148
50
 
@@ -157,7 +59,12 @@ var __webpack_unused_export__;
157
59
  __webpack_unused_export__ = ({
158
60
  value: true
159
61
  });
160
- exports.Z = _objectWithoutPropertiesLoose;
62
+ Object.defineProperty(exports, "Z", ({
63
+ enumerable: true,
64
+ get: function() {
65
+ return _objectWithoutPropertiesLoose;
66
+ }
67
+ }));
161
68
  function _objectWithoutPropertiesLoose(source, excluded) {
162
69
  if (source == null) return {};
163
70
  var target = {};
@@ -174,7 +81,7 @@ function _objectWithoutPropertiesLoose(source, excluded) {
174
81
 
175
82
  /***/ }),
176
83
 
177
- /***/ 98684:
84
+ /***/ 33468:
178
85
  /***/ ((module, exports, __webpack_require__) => {
179
86
 
180
87
  "use strict";
@@ -184,7 +91,7 @@ Object.defineProperty(exports, "__esModule", ({
184
91
  }));
185
92
  exports.addBasePath = addBasePath;
186
93
  var _addPathPrefix = __webpack_require__(11751);
187
- var _normalizeTrailingSlash = __webpack_require__(82392);
94
+ var _normalizeTrailingSlash = __webpack_require__(52700);
188
95
  const basePath = false || "";
189
96
  function addBasePath(path, required) {
190
97
  if (false) {}
@@ -201,7 +108,7 @@ if ((typeof exports.default === "function" || typeof exports.default === "object
201
108
 
202
109
  /***/ }),
203
110
 
204
- /***/ 22725:
111
+ /***/ 54465:
205
112
  /***/ ((module, exports, __webpack_require__) => {
206
113
 
207
114
  "use strict";
@@ -210,7 +117,7 @@ Object.defineProperty(exports, "__esModule", ({
210
117
  value: true
211
118
  }));
212
119
  exports.addLocale = void 0;
213
- var _normalizeTrailingSlash = __webpack_require__(82392);
120
+ var _normalizeTrailingSlash = __webpack_require__(52700);
214
121
  const addLocale = (path, ...args)=>{
215
122
  if (false) {}
216
123
  return path;
@@ -227,7 +134,7 @@ if ((typeof exports.default === "function" || typeof exports.default === "object
227
134
 
228
135
  /***/ }),
229
136
 
230
- /***/ 38748:
137
+ /***/ 84643:
231
138
  /***/ ((module, exports) => {
232
139
 
233
140
  "use strict";
@@ -251,7 +158,7 @@ if ((typeof exports.default === "function" || typeof exports.default === "object
251
158
 
252
159
  /***/ }),
253
160
 
254
- /***/ 71210:
161
+ /***/ 10227:
255
162
  /***/ ((module, exports) => {
256
163
 
257
164
  "use strict";
@@ -277,7 +184,7 @@ if ((typeof exports.default === "function" || typeof exports.default === "object
277
184
 
278
185
  /***/ }),
279
186
 
280
- /***/ 94119:
187
+ /***/ 10928:
281
188
  /***/ ((module, exports, __webpack_require__) => {
282
189
 
283
190
  "use strict";
@@ -302,7 +209,7 @@ if ((typeof exports.default === "function" || typeof exports.default === "object
302
209
 
303
210
  /***/ }),
304
211
 
305
- /***/ 56007:
212
+ /***/ 31831:
306
213
  /***/ ((module, exports) => {
307
214
 
308
215
  "use strict";
@@ -435,12 +342,12 @@ if ((typeof exports.default === "function" || typeof exports.default === "object
435
342
 
436
343
  /***/ }),
437
344
 
438
- /***/ 48418:
345
+ /***/ 31551:
439
346
  /***/ ((module, exports, __webpack_require__) => {
440
347
 
441
348
  "use strict";
442
349
 
443
- "client";
350
+ "use client";
444
351
  Object.defineProperty(exports, "__esModule", ({
445
352
  value: true
446
353
  }));
@@ -448,18 +355,34 @@ exports["default"] = void 0;
448
355
  var _interop_require_default = (__webpack_require__(92648)/* ["default"] */ .Z);
449
356
  var _object_without_properties_loose = (__webpack_require__(17273)/* ["default"] */ .Z);
450
357
  var _react = _interop_require_default(__webpack_require__(16689));
451
- var _router = __webpack_require__(76273);
452
- var _addLocale = __webpack_require__(22725);
358
+ var _router = __webpack_require__(41003);
359
+ var _formatUrl = __webpack_require__(23938);
360
+ var _addLocale = __webpack_require__(54465);
453
361
  var _routerContext = __webpack_require__(24964);
454
362
  var _appRouterContext = __webpack_require__(3280);
455
- var _useIntersection = __webpack_require__(57190);
456
- var _getDomainLocale = __webpack_require__(71210);
457
- var _addBasePath = __webpack_require__(98684);
458
- "client";
459
- const prefetched = {};
363
+ var _useIntersection = __webpack_require__(69246);
364
+ var _getDomainLocale = __webpack_require__(10227);
365
+ var _addBasePath = __webpack_require__(33468);
366
+ const prefetched = new Set();
460
367
  function prefetch(router, href, as, options) {
461
- if (true) return;
462
- if (!(0, _router).isLocalURL(href)) return;
368
+ if (true) {
369
+ return;
370
+ }
371
+ if (!(0, _router).isLocalURL(href)) {
372
+ return;
373
+ }
374
+ // We should only dedupe requests when experimental.optimisticClientCache is
375
+ // disabled.
376
+ if (!options.bypassPrefetchedCheck) {
377
+ const locale = typeof options.locale !== "undefined" ? options.locale : "locale" in router ? router.locale : undefined;
378
+ const prefetchedKey = href + "%" + as + "%" + locale;
379
+ // If we've already fetched the key, then don't prefetch it again!
380
+ if (prefetched.has(prefetchedKey)) {
381
+ return;
382
+ }
383
+ // Mark this URL as prefetched.
384
+ prefetched.add(prefetchedKey);
385
+ }
463
386
  // Prefetch the JSON page if asked (only in the client)
464
387
  // We need to handle a prefetch error here since we may be
465
388
  // loading with priority which can reject but we don't
@@ -467,9 +390,6 @@ function prefetch(router, href, as, options) {
467
390
  Promise.resolve(router.prefetch(href, as, options)).catch((err)=>{
468
391
  if (false) {}
469
392
  });
470
- const curLocale = options && typeof options.locale !== "undefined" ? options.locale : router && router.locale;
471
- // Join on an invalid URI character
472
- prefetched[href + "%" + as + (curLocale ? "%" + curLocale : "")] = true;
473
393
  }
474
394
  function isModifiedEvent(event) {
475
395
  const { target } = event.currentTarget;
@@ -493,9 +413,7 @@ function linkClicked(e, router, href, as, replace, shallow, scroll, locale, isAp
493
413
  scroll
494
414
  });
495
415
  } else {
496
- // If `beforePopState` doesn't exist on the router it's the AppRouter.
497
- const method = replace ? "replace" : "push";
498
- router[method](href, {
416
+ router[replace ? "replace" : "push"](as || href, {
499
417
  forceOptimisticNavigation: !prefetchEnabled
500
418
  });
501
419
  }
@@ -507,10 +425,18 @@ function linkClicked(e, router, href, as, replace, shallow, scroll, locale, isAp
507
425
  navigate();
508
426
  }
509
427
  }
510
- const Link = /*#__PURE__*/ _react.default.forwardRef(function LinkComponent(props, forwardedRef) {
428
+ function formatStringOrUrl(urlObjOrString) {
429
+ if (typeof urlObjOrString === "string") {
430
+ return urlObjOrString;
431
+ }
432
+ return (0, _formatUrl).formatUrl(urlObjOrString);
433
+ }
434
+ /**
435
+ * React Component that enables client-side transitions between routes.
436
+ */ const Link = /*#__PURE__*/ _react.default.forwardRef(function LinkComponent(props, forwardedRef) {
511
437
  if (false) {}
512
438
  let children;
513
- const { href: hrefProp , as: asProp , children: childrenProp , prefetch: prefetchProp , passHref , replace , shallow , scroll , locale , onClick , onMouseEnter , onTouchStart , legacyBehavior =Boolean(false) !== true } = props, restProps = _object_without_properties_loose(props, [
439
+ const { href: hrefProp , as: asProp , children: childrenProp , prefetch: prefetchProp , passHref , replace , shallow , scroll , locale , onClick , onMouseEnter: onMouseEnterProp , onTouchStart: onTouchStartProp , legacyBehavior =true === false } = props, restProps = _object_without_properties_loose(props, [
514
440
  "href",
515
441
  "as",
516
442
  "children",
@@ -529,21 +455,28 @@ const Link = /*#__PURE__*/ _react.default.forwardRef(function LinkComponent(prop
529
455
  if (legacyBehavior && (typeof children === "string" || typeof children === "number")) {
530
456
  children = /*#__PURE__*/ _react.default.createElement("a", null, children);
531
457
  }
532
- const p = prefetchProp !== false;
533
- let router = _react.default.useContext(_routerContext.RouterContext);
534
- // TODO-APP: type error. Remove `as any`
458
+ const prefetchEnabled = prefetchProp !== false;
459
+ const pagesRouter = _react.default.useContext(_routerContext.RouterContext);
535
460
  const appRouter = _react.default.useContext(_appRouterContext.AppRouterContext);
536
- if (appRouter) {
537
- router = appRouter;
538
- }
461
+ const router = pagesRouter != null ? pagesRouter : appRouter;
462
+ // We're in the app directory if there is no pages router.
463
+ const isAppRouter = !pagesRouter;
464
+ if (false) {}
539
465
  const { href , as } = _react.default.useMemo(()=>{
540
- const [resolvedHref, resolvedAs] = (0, _router).resolveHref(router, hrefProp, true);
466
+ if (!pagesRouter) {
467
+ const resolvedHref = formatStringOrUrl(hrefProp);
468
+ return {
469
+ href: resolvedHref,
470
+ as: asProp ? formatStringOrUrl(asProp) : resolvedHref
471
+ };
472
+ }
473
+ const [resolvedHref, resolvedAs] = (0, _router).resolveHref(pagesRouter, hrefProp, true);
541
474
  return {
542
475
  href: resolvedHref,
543
- as: asProp ? (0, _router).resolveHref(router, asProp) : resolvedAs || resolvedHref
476
+ as: asProp ? (0, _router).resolveHref(pagesRouter, asProp) : resolvedAs || resolvedHref
544
477
  };
545
478
  }, [
546
- router,
479
+ pagesRouter,
547
480
  hrefProp,
548
481
  asProp
549
482
  ]);
@@ -555,6 +488,8 @@ const Link = /*#__PURE__*/ _react.default.forwardRef(function LinkComponent(prop
555
488
  if (false) {} else {
556
489
  child = _react.default.Children.only(children);
557
490
  }
491
+ } else {
492
+ if (false) { var ref; }
558
493
  }
559
494
  const childRef = legacyBehavior ? child && typeof child === "object" && child.ref : forwardedRef;
560
495
  const [setIntersectionRef, isVisible, resetVisible] = (0, _useIntersection).useIntersection({
@@ -581,26 +516,33 @@ const Link = /*#__PURE__*/ _react.default.forwardRef(function LinkComponent(prop
581
516
  resetVisible,
582
517
  setIntersectionRef
583
518
  ]);
519
+ // Prefetch the URL if we haven't already and it's visible.
584
520
  _react.default.useEffect(()=>{
585
- const shouldPrefetch = isVisible && p && (0, _router).isLocalURL(href);
586
- const curLocale = typeof locale !== "undefined" ? locale : router && router.locale;
587
- const isPrefetched = prefetched[href + "%" + as + (curLocale ? "%" + curLocale : "")];
588
- if (shouldPrefetch && !isPrefetched) {
589
- prefetch(router, href, as, {
590
- locale: curLocale
591
- });
521
+ // in dev, we only prefetch on hover to avoid wasting resources as the prefetch will trigger compiling the page.
522
+ if (false) {}
523
+ if (!router) {
524
+ return;
592
525
  }
526
+ // If we don't need to prefetch the URL, don't do prefetch.
527
+ if (!isVisible || !prefetchEnabled) {
528
+ return;
529
+ }
530
+ // Prefetch the URL.
531
+ prefetch(router, href, as, {
532
+ locale
533
+ });
593
534
  }, [
594
535
  as,
595
536
  href,
596
537
  isVisible,
597
538
  locale,
598
- p,
539
+ prefetchEnabled,
540
+ pagesRouter == null ? void 0 : pagesRouter.locale,
599
541
  router
600
542
  ]);
601
543
  const childProps = {
602
544
  ref: setRef,
603
- onClick: (e)=>{
545
+ onClick (e) {
604
546
  if (false) {}
605
547
  if (!legacyBehavior && typeof onClick === "function") {
606
548
  onClick(e);
@@ -608,51 +550,63 @@ const Link = /*#__PURE__*/ _react.default.forwardRef(function LinkComponent(prop
608
550
  if (legacyBehavior && child.props && typeof child.props.onClick === "function") {
609
551
  child.props.onClick(e);
610
552
  }
611
- if (!e.defaultPrevented) {
612
- linkClicked(e, router, href, as, replace, shallow, scroll, locale, Boolean(appRouter), p);
553
+ if (!router) {
554
+ return;
555
+ }
556
+ if (e.defaultPrevented) {
557
+ return;
613
558
  }
559
+ linkClicked(e, router, href, as, replace, shallow, scroll, locale, isAppRouter, prefetchEnabled);
614
560
  },
615
- onMouseEnter: (e)=>{
616
- if (!legacyBehavior && typeof onMouseEnter === "function") {
617
- onMouseEnter(e);
561
+ onMouseEnter (e) {
562
+ if (!legacyBehavior && typeof onMouseEnterProp === "function") {
563
+ onMouseEnterProp(e);
618
564
  }
619
565
  if (legacyBehavior && child.props && typeof child.props.onMouseEnter === "function") {
620
566
  child.props.onMouseEnter(e);
621
567
  }
622
- // Check for not prefetch disabled in page using appRouter
623
- if (!(!p && appRouter)) {
624
- if ((0, _router).isLocalURL(href)) {
625
- prefetch(router, href, as, {
626
- priority: true
627
- });
628
- }
568
+ if (!router) {
569
+ return;
570
+ }
571
+ if (!prefetchEnabled && isAppRouter) {
572
+ return;
629
573
  }
574
+ prefetch(router, href, as, {
575
+ locale,
576
+ priority: true,
577
+ // @see {https://github.com/vercel/next.js/discussions/40268?sort=top#discussioncomment-3572642}
578
+ bypassPrefetchedCheck: true
579
+ });
630
580
  },
631
- onTouchStart: (e)=>{
632
- if (!legacyBehavior && typeof onTouchStart === "function") {
633
- onTouchStart(e);
581
+ onTouchStart (e) {
582
+ if (!legacyBehavior && typeof onTouchStartProp === "function") {
583
+ onTouchStartProp(e);
634
584
  }
635
585
  if (legacyBehavior && child.props && typeof child.props.onTouchStart === "function") {
636
586
  child.props.onTouchStart(e);
637
587
  }
638
- // Check for not prefetch disabled in page using appRouter
639
- if (!(!p && appRouter)) {
640
- if ((0, _router).isLocalURL(href)) {
641
- prefetch(router, href, as, {
642
- priority: true
643
- });
644
- }
588
+ if (!router) {
589
+ return;
590
+ }
591
+ if (!prefetchEnabled && isAppRouter) {
592
+ return;
645
593
  }
594
+ prefetch(router, href, as, {
595
+ locale,
596
+ priority: true,
597
+ // @see {https://github.com/vercel/next.js/discussions/40268?sort=top#discussioncomment-3572642}
598
+ bypassPrefetchedCheck: true
599
+ });
646
600
  }
647
601
  };
648
602
  // If child is an <a> tag and doesn't have a href attribute, or if the 'passHref' property is
649
603
  // defined, we specify the current 'href', so that repetition is not needed by the user
650
604
  if (!legacyBehavior || passHref || child.type === "a" && !("href" in child.props)) {
651
- const curLocale = typeof locale !== "undefined" ? locale : router && router.locale;
605
+ const curLocale = typeof locale !== "undefined" ? locale : pagesRouter == null ? void 0 : pagesRouter.locale;
652
606
  // we only render domain locales if we are currently on a domain locale
653
607
  // so that locale links are still visitable in development/preview envs
654
- const localeDomain = router && router.isLocaleDomain && (0, _getDomainLocale).getDomainLocale(as, curLocale, router.locales, router.domainLocales);
655
- childProps.href = localeDomain || (0, _addBasePath).addBasePath((0, _addLocale).addLocale(as, curLocale, router && router.defaultLocale));
608
+ const localeDomain = (pagesRouter == null ? void 0 : pagesRouter.isLocaleDomain) && (0, _getDomainLocale).getDomainLocale(as, curLocale, pagesRouter == null ? void 0 : pagesRouter.locales, pagesRouter == null ? void 0 : pagesRouter.domainLocales);
609
+ childProps.href = localeDomain || (0, _addBasePath).addBasePath((0, _addLocale).addLocale(as, curLocale, pagesRouter == null ? void 0 : pagesRouter.defaultLocale));
656
610
  }
657
611
  return legacyBehavior ? /*#__PURE__*/ _react.default.cloneElement(child, childProps) : /*#__PURE__*/ _react.default.createElement("a", Object.assign({}, restProps, childProps), children);
658
612
  });
@@ -669,7 +623,7 @@ if ((typeof exports.default === "function" || typeof exports.default === "object
669
623
 
670
624
  /***/ }),
671
625
 
672
- /***/ 82392:
626
+ /***/ 52700:
673
627
  /***/ ((module, exports, __webpack_require__) => {
674
628
 
675
629
  "use strict";
@@ -681,7 +635,7 @@ exports.normalizePathTrailingSlash = void 0;
681
635
  var _removeTrailingSlash = __webpack_require__(93297);
682
636
  var _parsePath = __webpack_require__(28854);
683
637
  const normalizePathTrailingSlash = (path)=>{
684
- if (!path.startsWith("/")) {
638
+ if (!path.startsWith("/") || undefined) {
685
639
  return path;
686
640
  }
687
641
  const { pathname , query , hash } = (0, _parsePath).parsePath(path);
@@ -700,7 +654,7 @@ if ((typeof exports.default === "function" || typeof exports.default === "object
700
654
 
701
655
  /***/ }),
702
656
 
703
- /***/ 19320:
657
+ /***/ 82813:
704
658
  /***/ ((module, exports, __webpack_require__) => {
705
659
 
706
660
  "use strict";
@@ -709,7 +663,7 @@ Object.defineProperty(exports, "__esModule", ({
709
663
  value: true
710
664
  }));
711
665
  exports.removeBasePath = removeBasePath;
712
- var _hasBasePath = __webpack_require__(94119);
666
+ var _hasBasePath = __webpack_require__(10928);
713
667
  const basePath = false || "";
714
668
  function removeBasePath(path) {
715
669
  if (false) {}
@@ -728,7 +682,7 @@ if ((typeof exports.default === "function" || typeof exports.default === "object
728
682
 
729
683
  /***/ }),
730
684
 
731
- /***/ 75776:
685
+ /***/ 66876:
732
686
  /***/ ((module, exports, __webpack_require__) => {
733
687
 
734
688
  "use strict";
@@ -753,7 +707,7 @@ if ((typeof exports.default === "function" || typeof exports.default === "object
753
707
 
754
708
  /***/ }),
755
709
 
756
- /***/ 9311:
710
+ /***/ 44686:
757
711
  /***/ ((module, exports) => {
758
712
 
759
713
  "use strict";
@@ -764,7 +718,7 @@ Object.defineProperty(exports, "__esModule", ({
764
718
  exports.cancelIdleCallback = exports.requestIdleCallback = void 0;
765
719
  const requestIdleCallback = typeof self !== "undefined" && self.requestIdleCallback && self.requestIdleCallback.bind(window) || function(cb) {
766
720
  let start = Date.now();
767
- return setTimeout(function() {
721
+ return self.setTimeout(function() {
768
722
  cb({
769
723
  didTimeout: false,
770
724
  timeRemaining: function() {
@@ -789,7 +743,7 @@ if ((typeof exports.default === "function" || typeof exports.default === "object
789
743
 
790
744
  /***/ }),
791
745
 
792
- /***/ 22669:
746
+ /***/ 82497:
793
747
  /***/ ((module, exports, __webpack_require__) => {
794
748
 
795
749
  "use strict";
@@ -803,8 +757,8 @@ exports.getClientBuildManifest = getClientBuildManifest;
803
757
  exports.createRouteLoader = createRouteLoader;
804
758
  var _interop_require_default = (__webpack_require__(92648)/* ["default"] */ .Z);
805
759
  var _getAssetPathFromRoute = _interop_require_default(__webpack_require__(29565));
806
- var _trustedTypes = __webpack_require__(44991);
807
- var _requestIdleCallback = __webpack_require__(9311);
760
+ var _trustedTypes = __webpack_require__(65407);
761
+ var _requestIdleCallback = __webpack_require__(44686);
808
762
  // 3.8s was arbitrarily chosen as it's what https://web.dev/interactive
809
763
  // considers as "Good" time-to-interactive. We must assume something went
810
764
  // wrong beyond this point, and then fall-back to a full page transition to
@@ -832,6 +786,13 @@ function withFuture(key, map, generator) {
832
786
  throw err;
833
787
  }) : prom;
834
788
  }
789
+ const ASSET_LOAD_ERROR = Symbol("ASSET_LOAD_ERROR");
790
+ function markAssetError(err) {
791
+ return Object.defineProperty(err, ASSET_LOAD_ERROR, {});
792
+ }
793
+ function isAssetError(err) {
794
+ return err && ASSET_LOAD_ERROR in err;
795
+ }
835
796
  function hasPrefetch(link) {
836
797
  try {
837
798
  link = document.createElement("link");
@@ -843,33 +804,26 @@ function hasPrefetch(link) {
843
804
  }
844
805
  const canPrefetch = hasPrefetch();
845
806
  function prefetchViaDom(href, as, link) {
846
- return new Promise((res, rej)=>{
807
+ return new Promise((resolve, reject)=>{
847
808
  const selector = `
848
809
  link[rel="prefetch"][href^="${href}"],
849
810
  link[rel="preload"][href^="${href}"],
850
811
  script[src^="${href}"]`;
851
812
  if (document.querySelector(selector)) {
852
- return res();
813
+ return resolve();
853
814
  }
854
815
  link = document.createElement("link");
855
816
  // The order of property assignment here is intentional:
856
817
  if (as) link.as = as;
857
818
  link.rel = `prefetch`;
858
819
  link.crossOrigin = undefined;
859
- link.onload = res;
860
- link.onerror = rej;
820
+ link.onload = resolve;
821
+ link.onerror = ()=>reject(markAssetError(new Error(`Failed to prefetch: ${href}`)));
861
822
  // `href` should always be last:
862
823
  link.href = href;
863
824
  document.head.appendChild(link);
864
825
  });
865
826
  }
866
- const ASSET_LOAD_ERROR = Symbol("ASSET_LOAD_ERROR");
867
- function markAssetError(err) {
868
- return Object.defineProperty(err, ASSET_LOAD_ERROR, {});
869
- }
870
- function isAssetError(err) {
871
- return err && ASSET_LOAD_ERROR in err;
872
- }
873
827
  function appendScript(src, script) {
874
828
  return new Promise((resolve, reject)=>{
875
829
  script = document.createElement("script");
@@ -1015,7 +969,7 @@ function createRouteLoader(assetPrefix) {
1015
969
  return resolvePromiseWithTimeout(getFilesForRoute(assetPrefix, route).then(({ scripts , css })=>{
1016
970
  return Promise.all([
1017
971
  entrypoints.has(route) ? [] : Promise.all(scripts.map(maybeExecuteScript)),
1018
- Promise.all(css.map(fetchStyleSheet)),
972
+ Promise.all(css.map(fetchStyleSheet))
1019
973
  ]);
1020
974
  }).then((res)=>{
1021
975
  return this.whenEntrypoint(route).then((entrypoint)=>({
@@ -1065,12 +1019,12 @@ if ((typeof exports.default === "function" || typeof exports.default === "object
1065
1019
 
1066
1020
  /***/ }),
1067
1021
 
1068
- /***/ 20699:
1022
+ /***/ 63573:
1069
1023
  /***/ ((module, exports, __webpack_require__) => {
1070
1024
 
1071
1025
  "use strict";
1072
1026
 
1073
- "client";
1027
+ "use client";
1074
1028
  Object.defineProperty(exports, "__esModule", ({
1075
1029
  value: true
1076
1030
  }));
@@ -1078,13 +1032,14 @@ exports.handleClientScriptLoad = handleClientScriptLoad;
1078
1032
  exports.initScriptLoader = initScriptLoader;
1079
1033
  exports["default"] = void 0;
1080
1034
  var _extends = (__webpack_require__(6495)/* ["default"] */ .Z);
1035
+ var _interop_require_default = (__webpack_require__(92648)/* ["default"] */ .Z);
1081
1036
  var _interop_require_wildcard = (__webpack_require__(91598)/* ["default"] */ .Z);
1082
1037
  var _object_without_properties_loose = (__webpack_require__(17273)/* ["default"] */ .Z);
1038
+ var _reactDom = _interop_require_default(__webpack_require__(66405));
1083
1039
  var _react = _interop_require_wildcard(__webpack_require__(16689));
1084
1040
  var _headManagerContext = __webpack_require__(92796);
1085
- var _headManager = __webpack_require__(56007);
1086
- var _requestIdleCallback = __webpack_require__(9311);
1087
- "client";
1041
+ var _headManager = __webpack_require__(31831);
1042
+ var _requestIdleCallback = __webpack_require__(44686);
1088
1043
  const ScriptCache = new Map();
1089
1044
  const LoadCache = new Set();
1090
1045
  const ignoreProps = [
@@ -1093,10 +1048,10 @@ const ignoreProps = [
1093
1048
  "dangerouslySetInnerHTML",
1094
1049
  "children",
1095
1050
  "onError",
1096
- "strategy",
1051
+ "strategy"
1097
1052
  ];
1098
1053
  const loadScript = (props)=>{
1099
- const { src , id , onLoad =()=>{} , onReady =null , dangerouslySetInnerHTML , children ="" , strategy ="afterInteractive" , onError , } = props;
1054
+ const { src , id , onLoad =()=>{} , onReady =null , dangerouslySetInnerHTML , children ="" , strategy ="afterInteractive" , onError } = props;
1100
1055
  const cacheKey = id || src;
1101
1056
  // Script has already loaded
1102
1057
  if (cacheKey && LoadCache.has(cacheKey)) {
@@ -1182,7 +1137,7 @@ function loadLazyScript(props) {
1182
1137
  function addBeforeInteractiveToCache() {
1183
1138
  const scripts = [
1184
1139
  ...document.querySelectorAll('[data-nscript="beforeInteractive"]'),
1185
- ...document.querySelectorAll('[data-nscript="beforePageRender"]'),
1140
+ ...document.querySelectorAll('[data-nscript="beforePageRender"]')
1186
1141
  ];
1187
1142
  scripts.forEach((script)=>{
1188
1143
  const cacheKey = script.id || script.getAttribute("src");
@@ -1203,7 +1158,7 @@ function Script(props) {
1203
1158
  "onError"
1204
1159
  ]);
1205
1160
  // Context is available only during SSR
1206
- const { updateScripts , scripts , getIsSsr } = (0, _react).useContext(_headManagerContext.HeadManagerContext);
1161
+ const { updateScripts , scripts , getIsSsr , appDir , nonce } = (0, _react).useContext(_headManagerContext.HeadManagerContext);
1207
1162
  /**
1208
1163
  * - First mount:
1209
1164
  * 1. The useEffect for onReady executes
@@ -1267,7 +1222,7 @@ function Script(props) {
1267
1222
  onLoad,
1268
1223
  onReady,
1269
1224
  onError
1270
- }, restProps),
1225
+ }, restProps)
1271
1226
  ]);
1272
1227
  updateScripts(scripts);
1273
1228
  } else if (getIsSsr && getIsSsr()) {
@@ -1277,6 +1232,54 @@ function Script(props) {
1277
1232
  loadScript(props);
1278
1233
  }
1279
1234
  }
1235
+ // For the app directory, we need React Float to preload these scripts.
1236
+ if (appDir) {
1237
+ // Before interactive scripts need to be loaded by Next.js' runtime instead
1238
+ // of native <script> tags, because they no longer have `defer`.
1239
+ if (strategy === "beforeInteractive") {
1240
+ if (!src) {
1241
+ // For inlined scripts, we put the content in `children`.
1242
+ if (restProps.dangerouslySetInnerHTML) {
1243
+ restProps.children = restProps.dangerouslySetInnerHTML.__html;
1244
+ delete restProps.dangerouslySetInnerHTML;
1245
+ }
1246
+ return /*#__PURE__*/ _react.default.createElement("script", {
1247
+ nonce: nonce,
1248
+ dangerouslySetInnerHTML: {
1249
+ __html: `(self.__next_s=self.__next_s||[]).push(${JSON.stringify([
1250
+ 0,
1251
+ _extends({}, restProps)
1252
+ ])})`
1253
+ }
1254
+ });
1255
+ }
1256
+ // @ts-ignore
1257
+ _reactDom.default.preload(src, restProps.integrity ? {
1258
+ as: "script",
1259
+ integrity: restProps.integrity
1260
+ } : {
1261
+ as: "script"
1262
+ });
1263
+ return /*#__PURE__*/ _react.default.createElement("script", {
1264
+ nonce: nonce,
1265
+ dangerouslySetInnerHTML: {
1266
+ __html: `(self.__next_s=self.__next_s||[]).push(${JSON.stringify([
1267
+ src
1268
+ ])})`
1269
+ }
1270
+ });
1271
+ } else if (strategy === "afterInteractive") {
1272
+ if (src) {
1273
+ // @ts-ignore
1274
+ _reactDom.default.preload(src, restProps.integrity ? {
1275
+ as: "script",
1276
+ integrity: restProps.integrity
1277
+ } : {
1278
+ as: "script"
1279
+ });
1280
+ }
1281
+ }
1282
+ }
1280
1283
  return null;
1281
1284
  }
1282
1285
  Object.defineProperty(Script, "__nextScript", {
@@ -1295,7 +1298,7 @@ if ((typeof exports.default === "function" || typeof exports.default === "object
1295
1298
 
1296
1299
  /***/ }),
1297
1300
 
1298
- /***/ 44991:
1301
+ /***/ 65407:
1299
1302
  /***/ ((module, exports) => {
1300
1303
 
1301
1304
  "use strict";
@@ -1330,7 +1333,7 @@ if ((typeof exports.default === "function" || typeof exports.default === "object
1330
1333
 
1331
1334
  /***/ }),
1332
1335
 
1333
- /***/ 57190:
1336
+ /***/ 69246:
1334
1337
  /***/ ((module, exports, __webpack_require__) => {
1335
1338
 
1336
1339
  "use strict";
@@ -1340,7 +1343,7 @@ Object.defineProperty(exports, "__esModule", ({
1340
1343
  }));
1341
1344
  exports.useIntersection = useIntersection;
1342
1345
  var _react = __webpack_require__(16689);
1343
- var _requestIdleCallback = __webpack_require__(9311);
1346
+ var _requestIdleCallback = __webpack_require__(44686);
1344
1347
  const hasIntersectionObserver = typeof IntersectionObserver === "function";
1345
1348
  const observers = new Map();
1346
1349
  const idList = [];
@@ -1397,10 +1400,14 @@ function observe(element, callback, options) {
1397
1400
  function useIntersection({ rootRef , rootMargin , disabled }) {
1398
1401
  const isDisabled = disabled || !hasIntersectionObserver;
1399
1402
  const [visible, setVisible] = (0, _react).useState(false);
1400
- const [element, setElement] = (0, _react).useState(null);
1403
+ const elementRef = (0, _react).useRef(null);
1404
+ const setElement = (0, _react).useCallback((element)=>{
1405
+ elementRef.current = element;
1406
+ }, []);
1401
1407
  (0, _react).useEffect(()=>{
1402
1408
  if (hasIntersectionObserver) {
1403
1409
  if (isDisabled || visible) return;
1410
+ const element = elementRef.current;
1404
1411
  if (element && element.tagName) {
1405
1412
  const unobserve = observe(element, (isVisible)=>isVisible && setVisible(isVisible), {
1406
1413
  root: rootRef == null ? void 0 : rootRef.current,
@@ -1414,12 +1421,13 @@ function useIntersection({ rootRef , rootMargin , disabled }) {
1414
1421
  return ()=>(0, _requestIdleCallback).cancelIdleCallback(idleCallback);
1415
1422
  }
1416
1423
  }
1424
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1417
1425
  }, [
1418
- element,
1419
1426
  isDisabled,
1420
1427
  rootMargin,
1421
1428
  rootRef,
1422
- visible
1429
+ visible,
1430
+ elementRef.current
1423
1431
  ]);
1424
1432
  const resetVisible = (0, _react).useCallback(()=>{
1425
1433
  setVisible(false);
@@ -1441,7 +1449,7 @@ if ((typeof exports.default === "function" || typeof exports.default === "object
1441
1449
 
1442
1450
  /***/ }),
1443
1451
 
1444
- /***/ 76273:
1452
+ /***/ 41003:
1445
1453
  /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
1446
1454
 
1447
1455
  "use strict";
@@ -1453,16 +1461,17 @@ exports.matchesMiddleware = matchesMiddleware;
1453
1461
  exports.isLocalURL = isLocalURL;
1454
1462
  exports.interpolateAs = interpolateAs;
1455
1463
  exports.resolveHref = resolveHref;
1464
+ exports.handleSmoothScroll = handleSmoothScroll;
1456
1465
  exports.createKey = createKey;
1457
1466
  exports["default"] = void 0;
1458
1467
  var _async_to_generator = (__webpack_require__(60932)/* ["default"] */ .Z);
1459
1468
  var _extends = (__webpack_require__(6495)/* ["default"] */ .Z);
1460
1469
  var _interop_require_default = (__webpack_require__(92648)/* ["default"] */ .Z);
1461
1470
  var _interop_require_wildcard = (__webpack_require__(91598)/* ["default"] */ .Z);
1462
- var _normalizeTrailingSlash = __webpack_require__(82392);
1471
+ var _normalizeTrailingSlash = __webpack_require__(52700);
1463
1472
  var _removeTrailingSlash = __webpack_require__(93297);
1464
- var _routeLoader = __webpack_require__(22669);
1465
- var _script = __webpack_require__(20699);
1473
+ var _routeLoader = __webpack_require__(82497);
1474
+ var _script = __webpack_require__(63573);
1466
1475
  var _isError = _interop_require_wildcard(__webpack_require__(80676));
1467
1476
  var _denormalizePagePath = __webpack_require__(64406);
1468
1477
  var _normalizeLocalePath = __webpack_require__(34014);
@@ -1475,13 +1484,14 @@ var _resolveRewrites = _interop_require_default(__webpack_require__(36052));
1475
1484
  var _routeMatcher = __webpack_require__(84226);
1476
1485
  var _routeRegex = __webpack_require__(95052);
1477
1486
  var _formatUrl = __webpack_require__(23938);
1478
- var _detectDomainLocale = __webpack_require__(38748);
1487
+ var _detectDomainLocale = __webpack_require__(84643);
1479
1488
  var _parsePath = __webpack_require__(28854);
1480
- var _addLocale = __webpack_require__(22725);
1481
- var _removeLocale = __webpack_require__(75776);
1482
- var _removeBasePath = __webpack_require__(19320);
1483
- var _addBasePath = __webpack_require__(98684);
1484
- var _hasBasePath = __webpack_require__(94119);
1489
+ var _addLocale = __webpack_require__(54465);
1490
+ var _removeLocale = __webpack_require__(66876);
1491
+ var _removeBasePath = __webpack_require__(82813);
1492
+ var _addBasePath = __webpack_require__(33468);
1493
+ var _hasBasePath = __webpack_require__(10928);
1494
+ var _isApiRoute = __webpack_require__(79423);
1485
1495
  var _getNextPathnameInfo = __webpack_require__(35789);
1486
1496
  var _formatNextPathnameInfo = __webpack_require__(10299);
1487
1497
  var _compareStates = __webpack_require__(46220);
@@ -1628,15 +1638,15 @@ function prepareUrlAs(router, url, as) {
1628
1638
  // we'll format them into the string version here.
1629
1639
  let [resolvedHref, resolvedAs] = resolveHref(router, url, true);
1630
1640
  const origin = (0, _utils).getLocationOrigin();
1631
- const hrefHadOrigin = resolvedHref.startsWith(origin);
1632
- const asHadOrigin = resolvedAs && resolvedAs.startsWith(origin);
1641
+ const hrefWasAbsolute = resolvedHref.startsWith(origin);
1642
+ const asWasAbsolute = resolvedAs && resolvedAs.startsWith(origin);
1633
1643
  resolvedHref = stripOrigin(resolvedHref);
1634
1644
  resolvedAs = resolvedAs ? stripOrigin(resolvedAs) : resolvedAs;
1635
- const preparedUrl = hrefHadOrigin ? resolvedHref : (0, _addBasePath).addBasePath(resolvedHref);
1645
+ const preparedUrl = hrefWasAbsolute ? resolvedHref : (0, _addBasePath).addBasePath(resolvedHref);
1636
1646
  const preparedAs = as ? stripOrigin(resolveHref(router, as)) : resolvedAs || resolvedHref;
1637
1647
  return {
1638
1648
  url: preparedUrl,
1639
- as: asHadOrigin ? preparedAs : (0, _addBasePath).addBasePath(preparedAs)
1649
+ as: asWasAbsolute ? preparedAs : (0, _addBasePath).addBasePath(preparedAs)
1640
1650
  };
1641
1651
  }
1642
1652
  function resolveDynamicRoute(pathname, pages) {
@@ -1681,7 +1691,7 @@ function getMiddlewareData(source, response, options) {
1681
1691
  let fsPathname = (0, _removeTrailingSlash).removeTrailingSlash(pathnameInfo.pathname);
1682
1692
  return Promise.all([
1683
1693
  options.router.pageLoader.getPageList(),
1684
- (0, _routeLoader).getClientBuildManifest(),
1694
+ (0, _routeLoader).getClientBuildManifest()
1685
1695
  ]).then(([pages, { __rewrites: rewrites }])=>{
1686
1696
  let as = (0, _addLocale).addLocale(pathnameInfo.pathname, pathnameInfo.locale);
1687
1697
  if ((0, _isDynamic).isDynamicRoute(as) || !rewriteHeader && pages.includes((0, _normalizeLocalePath).normalizeLocalePath((0, _removeBasePath).removeBasePath(as), options.router.locales).pathname)) {
@@ -1725,8 +1735,8 @@ function getMiddlewareData(source, response, options) {
1725
1735
  const redirectTarget = response.headers.get("x-nextjs-redirect");
1726
1736
  if (redirectTarget) {
1727
1737
  if (redirectTarget.startsWith("/")) {
1728
- const src1 = (0, _parsePath).parsePath(redirectTarget);
1729
- const pathname1 = (0, _formatNextPathnameInfo).formatNextPathnameInfo(_extends({}, (0, _getNextPathnameInfo).getNextPathnameInfo(src1.pathname, {
1738
+ const src = (0, _parsePath).parsePath(redirectTarget);
1739
+ const pathname = (0, _formatNextPathnameInfo).formatNextPathnameInfo(_extends({}, (0, _getNextPathnameInfo).getNextPathnameInfo(src.pathname, {
1730
1740
  nextConfig,
1731
1741
  parseData: true
1732
1742
  }), {
@@ -1735,8 +1745,8 @@ function getMiddlewareData(source, response, options) {
1735
1745
  }));
1736
1746
  return Promise.resolve({
1737
1747
  type: "redirect-internal",
1738
- newAs: `${pathname1}${src1.query}${src1.hash}`,
1739
- newUrl: `${pathname1}${src1.query}${src1.hash}`
1748
+ newAs: `${pathname}${src.query}${src.hash}`,
1749
+ newUrl: `${pathname}${src.query}${src.hash}`
1740
1750
  });
1741
1751
  }
1742
1752
  return Promise.resolve({
@@ -1749,25 +1759,34 @@ function getMiddlewareData(source, response, options) {
1749
1759
  });
1750
1760
  }
1751
1761
  function withMiddlewareEffects(options) {
1752
- return matchesMiddleware(options).then((matches)=>{
1753
- if (matches && options.fetchData) {
1754
- return options.fetchData().then((data)=>getMiddlewareData(data.dataHref, data.response, options).then((effect)=>({
1755
- dataHref: data.dataHref,
1756
- cacheKey: data.cacheKey,
1757
- json: data.json,
1758
- response: data.response,
1759
- text: data.text,
1760
- effect
1761
- }))).catch((_err)=>{
1762
- /**
1763
- * TODO: Revisit this in the future.
1764
- * For now we will not consider middleware data errors to be fatal.
1765
- * maybe we should revisit in the future.
1766
- */ return null;
1767
- });
1762
+ return _withMiddlewareEffects.apply(this, arguments);
1763
+ }
1764
+ function _withMiddlewareEffects() {
1765
+ _withMiddlewareEffects = _async_to_generator(function*(options) {
1766
+ const matches = yield matchesMiddleware(options);
1767
+ if (!matches || !options.fetchData) {
1768
+ return null;
1769
+ }
1770
+ try {
1771
+ const data = yield options.fetchData();
1772
+ const effect = yield getMiddlewareData(data.dataHref, data.response, options);
1773
+ return {
1774
+ dataHref: data.dataHref,
1775
+ json: data.json,
1776
+ response: data.response,
1777
+ text: data.text,
1778
+ cacheKey: data.cacheKey,
1779
+ effect
1780
+ };
1781
+ } catch (e) {
1782
+ /**
1783
+ * TODO: Revisit this in the future.
1784
+ * For now we will not consider middleware data errors to be fatal.
1785
+ * maybe we should revisit in the future.
1786
+ */ return null;
1768
1787
  }
1769
- return null;
1770
1788
  });
1789
+ return _withMiddlewareEffects.apply(this, arguments);
1771
1790
  }
1772
1791
  const manualScrollRestoration = (/* unused pure expression or super */ null && ( false && 0));
1773
1792
  const SSG_DATA_NOT_FOUND = Symbol("SSG_DATA_NOT_FOUND");
@@ -1793,11 +1812,16 @@ function fetchRetry(url, attempts, options) {
1793
1812
  return !response.ok && attempts > 1 && response.status >= 500 ? fetchRetry(url, attempts - 1, options) : response;
1794
1813
  });
1795
1814
  }
1796
- const backgroundCache = {};
1797
- function handleSmoothScroll(fn) {
1815
+ function handleSmoothScroll(fn, options = {}) {
1798
1816
  const htmlElement = document.documentElement;
1799
1817
  const existing = htmlElement.style.scrollBehavior;
1800
1818
  htmlElement.style.scrollBehavior = "auto";
1819
+ if (!options.dontForceLayout) {
1820
+ // In Chrome-based browsers we need to force reflow before calling `scrollTo`.
1821
+ // Otherwise it will not pickup the change in scrollBehavior
1822
+ // More info here: https://github.com/vercel/next.js/issues/40719#issuecomment-1336248042
1823
+ htmlElement.getClientRects();
1824
+ }
1801
1825
  fn();
1802
1826
  htmlElement.style.scrollBehavior = existing;
1803
1827
  }
@@ -1813,9 +1837,11 @@ function fetchNextData({ dataHref , inflightCache , isPrefetch , hasMiddleware ,
1813
1837
  var ref1;
1814
1838
  const getData = (params)=>{
1815
1839
  return fetchRetry(dataHref, isServerRender ? 3 : 1, {
1816
- headers: isPrefetch ? {
1840
+ headers: Object.assign({}, isPrefetch ? {
1817
1841
  purpose: "prefetch"
1818
- } : {},
1842
+ } : {}, isPrefetch && hasMiddleware ? {
1843
+ "x-middleware-prefetch": "1"
1844
+ } : {}),
1819
1845
  method: (ref1 = params == null ? void 0 : params.method) != null ? ref1 : "GET"
1820
1846
  }).then((response)=>{
1821
1847
  if (response.ok && (params == null ? void 0 : params.method) === "HEAD") {
@@ -1886,7 +1912,14 @@ function fetchNextData({ dataHref , inflightCache , isPrefetch , hasMiddleware ,
1886
1912
  }
1887
1913
  return data;
1888
1914
  }).catch((err)=>{
1889
- delete inflightCache[cacheKey];
1915
+ if (!unstable_skipClientCache) {
1916
+ delete inflightCache[cacheKey];
1917
+ }
1918
+ if (err.message === "Failed to fetch" || // firefox
1919
+ err.message === "NetworkError when attempting to fetch resource." || // safari
1920
+ err.message === "Load failed") {
1921
+ (0, _routeLoader).markAssetError(err);
1922
+ }
1890
1923
  throw err;
1891
1924
  });
1892
1925
  };
@@ -1945,6 +1978,11 @@ class Router {
1945
1978
  window.history.back();
1946
1979
  }
1947
1980
  /**
1981
+ * Go forward in history
1982
+ */ forward() {
1983
+ window.history.forward();
1984
+ }
1985
+ /**
1948
1986
  * Performs a `pushState` with arguments
1949
1987
  * @param url of the route
1950
1988
  * @param as masks `url` for the browser
@@ -1976,8 +2014,8 @@ class Router {
1976
2014
  // WARNING: `_h` is an internal option for handing Next.js client-side
1977
2015
  // hydration. Your app should _never_ use this property. It may change at
1978
2016
  // any time without notice.
1979
- const isQueryUpdating = options._h;
1980
- const shouldResolveHref = isQueryUpdating || options._shouldResolveHref || (0, _parsePath).parsePath(url).pathname === (0, _parsePath).parsePath(as).pathname;
2017
+ const isQueryUpdating = options._h === 1;
2018
+ let shouldResolveHref = isQueryUpdating || options._shouldResolveHref || (0, _parsePath).parsePath(url).pathname === (0, _parsePath).parsePath(as).pathname;
1981
2019
  const nextState = _extends({}, _this.state);
1982
2020
  // for static pages with query params in the URL we delay
1983
2021
  // marking the router ready until after the query is updated
@@ -2047,9 +2085,9 @@ class Router {
2047
2085
  [pages, { __rewrites: rewrites }] = yield Promise.all([
2048
2086
  _this.pageLoader.getPageList(),
2049
2087
  (0, _routeLoader).getClientBuildManifest(),
2050
- _this.pageLoader.getMiddleware(),
2088
+ _this.pageLoader.getMiddleware()
2051
2089
  ]);
2052
- } catch (err1) {
2090
+ } catch (err) {
2053
2091
  // If we fail to resolve the page list or client-build manifest, we must
2054
2092
  // do a server-side transition:
2055
2093
  handleHardNavigation({
@@ -2073,15 +2111,18 @@ class Router {
2073
2111
  // point by either next/link or router.push/replace so strip the
2074
2112
  // basePath from the pathname to match the pages dir 1-to-1
2075
2113
  pathname = pathname ? (0, _removeTrailingSlash).removeTrailingSlash((0, _removeBasePath).removeBasePath(pathname)) : pathname;
2114
+ let route = (0, _removeTrailingSlash).removeTrailingSlash(pathname);
2115
+ const parsedAsPathname = as.startsWith("/") && (0, _parseRelativeUrl).parseRelativeUrl(as).pathname;
2116
+ const isMiddlewareRewrite = !!(parsedAsPathname && route !== parsedAsPathname && (!(0, _isDynamic).isDynamicRoute(route) || !(0, _routeMatcher).getRouteMatcher((0, _routeRegex).getRouteRegex(route))(parsedAsPathname)));
2076
2117
  // we don't attempt resolve asPath when we need to execute
2077
2118
  // middleware as the resolving will occur server-side
2078
- const isMiddlewareMatch = yield matchesMiddleware({
2119
+ const isMiddlewareMatch = !options.shallow && (yield matchesMiddleware({
2079
2120
  asPath: as,
2080
2121
  locale: nextState.locale,
2081
2122
  router: _this
2082
- });
2083
- if (options.shallow && isMiddlewareMatch) {
2084
- pathname = _this.pathname;
2123
+ }));
2124
+ if (isQueryUpdating && isMiddlewareMatch) {
2125
+ shouldResolveHref = false;
2085
2126
  }
2086
2127
  if (shouldResolveHref && pathname !== "/_error") {
2087
2128
  options._shouldResolveHref = true;
@@ -2105,23 +2146,23 @@ class Router {
2105
2146
  return false;
2106
2147
  }
2107
2148
  resolvedAs = (0, _removeLocale).removeLocale((0, _removeBasePath).removeBasePath(resolvedAs), nextState.locale);
2108
- let route = (0, _removeTrailingSlash).removeTrailingSlash(pathname);
2149
+ route = (0, _removeTrailingSlash).removeTrailingSlash(pathname);
2109
2150
  let routeMatch = false;
2110
2151
  if ((0, _isDynamic).isDynamicRoute(route)) {
2111
- const parsedAs1 = (0, _parseRelativeUrl).parseRelativeUrl(resolvedAs);
2112
- const asPathname = parsedAs1.pathname;
2152
+ const parsedAs = (0, _parseRelativeUrl).parseRelativeUrl(resolvedAs);
2153
+ const asPathname = parsedAs.pathname;
2113
2154
  const routeRegex = (0, _routeRegex).getRouteRegex(route);
2114
2155
  routeMatch = (0, _routeMatcher).getRouteMatcher(routeRegex)(asPathname);
2115
2156
  const shouldInterpolate = route === asPathname;
2116
2157
  const interpolatedAs = shouldInterpolate ? interpolateAs(route, asPathname, query) : {};
2117
2158
  if (!routeMatch || shouldInterpolate && !interpolatedAs.result) {
2118
- const missingParams = Object.keys(routeRegex.groups).filter((param)=>!query[param]);
2159
+ const missingParams = Object.keys(routeRegex.groups).filter((param)=>!query[param] && !routeRegex.groups[param].optional);
2119
2160
  if (missingParams.length > 0 && !isMiddlewareMatch) {
2120
2161
  if (false) {}
2121
2162
  throw new Error((shouldInterpolate ? `The provided \`href\` (${url}) value is missing query values (${missingParams.join(", ")}) to be interpolated properly. ` : `The provided \`as\` value (${asPathname}) is incompatible with the \`href\` value (${route}). `) + `Read more: https://nextjs.org/docs/messages/${shouldInterpolate ? "href-interpolation-failed" : "incompatible-href-as"}`);
2122
2163
  }
2123
2164
  } else if (shouldInterpolate) {
2124
- as = (0, _formatUrl).formatWithValidation(Object.assign({}, parsedAs1, {
2165
+ as = (0, _formatUrl).formatWithValidation(Object.assign({}, parsedAs, {
2125
2166
  pathname: interpolatedAs.result,
2126
2167
  query: omit(query, interpolatedAs.params)
2127
2168
  }));
@@ -2134,7 +2175,7 @@ class Router {
2134
2175
  Router.events.emit("routeChangeStart", as, routeProps);
2135
2176
  }
2136
2177
  try {
2137
- var ref2, ref3;
2178
+ var ref2, ref3, ref4;
2138
2179
  let routeInfo = yield _this.getRouteInfo({
2139
2180
  route,
2140
2181
  pathname,
@@ -2144,7 +2185,10 @@ class Router {
2144
2185
  routeProps,
2145
2186
  locale: nextState.locale,
2146
2187
  isPreview: nextState.isPreview,
2147
- hasMiddleware: isMiddlewareMatch
2188
+ hasMiddleware: isMiddlewareMatch,
2189
+ unstable_skipClientCache: options.unstable_skipClientCache,
2190
+ isQueryUpdating: isQueryUpdating && !_this.isFallback,
2191
+ isMiddlewareRewrite
2148
2192
  });
2149
2193
  if ("route" in routeInfo && isMiddlewareMatch) {
2150
2194
  pathname = routeInfo.route || route;
@@ -2167,8 +2211,8 @@ class Router {
2167
2211
  rewriteAs = (0, _removeBasePath).removeBasePath(rewriteAs);
2168
2212
  }
2169
2213
  if (false) {}
2170
- const routeRegex1 = (0, _routeRegex).getRouteRegex(pathname);
2171
- const curRouteMatch = (0, _routeMatcher).getRouteMatcher(routeRegex1)(rewriteAs);
2214
+ const routeRegex = (0, _routeRegex).getRouteRegex(pathname);
2215
+ const curRouteMatch = (0, _routeMatcher).getRouteMatcher(routeRegex)(new URL(rewriteAs, location.href).pathname);
2172
2216
  if (curRouteMatch) {
2173
2217
  Object.assign(query, curRouteMatch);
2174
2218
  }
@@ -2186,7 +2230,6 @@ class Router {
2186
2230
  return new Promise(()=>{});
2187
2231
  }
2188
2232
  }
2189
- let { error , props , __N_SSG , __N_SSP } = routeInfo;
2190
2233
  const component = routeInfo.Component;
2191
2234
  if (component && component.unstable_scriptLoader) {
2192
2235
  const scripts = [].concat(component.unstable_scriptLoader());
@@ -2195,15 +2238,15 @@ class Router {
2195
2238
  });
2196
2239
  }
2197
2240
  // handle redirect on client-transition
2198
- if ((__N_SSG || __N_SSP) && props) {
2199
- if (props.pageProps && props.pageProps.__N_REDIRECT) {
2241
+ if ((routeInfo.__N_SSG || routeInfo.__N_SSP) && routeInfo.props) {
2242
+ if (routeInfo.props.pageProps && routeInfo.props.pageProps.__N_REDIRECT) {
2200
2243
  // Use the destination from redirect without adding locale
2201
2244
  options.locale = false;
2202
- const destination = props.pageProps.__N_REDIRECT;
2245
+ const destination = routeInfo.props.pageProps.__N_REDIRECT;
2203
2246
  // check if destination is internal (resolves to a page) and attempt
2204
2247
  // client-navigation if it is falling back to hard navigation if
2205
2248
  // it's not
2206
- if (destination.startsWith("/") && props.pageProps.__N_REDIRECT_BASE_PATH !== false) {
2249
+ if (destination.startsWith("/") && routeInfo.props.pageProps.__N_REDIRECT_BASE_PATH !== false) {
2207
2250
  const parsedHref = (0, _parseRelativeUrl).parseRelativeUrl(destination);
2208
2251
  parsedHref.pathname = resolveDynamicRoute(parsedHref.pathname, pages);
2209
2252
  const { url: newUrl , as: newAs } = prepareUrlAs(_this, destination, destination);
@@ -2215,9 +2258,9 @@ class Router {
2215
2258
  });
2216
2259
  return new Promise(()=>{});
2217
2260
  }
2218
- nextState.isPreview = !!props.__N_PREVIEW;
2261
+ nextState.isPreview = !!routeInfo.props.__N_PREVIEW;
2219
2262
  // handle SSG data 404
2220
- if (props.notFound === SSG_DATA_NOT_FOUND) {
2263
+ if (routeInfo.props.notFound === SSG_DATA_NOT_FOUND) {
2221
2264
  let notFoundRoute;
2222
2265
  try {
2223
2266
  yield _this.fetchComponent("/404");
@@ -2242,22 +2285,21 @@ class Router {
2242
2285
  }
2243
2286
  }
2244
2287
  }
2245
- Router.events.emit("beforeHistoryChange", as, routeProps);
2246
- _this.changeState(method, url, as, options);
2247
- if (isQueryUpdating && pathname === "/_error" && ((ref2 = self.__NEXT_DATA__.props) == null ? void 0 : (ref3 = ref2.pageProps) == null ? void 0 : ref3.statusCode) === 500 && (props == null ? void 0 : props.pageProps)) {
2288
+ if (isQueryUpdating && _this.pathname === "/_error" && ((ref2 = self.__NEXT_DATA__.props) == null ? void 0 : (ref3 = ref2.pageProps) == null ? void 0 : ref3.statusCode) === 500 && ((ref4 = routeInfo.props) == null ? void 0 : ref4.pageProps)) {
2248
2289
  // ensure statusCode is still correct for static 500 page
2249
2290
  // when updating query information
2250
- props.pageProps.statusCode = 500;
2291
+ routeInfo.props.pageProps.statusCode = 500;
2251
2292
  }
2252
2293
  var _route;
2253
2294
  // shallow routing is only allowed for same page URL changes.
2254
2295
  const isValidShallowRoute = options.shallow && nextState.route === ((_route = routeInfo.route) != null ? _route : route);
2255
2296
  var _scroll;
2256
- const shouldScroll = (_scroll = options.scroll) != null ? _scroll : !options._h && !isValidShallowRoute;
2297
+ const shouldScroll = (_scroll = options.scroll) != null ? _scroll : !isQueryUpdating && !isValidShallowRoute;
2257
2298
  const resetScroll = shouldScroll ? {
2258
2299
  x: 0,
2259
2300
  y: 0
2260
2301
  } : null;
2302
+ const upcomingScrollState = forcedScroll != null ? forcedScroll : resetScroll;
2261
2303
  // the new state that the router gonna set
2262
2304
  const upcomingRouterState = _extends({}, nextState, {
2263
2305
  route,
@@ -2266,21 +2308,61 @@ class Router {
2266
2308
  asPath: cleanedAs,
2267
2309
  isFallback: false
2268
2310
  });
2269
- const upcomingScrollState = forcedScroll != null ? forcedScroll : resetScroll;
2311
+ // When the page being rendered is the 404 page, we should only update the
2312
+ // query parameters. Route changes here might add the basePath when it
2313
+ // wasn't originally present. This is also why this block is before the
2314
+ // below `changeState` call which updates the browser's history (changing
2315
+ // the URL).
2316
+ if (isQueryUpdating && (_this.pathname === "/404" || _this.pathname === "/_error")) {
2317
+ var ref5, ref6, ref7;
2318
+ routeInfo = yield _this.getRouteInfo({
2319
+ route: _this.pathname,
2320
+ pathname: _this.pathname,
2321
+ query,
2322
+ as,
2323
+ resolvedAs,
2324
+ routeProps: {
2325
+ shallow: false
2326
+ },
2327
+ locale: nextState.locale,
2328
+ isPreview: nextState.isPreview
2329
+ });
2330
+ if ("type" in routeInfo) {
2331
+ throw new Error(`Unexpected middleware effect on ${_this.pathname}`);
2332
+ }
2333
+ if (_this.pathname === "/_error" && ((ref5 = self.__NEXT_DATA__.props) == null ? void 0 : (ref6 = ref5.pageProps) == null ? void 0 : ref6.statusCode) === 500 && ((ref7 = routeInfo.props) == null ? void 0 : ref7.pageProps)) {
2334
+ // ensure statusCode is still correct for static 500 page
2335
+ // when updating query information
2336
+ routeInfo.props.pageProps.statusCode = 500;
2337
+ }
2338
+ try {
2339
+ yield _this.set(upcomingRouterState, routeInfo, upcomingScrollState);
2340
+ } catch (err) {
2341
+ if ((0, _isError).default(err) && err.cancelled) {
2342
+ Router.events.emit("routeChangeError", err, cleanedAs, routeProps);
2343
+ }
2344
+ throw err;
2345
+ }
2346
+ return true;
2347
+ }
2348
+ Router.events.emit("beforeHistoryChange", as, routeProps);
2349
+ _this.changeState(method, url, as, options);
2270
2350
  // for query updates we can skip it if the state is unchanged and we don't
2271
2351
  // need to scroll
2272
2352
  // https://github.com/vercel/next.js/issues/37139
2273
- const canSkipUpdating = options._h && !upcomingScrollState && !readyStateChange && !localeChange && (0, _compareStates).compareRouterStates(upcomingRouterState, _this.state);
2353
+ const canSkipUpdating = isQueryUpdating && !upcomingScrollState && !readyStateChange && !localeChange && (0, _compareStates).compareRouterStates(upcomingRouterState, _this.state);
2274
2354
  if (!canSkipUpdating) {
2275
- yield _this.set(upcomingRouterState, routeInfo, upcomingScrollState).catch((e)=>{
2276
- if (e.cancelled) error = error || e;
2355
+ try {
2356
+ yield _this.set(upcomingRouterState, routeInfo, upcomingScrollState);
2357
+ } catch (e) {
2358
+ if (e.cancelled) routeInfo.error = routeInfo.error || e;
2277
2359
  else throw e;
2278
- });
2279
- if (error) {
2360
+ }
2361
+ if (routeInfo.error) {
2280
2362
  if (!isQueryUpdating) {
2281
- Router.events.emit("routeChangeError", error, cleanedAs, routeProps);
2363
+ Router.events.emit("routeChangeError", routeInfo.error, cleanedAs, routeProps);
2282
2364
  }
2283
- throw error;
2365
+ throw routeInfo.error;
2284
2366
  }
2285
2367
  if (false) {}
2286
2368
  if (!isQueryUpdating) {
@@ -2293,11 +2375,11 @@ class Router {
2293
2375
  }
2294
2376
  }
2295
2377
  return true;
2296
- } catch (err11) {
2297
- if ((0, _isError).default(err11) && err11.cancelled) {
2378
+ } catch (err1) {
2379
+ if ((0, _isError).default(err1) && err1.cancelled) {
2298
2380
  return false;
2299
2381
  }
2300
- throw err11;
2382
+ throw err1;
2301
2383
  }
2302
2384
  })();
2303
2385
  }
@@ -2367,7 +2449,7 @@ class Router {
2367
2449
  }
2368
2450
  })();
2369
2451
  }
2370
- getRouteInfo({ route: requestedRoute , pathname , query , as , resolvedAs , routeProps , locale , hasMiddleware , isPreview , unstable_skipClientCache }) {
2452
+ getRouteInfo({ route: requestedRoute , pathname , query , as , resolvedAs , routeProps , locale , hasMiddleware , isPreview , unstable_skipClientCache , isQueryUpdating , isMiddlewareRewrite }) {
2371
2453
  var _this = this;
2372
2454
  return _async_to_generator(function*() {
2373
2455
  /**
@@ -2377,7 +2459,7 @@ class Router {
2377
2459
  * for shallow routing purposes.
2378
2460
  */ let route = requestedRoute;
2379
2461
  try {
2380
- var ref, ref4, ref5;
2462
+ var ref, ref8, ref9, ref10;
2381
2463
  const handleCancelled = getCancelledHandler({
2382
2464
  route,
2383
2465
  router: _this
@@ -2390,6 +2472,7 @@ class Router {
2390
2472
  existingInfo = undefined;
2391
2473
  }
2392
2474
  let cachedRouteInfo = existingInfo && !("initial" in existingInfo) && "production" !== "development" ? existingInfo : undefined;
2475
+ const isBackground = isQueryUpdating;
2393
2476
  const fetchNextDataParams = {
2394
2477
  dataHref: _this.pageLoader.getDataHref({
2395
2478
  href: (0, _formatUrl).formatWithValidation({
@@ -2403,38 +2486,65 @@ class Router {
2403
2486
  hasMiddleware: true,
2404
2487
  isServerRender: _this.isSsr,
2405
2488
  parseJSON: true,
2406
- inflightCache: _this.sdc,
2489
+ inflightCache: isBackground ? _this.sbc : _this.sdc,
2407
2490
  persistCache: !isPreview,
2408
2491
  isPrefetch: false,
2409
- unstable_skipClientCache
2492
+ unstable_skipClientCache,
2493
+ isBackground
2410
2494
  };
2411
- const data = yield withMiddlewareEffects({
2495
+ let data = isQueryUpdating && !isMiddlewareRewrite ? null : yield withMiddlewareEffects({
2412
2496
  fetchData: ()=>fetchNextData(fetchNextDataParams),
2413
2497
  asPath: resolvedAs,
2414
2498
  locale: locale,
2415
2499
  router: _this
2500
+ }).catch((err)=>{
2501
+ // we don't hard error during query updating
2502
+ // as it's un-necessary and doesn't need to be fatal
2503
+ // unless it is a fallback route and the props can't
2504
+ // be loaded
2505
+ if (isQueryUpdating) {
2506
+ return null;
2507
+ }
2508
+ throw err;
2416
2509
  });
2510
+ if (isQueryUpdating) {
2511
+ if (!data) {
2512
+ data = {
2513
+ json: self.__NEXT_DATA__.props
2514
+ };
2515
+ } else {
2516
+ data.json = self.__NEXT_DATA__.props;
2517
+ }
2518
+ }
2417
2519
  handleCancelled();
2418
- if ((data == null ? void 0 : (ref = data.effect) == null ? void 0 : ref.type) === "redirect-internal" || (data == null ? void 0 : (ref4 = data.effect) == null ? void 0 : ref4.type) === "redirect-external") {
2520
+ if ((data == null ? void 0 : (ref = data.effect) == null ? void 0 : ref.type) === "redirect-internal" || (data == null ? void 0 : (ref8 = data.effect) == null ? void 0 : ref8.type) === "redirect-external") {
2419
2521
  return data.effect;
2420
2522
  }
2421
- if ((data == null ? void 0 : (ref5 = data.effect) == null ? void 0 : ref5.type) === "rewrite") {
2422
- route = (0, _removeTrailingSlash).removeTrailingSlash(data.effect.resolvedHref);
2423
- pathname = data.effect.resolvedHref;
2424
- query = _extends({}, query, data.effect.parsedAs.query);
2425
- resolvedAs = (0, _removeBasePath).removeBasePath((0, _normalizeLocalePath).normalizeLocalePath(data.effect.parsedAs.pathname, _this.locales).pathname);
2426
- // Check again the cache with the new destination.
2427
- existingInfo = _this.components[route];
2428
- if (routeProps.shallow && existingInfo && _this.route === route && !hasMiddleware) {
2429
- // If we have a match with the current route due to rewrite,
2430
- // we can copy the existing information to the rewritten one.
2431
- // Then, we return the information along with the matched route.
2432
- return _extends({}, existingInfo, {
2433
- route
2434
- });
2523
+ if ((data == null ? void 0 : (ref9 = data.effect) == null ? void 0 : ref9.type) === "rewrite") {
2524
+ const resolvedRoute = (0, _removeTrailingSlash).removeTrailingSlash(data.effect.resolvedHref);
2525
+ const pages = yield _this.pageLoader.getPageList();
2526
+ // during query updating the page must match although during
2527
+ // client-transition a redirect that doesn't match a page
2528
+ // can be returned and this should trigger a hard navigation
2529
+ // which is valid for incremental migration
2530
+ if (!isQueryUpdating || pages.includes(resolvedRoute)) {
2531
+ route = resolvedRoute;
2532
+ pathname = data.effect.resolvedHref;
2533
+ query = _extends({}, query, data.effect.parsedAs.query);
2534
+ resolvedAs = (0, _removeBasePath).removeBasePath((0, _normalizeLocalePath).normalizeLocalePath(data.effect.parsedAs.pathname, _this.locales).pathname);
2535
+ // Check again the cache with the new destination.
2536
+ existingInfo = _this.components[route];
2537
+ if (routeProps.shallow && existingInfo && _this.route === route && !hasMiddleware) {
2538
+ // If we have a match with the current route due to rewrite,
2539
+ // we can copy the existing information to the rewritten one.
2540
+ // Then, we return the information along with the matched route.
2541
+ return _extends({}, existingInfo, {
2542
+ route
2543
+ });
2544
+ }
2435
2545
  }
2436
2546
  }
2437
- if (route === "/api" || route.startsWith("/api/")) {
2547
+ if ((0, _isApiRoute).isAPIRoute(route)) {
2438
2548
  handleHardNavigation({
2439
2549
  url: as,
2440
2550
  router: _this
@@ -2448,33 +2558,45 @@ class Router {
2448
2558
  __N_SSP: res.mod.__N_SSP
2449
2559
  })));
2450
2560
  if (false) {}
2561
+ const wasBailedPrefetch = data == null ? void 0 : (ref10 = data.response) == null ? void 0 : ref10.headers.get("x-middleware-skip");
2451
2562
  const shouldFetchData = routeInfo.__N_SSG || routeInfo.__N_SSP;
2563
+ // For non-SSG prefetches that bailed before sending data
2564
+ // we clear the cache to fetch full response
2565
+ if (wasBailedPrefetch && (data == null ? void 0 : data.dataHref)) {
2566
+ delete _this.sdc[data.dataHref];
2567
+ }
2452
2568
  const { props , cacheKey } = yield _this._getData(_async_to_generator(function*() {
2453
2569
  if (shouldFetchData) {
2454
- const { json , cacheKey: _cacheKey } = (data == null ? void 0 : data.json) ? data : yield fetchNextData({
2455
- dataHref: _this.pageLoader.getDataHref({
2456
- href: (0, _formatUrl).formatWithValidation({
2457
- pathname,
2458
- query
2459
- }),
2460
- asPath: resolvedAs,
2461
- locale
2570
+ if ((data == null ? void 0 : data.json) && !wasBailedPrefetch) {
2571
+ return {
2572
+ cacheKey: data.cacheKey,
2573
+ props: data.json
2574
+ };
2575
+ }
2576
+ const dataHref = (data == null ? void 0 : data.dataHref) ? data.dataHref : _this.pageLoader.getDataHref({
2577
+ href: (0, _formatUrl).formatWithValidation({
2578
+ pathname,
2579
+ query
2462
2580
  }),
2581
+ asPath: resolvedAs,
2582
+ locale
2583
+ });
2584
+ const fetched = yield fetchNextData({
2585
+ dataHref,
2463
2586
  isServerRender: _this.isSsr,
2464
2587
  parseJSON: true,
2465
- inflightCache: _this.sdc,
2588
+ inflightCache: wasBailedPrefetch ? {} : _this.sdc,
2466
2589
  persistCache: !isPreview,
2467
2590
  isPrefetch: false,
2468
2591
  unstable_skipClientCache
2469
2592
  });
2470
2593
  return {
2471
- cacheKey: _cacheKey,
2472
- props: json || {}
2594
+ cacheKey: fetched.cacheKey,
2595
+ props: fetched.json || {}
2473
2596
  };
2474
2597
  }
2475
2598
  return {
2476
2599
  headers: {},
2477
- cacheKey: "",
2478
2600
  props: yield _this.getInitialProps(routeInfo.Component, {
2479
2601
  pathname,
2480
2602
  query,
@@ -2488,16 +2610,16 @@ class Router {
2488
2610
  // Only bust the data cache for SSP routes although
2489
2611
  // middleware can skip cache per request with
2490
2612
  // x-middleware-cache: no-cache as well
2491
- if (routeInfo.__N_SSP && fetchNextDataParams.dataHref) {
2613
+ if (routeInfo.__N_SSP && fetchNextDataParams.dataHref && cacheKey) {
2492
2614
  delete _this.sdc[cacheKey];
2493
2615
  }
2494
2616
  // we kick off a HEAD request in the background
2495
2617
  // when a non-prefetch request is made to signal revalidation
2496
- if (!_this.isPreview && routeInfo.__N_SSG && "production" !== "development") {
2618
+ if (!_this.isPreview && routeInfo.__N_SSG && "production" !== "development" && !isQueryUpdating) {
2497
2619
  fetchNextData(Object.assign({}, fetchNextDataParams, {
2498
2620
  isBackground: true,
2499
2621
  persistCache: false,
2500
- inflightCache: backgroundCache
2622
+ inflightCache: _this.sbc
2501
2623
  })).catch(()=>{});
2502
2624
  }
2503
2625
  props.pageProps = Object.assign({}, props.pageProps);
@@ -2574,28 +2696,74 @@ class Router {
2574
2696
  */ prefetch(url, asPath = url, options = {}) {
2575
2697
  var _this = this;
2576
2698
  return _async_to_generator(function*() {
2699
+ // Prefetch is not supported in development mode because it would trigger on-demand-entries
2700
+ if (false) {}
2577
2701
  if (false) {}
2578
2702
  let parsed = (0, _parseRelativeUrl).parseRelativeUrl(url);
2579
2703
  let { pathname , query } = parsed;
2704
+ const originalPathname = pathname;
2580
2705
  if (false) {}
2581
2706
  const pages = yield _this.pageLoader.getPageList();
2582
2707
  let resolvedAs = asPath;
2583
2708
  const locale = typeof options.locale !== "undefined" ? options.locale || undefined : _this.locale;
2709
+ const isMiddlewareMatch = yield matchesMiddleware({
2710
+ asPath: asPath,
2711
+ locale: locale,
2712
+ router: _this
2713
+ });
2584
2714
  if (false) {}
2585
2715
  parsed.pathname = resolveDynamicRoute(parsed.pathname, pages);
2586
2716
  if ((0, _isDynamic).isDynamicRoute(parsed.pathname)) {
2587
2717
  pathname = parsed.pathname;
2588
2718
  parsed.pathname = pathname;
2589
2719
  Object.assign(query, (0, _routeMatcher).getRouteMatcher((0, _routeRegex).getRouteRegex(parsed.pathname))((0, _parsePath).parsePath(asPath).pathname) || {});
2720
+ if (!isMiddlewareMatch) {
2721
+ url = (0, _formatUrl).formatWithValidation(parsed);
2722
+ }
2723
+ }
2724
+ const data = false ? 0 : yield withMiddlewareEffects({
2725
+ fetchData: ()=>fetchNextData({
2726
+ dataHref: _this.pageLoader.getDataHref({
2727
+ href: (0, _formatUrl).formatWithValidation({
2728
+ pathname: originalPathname,
2729
+ query
2730
+ }),
2731
+ skipInterpolation: true,
2732
+ asPath: resolvedAs,
2733
+ locale
2734
+ }),
2735
+ hasMiddleware: true,
2736
+ isServerRender: _this.isSsr,
2737
+ parseJSON: true,
2738
+ inflightCache: _this.sdc,
2739
+ persistCache: !_this.isPreview,
2740
+ isPrefetch: true
2741
+ }),
2742
+ asPath: asPath,
2743
+ locale: locale,
2744
+ router: _this
2745
+ });
2746
+ /**
2747
+ * If there was a rewrite we apply the effects of the rewrite on the
2748
+ * current parameters for the prefetch.
2749
+ */ if ((data == null ? void 0 : data.effect.type) === "rewrite") {
2750
+ parsed.pathname = data.effect.resolvedHref;
2751
+ pathname = data.effect.resolvedHref;
2752
+ query = _extends({}, query, data.effect.parsedAs.query);
2753
+ resolvedAs = data.effect.parsedAs.pathname;
2590
2754
  url = (0, _formatUrl).formatWithValidation(parsed);
2591
2755
  }
2592
- // Prefetch is not supported in development mode because it would trigger on-demand-entries
2593
- if (false) {}
2756
+ /**
2757
+ * If there is a redirect to an external destination then we don't have
2758
+ * to prefetch content as it will be unused.
2759
+ */ if ((data == null ? void 0 : data.effect.type) === "redirect-external") {
2760
+ return;
2761
+ }
2594
2762
  const route = (0, _removeTrailingSlash).removeTrailingSlash(pathname);
2595
2763
  yield Promise.all([
2596
2764
  _this.pageLoader._isSsg(route).then((isSsg)=>{
2597
2765
  return isSsg ? fetchNextData({
2598
- dataHref: _this.pageLoader.getDataHref({
2766
+ dataHref: (data == null ? void 0 : data.json) ? data == null ? void 0 : data.dataHref : _this.pageLoader.getDataHref({
2599
2767
  href: url,
2600
2768
  asPath: resolvedAs,
2601
2769
  locale: locale
@@ -2608,7 +2776,7 @@ class Router {
2608
2776
  unstable_skipClientCache: options.unstable_skipClientCache || options.priority && !!true
2609
2777
  }).then(()=>false) : false;
2610
2778
  }),
2611
- _this.pageLoader[options.priority ? "loadPage" : "prefetch"](route),
2779
+ _this.pageLoader[options.priority ? "loadPage" : "prefetch"](route)
2612
2780
  ]);
2613
2781
  })();
2614
2782
  }
@@ -2693,8 +2861,10 @@ class Router {
2693
2861
  return this.state.isPreview;
2694
2862
  }
2695
2863
  constructor(pathname1, query1, as1, { initialProps , pageLoader , App , wrapApp , Component , err , subscription , isFallback , locale , locales , defaultLocale , domainLocales , isPreview }){
2696
- // Server Data Cache
2864
+ // Server Data Cache (full data requests)
2697
2865
  this.sdc = {};
2866
+ // Server Background Cache (HEAD requests)
2867
+ this.sbc = {};
2698
2868
  this.isFirstPopStateEvent = true;
2699
2869
  this._key = createKey();
2700
2870
  this.onPopState = (e)=>{
@@ -2734,10 +2904,10 @@ class Router {
2734
2904
  const { url , as , options , key } = state;
2735
2905
  if (false) {}
2736
2906
  this._key = key;
2737
- const { pathname: pathname1 } = (0, _parseRelativeUrl).parseRelativeUrl(url);
2907
+ const { pathname } = (0, _parseRelativeUrl).parseRelativeUrl(url);
2738
2908
  // Make sure we don't re-render on initial load,
2739
2909
  // can be caused by navigating back from an external site
2740
- if (this.isSsr && as === (0, _addBasePath).addBasePath(this.asPath) && pathname1 === (0, _addBasePath).addBasePath(this.pathname)) {
2910
+ if (this.isSsr && as === (0, _addBasePath).addBasePath(this.asPath) && pathname === (0, _addBasePath).addBasePath(this.pathname)) {
2741
2911
  return;
2742
2912
  }
2743
2913
  // If the downstream application returns falsy, return.
@@ -2807,12 +2977,29 @@ Router.events = (0, _mitt).default();
2807
2977
  exports["default"] = Router; //# sourceMappingURL=router.js.map
2808
2978
 
2809
2979
 
2980
+ /***/ }),
2981
+
2982
+ /***/ 79423:
2983
+ /***/ ((__unused_webpack_module, exports) => {
2984
+
2985
+ "use strict";
2986
+
2987
+ Object.defineProperty(exports, "__esModule", ({
2988
+ value: true
2989
+ }));
2990
+ exports.isAPIRoute = isAPIRoute;
2991
+ function isAPIRoute(value) {
2992
+ return value === "/api" || Boolean(value == null ? void 0 : value.startsWith("/api/"));
2993
+ }
2994
+
2995
+ //# sourceMappingURL=is-api-route.js.map
2996
+
2810
2997
  /***/ }),
2811
2998
 
2812
2999
  /***/ 41664:
2813
3000
  /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2814
3001
 
2815
- module.exports = __webpack_require__(48418)
3002
+ module.exports = __webpack_require__(31551)
2816
3003
 
2817
3004
 
2818
3005
  /***/ })