New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revert "fix the dynamic routing of middleware" #35932
Merged
kodiakhq
merged 2 commits into
vercel:canary
from
nkzawa:revert-32601-fix-dynamic-middleware-routing.patch
Apr 6, 2022
Merged
Revert "fix the dynamic routing of middleware" #35932
kodiakhq
merged 2 commits into
vercel:canary
from
nkzawa:revert-32601-fix-dynamic-middleware-routing.patch
Apr 6, 2022
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This reverts commit 53d1b00.
nkzawa
requested review from
timneutkens,
ijjk,
shuding,
padmaia and
huozhi
as code owners
April 6, 2022 08:02
javivelasco
approved these changes
Apr 6, 2022
This comment has been minimized.
This comment has been minimized.
ijjk
approved these changes
Apr 6, 2022
Stats from current PRDefault Build (Increase detected
|
vercel/next.js canary | nkzawa/next.js revert-32601-fix-dynamic-middleware-routing.patch | Change | |
---|---|---|---|
buildDuration | 18.4s | 18.4s | |
buildDurationCached | 7.1s | 7.1s | |
nodeModulesSize | 477 MB | 477 MB | -9.66 kB |
Page Load Tests Overall increase ✓
vercel/next.js canary | nkzawa/next.js revert-32601-fix-dynamic-middleware-routing.patch | Change | |
---|---|---|---|
/ failed reqs | 0 | 0 | ✓ |
/ total time (seconds) | 3.693 | 3.687 | -0.01 |
/ avg req/sec | 677.04 | 678.06 | +1.02 |
/error-in-render failed reqs | 0 | 0 | ✓ |
/error-in-render total time (seconds) | 1.673 | 1.605 | -0.07 |
/error-in-render avg req/sec | 1494.41 | 1557.69 | +63.28 |
Client Bundles (main, webpack) Overall decrease ✓
vercel/next.js canary | nkzawa/next.js revert-32601-fix-dynamic-middleware-routing.patch | Change | |
---|---|---|---|
925.HASH.js gzip | 179 B | 179 B | ✓ |
framework-HASH.js gzip | 42 kB | 42 kB | ✓ |
main-HASH.js gzip | 28.5 kB | 28 kB | -487 B |
webpack-HASH.js gzip | 1.44 kB | 1.44 kB | ✓ |
Overall change | 72.1 kB | 71.7 kB | -487 B |
Legacy Client Bundles (polyfills)
vercel/next.js canary | nkzawa/next.js revert-32601-fix-dynamic-middleware-routing.patch | Change | |
---|---|---|---|
polyfills-HASH.js gzip | 31 kB | 31 kB | ✓ |
Overall change | 31 kB | 31 kB | ✓ |
Client Pages
vercel/next.js canary | nkzawa/next.js revert-32601-fix-dynamic-middleware-routing.patch | Change | |
---|---|---|---|
_app-HASH.js gzip | 1.36 kB | 1.36 kB | ✓ |
_error-HASH.js gzip | 192 B | 192 B | ✓ |
amp-HASH.js gzip | 309 B | 309 B | ✓ |
css-HASH.js gzip | 327 B | 327 B | ✓ |
dynamic-HASH.js gzip | 3.05 kB | 3.05 kB | ✓ |
head-HASH.js gzip | 351 B | 351 B | ✓ |
hooks-HASH.js gzip | 920 B | 920 B | ✓ |
image-HASH.js gzip | 5.64 kB | 5.64 kB | ✓ |
index-HASH.js gzip | 263 B | 263 B | ✓ |
link-HASH.js gzip | 2.32 kB | 2.32 kB | ✓ |
routerDirect..HASH.js gzip | 320 B | 320 B | ✓ |
script-HASH.js gzip | 387 B | 387 B | ✓ |
withRouter-HASH.js gzip | 319 B | 319 B | ✓ |
85e02e95b279..7e3.css gzip | 107 B | 107 B | ✓ |
Overall change | 15.9 kB | 15.9 kB | ✓ |
Client Build Manifests
vercel/next.js canary | nkzawa/next.js revert-32601-fix-dynamic-middleware-routing.patch | Change | |
---|---|---|---|
_buildManifest.js gzip | 459 B | 459 B | ✓ |
Overall change | 459 B | 459 B | ✓ |
Rendered Page Sizes
vercel/next.js canary | nkzawa/next.js revert-32601-fix-dynamic-middleware-routing.patch | Change | |
---|---|---|---|
index.html gzip | 531 B | 531 B | ✓ |
link.html gzip | 545 B | 545 B | ✓ |
withRouter.html gzip | 525 B | 525 B | ✓ |
Overall change | 1.6 kB | 1.6 kB | ✓ |
Diffs
Diff for main-HASH.js
@@ -473,7 +473,7 @@
var _routeAnnouncer = __webpack_require__(8483);
var _router1 = __webpack_require__(880);
var _isError = __webpack_require__(676);
- var _vitals = __webpack_require__(4564);
+ var _vitals = __webpack_require__(7185);
var _refresh = __webpack_require__(2129);
var _imageConfigContext = __webpack_require__(8730);
function asyncGeneratorStep(
@@ -3199,7 +3199,7 @@
/***/
},
- /***/ 4564: /***/ function(
+ /***/ 7185: /***/ function(
__unused_webpack_module,
exports,
__webpack_require__
@@ -4353,8 +4353,8 @@
var _resolveRewrites = _interopRequireDefault1(__webpack_require__(2431));
var _routeMatcher = __webpack_require__(3156);
var _routeRegex = __webpack_require__(4903);
+ var _getMiddlewareRegex = __webpack_require__(3072);
var _formatUrl = __webpack_require__(7795);
- var _routingItems = __webpack_require__(7185);
function _interopRequireDefault1(obj) {
return obj && obj.__esModule
? obj
@@ -6395,16 +6395,8 @@
_runtimeJs.default.mark(function _callee() {
var asPathname,
cleanedAs,
- middlewareList,
- middleware,
- routingItems,
+ fns,
requiresPreflight,
- _iteratorNormalCompletion,
- _didIteratorError,
- _iteratorError,
- _iterator,
- _step,
- item,
preflight,
parsed,
fsPathname,
@@ -6429,116 +6421,58 @@
_ctx.next = 4;
return _this.pageLoader.getMiddlewareList();
case 4:
- middlewareList = _ctx.sent;
- middleware = middlewareList.map(function(param) {
+ fns = _ctx.sent;
+ requiresPreflight = fns.some(function(param) {
var _param = _slicedToArray(param, 2),
- page = _param[0],
- ssr = _param[1];
- return {
- page: page,
- ssr: ssr
- };
+ middleware = _param[0],
+ isSSR = _param[1];
+ return (0, _routeMatcher).getRouteMatcher(
+ (0, _getMiddlewareRegex).getMiddlewareRegex(
+ middleware,
+ !isSSR
+ )
+ )(cleanedAs);
});
- routingItems = (0, _routingItems).getRoutingItems(
- options.pages,
- middleware
- );
- requiresPreflight = false;
- (_iteratorNormalCompletion = true),
- (_didIteratorError = false),
- (_iteratorError = undefined);
- _ctx.prev = 9;
- _iterator = routingItems[Symbol.iterator]();
- case 11:
- if (
- (_iteratorNormalCompletion = (_step = _iterator.next())
- .done)
- ) {
- _ctx.next = 19;
- break;
- }
- item = _step.value;
- if (!item.match(cleanedAs)) {
- _ctx.next = 16;
- break;
- }
- if (item.isMiddleware) {
- requiresPreflight = true;
- }
- return _ctx.abrupt("break", 19);
- case 16:
- _iteratorNormalCompletion = true;
- _ctx.next = 11;
- break;
- case 19:
- _ctx.next = 25;
- break;
- case 21:
- _ctx.prev = 21;
- _ctx.t0 = _ctx["catch"](9);
- _didIteratorError = true;
- _iteratorError = _ctx.t0;
- case 25:
- _ctx.prev = 25;
- _ctx.prev = 26;
- if (
- !_iteratorNormalCompletion &&
- _iterator.return != null
- ) {
- _iterator.return();
- }
- case 28:
- _ctx.prev = 28;
- if (!_didIteratorError) {
- _ctx.next = 31;
- break;
- }
- throw _iteratorError;
- case 31:
- return _ctx.finish(28);
- case 32:
- return _ctx.finish(25);
- case 33:
if (requiresPreflight) {
- _ctx.next = 35;
+ _ctx.next = 8;
break;
}
return _ctx.abrupt("return", {
type: "next"
});
- case 35:
- _ctx.prev = 36;
- _ctx.next = 39;
+ case 8:
+ _ctx.prev = 9;
+ _ctx.next = 12;
return _this._getPreflightData({
preflightHref: options.as,
shouldCache: options.cache,
isPreview: options.isPreview
});
- case 39:
+ case 12:
preflight = _ctx.sent;
- _ctx.next = 45;
+ _ctx.next = 18;
break;
- case 42:
- _ctx.prev = 42;
- _ctx.t1 = _ctx["catch"](36);
+ case 15:
+ _ctx.prev = 15;
+ _ctx.t0 = _ctx["catch"](9);
return _ctx.abrupt("return", {
type: "redirect",
destination: options.as
});
- case 45:
+ case 18:
if (!preflight.rewrite) {
- _ctx.next = 54;
+ _ctx.next = 27;
break;
}
if (preflight.rewrite.startsWith("/")) {
- _ctx.next = 48;
+ _ctx.next = 21;
break;
}
return _ctx.abrupt("return", {
type: "redirect",
destination: options.as
});
- case 48:
+ case 21:
parsed = (0, _parseRelativeUrl).parseRelativeUrl(
(0, _normalizeLocalePath).normalizeLocalePath(
hasBasePath(preflight.rewrite)
@@ -6573,13 +6507,13 @@
matchedPage: matchedPage,
resolvedHref: resolvedHref
});
- case 54:
+ case 27:
if (!preflight.redirect) {
- _ctx.next = 60;
+ _ctx.next = 33;
break;
}
if (!preflight.redirect.startsWith("/")) {
- _ctx.next = 59;
+ _ctx.next = 32;
break;
}
cleanRedirect = (0,
@@ -6603,35 +6537,31 @@
newUrl: newUrl,
newAs: newAs
});
- case 59:
+ case 32:
return _ctx.abrupt("return", {
type: "redirect",
destination: preflight.redirect
});
- case 60:
+ case 33:
if (!(preflight.refresh && !preflight.ssr)) {
- _ctx.next = 62;
+ _ctx.next = 35;
break;
}
return _ctx.abrupt("return", {
type: "refresh"
});
- case 62:
+ case 35:
return _ctx.abrupt("return", {
type: "next"
});
- case 63:
+ case 36:
case "end":
return _ctx.stop();
}
},
_callee,
null,
- [
- [9, 21, 25, 33],
- [26, , 28, 32],
- [36, 42]
- ]
+ [[9, 15]]
);
})
)();
@@ -6903,17 +6833,11 @@
});
exports.getMiddlewareRegex = getMiddlewareRegex;
var _routeRegex = __webpack_require__(4903);
- // Identify ^/[param]/ in route string
- var FIRST_SEGMENT_DYNAMIC = /^\/\[[^/]+?\](?=\/|$)/;
- var NOT_API_ROUTE = "(?!/api(?:/|$))";
function getMiddlewareRegex(normalizedRoute) {
var catchAll =
arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
var result = (0, _routeRegex).getParametrizedRoute(normalizedRoute);
- var notApiRegex = FIRST_SEGMENT_DYNAMIC.test(normalizedRoute)
- ? NOT_API_ROUTE
- : "";
- var catchAllRegex = catchAll ? "(?!_next($|/)).*" : "";
+ var catchAllRegex = catchAll ? "(?!_next).*" : "";
var catchAllGroupedRegex = catchAll ? "(?:(/.*)?)" : "";
if ("routeKeys" in result) {
if (result.parameterizedRoute === "/") {
@@ -6927,12 +6851,10 @@
return {
groups: result.groups,
namedRegex: "^"
- .concat(notApiRegex)
.concat(result.namedParameterizedRoute)
.concat(catchAllGroupedRegex, "$"),
re: new RegExp(
"^"
- .concat(notApiRegex)
.concat(result.parameterizedRoute)
.concat(catchAllGroupedRegex, "$")
),
@@ -6949,7 +6871,6 @@
groups: {},
re: new RegExp(
"^"
- .concat(notApiRegex)
.concat(result.parameterizedRoute)
.concat(catchAllGroupedRegex, "$")
)
@@ -6987,18 +6908,6 @@
return _routeRegex.getRouteRegex;
}
});
- Object.defineProperty(exports, "getRoutingItems", {
- enumerable: true,
- get: function get() {
- return _routingItems.getRoutingItems;
- }
- });
- Object.defineProperty(exports, "RoutingItem", {
- enumerable: true,
- get: function get() {
- return _routingItems.RoutingItem;
- }
- });
Object.defineProperty(exports, "getSortedRoutes", {
enumerable: true,
get: function get() {
@@ -7014,7 +6923,6 @@
var _getMiddlewareRegex = __webpack_require__(3072);
var _routeMatcher = __webpack_require__(3156);
var _routeRegex = __webpack_require__(4903);
- var _routingItems = __webpack_require__(7185);
var _sortedRoutes = __webpack_require__(566);
var _isDynamic = __webpack_require__(6238); //# sourceMappingURL=index.js.map
@@ -7346,101 +7254,6 @@
/***/
},
- /***/ 7185: /***/ function(
- __unused_webpack_module,
- exports,
- __webpack_require__
- ) {
- "use strict";
-
- function _arrayLikeToArray(arr, len) {
- if (len == null || len > arr.length) len = arr.length;
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
- return arr2;
- }
- function _arrayWithoutHoles(arr) {
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
- }
- function _iterableToArray(iter) {
- if (
- (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null) ||
- iter["@@iterator"] != null
- )
- return Array.from(iter);
- }
- function _nonIterableSpread() {
- throw new TypeError(
- "Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."
- );
- }
- function _toConsumableArray(arr) {
- return (
- _arrayWithoutHoles(arr) ||
- _iterableToArray(arr) ||
- _unsupportedIterableToArray(arr) ||
- _nonIterableSpread()
- );
- }
- function _unsupportedIterableToArray(o, minLen) {
- if (!o) return;
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
- var n = Object.prototype.toString.call(o).slice(8, -1);
- if (n === "Object" && o.constructor) n = o.constructor.name;
- if (n === "Map" || n === "Set") return Array.from(n);
- if (
- n === "Arguments" ||
- /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)
- )
- return _arrayLikeToArray(o, minLen);
- }
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.getRoutingItems = getRoutingItems;
- var _getMiddlewareRegex = __webpack_require__(3072);
- var _routeMatcher = __webpack_require__(3156);
- var _routeRegex = __webpack_require__(4903);
- var _sortedRoutes = __webpack_require__(566);
- var MIDDLEWARE_SUFFIX = "/_middleware";
- function getRoutingItems(pages, middleware) {
- // append the suffix so that `getSortedRoutes()` can handle middleware properly
- var middlewarePages = middleware.map(function(m) {
- return "".concat(m.page).concat(MIDDLEWARE_SUFFIX);
- });
- var middlewareMap = new Map(
- middleware.map(function(m) {
- return [m.page, m];
- })
- );
- var sortedRoutes = (0, _sortedRoutes).getSortedRoutes(
- _toConsumableArray(pages).concat(_toConsumableArray(middlewarePages))
- );
- return sortedRoutes.map(function(page) {
- if (page.endsWith(MIDDLEWARE_SUFFIX)) {
- var p = page.slice(0, -MIDDLEWARE_SUFFIX.length) || "/";
- var ssr = middlewareMap.get(p).ssr;
- return {
- match: (0, _routeMatcher).getRouteMatcher(
- (0, _getMiddlewareRegex).getMiddlewareRegex(p, !ssr)
- ),
- page: p,
- ssr: ssr,
- isMiddleware: true
- };
- } else {
- return {
- match: (0, _routeMatcher).getRouteMatcher(
- (0, _routeRegex).getRouteRegex(page)
- ),
- page: page
- };
- }
- });
- } //# sourceMappingURL=routing-items.js.map
-
- /***/
- },
-
/***/ 566: /***/ function(__unused_webpack_module, exports) {
"use strict";
@@ -7515,7 +7328,6 @@
this.slugName = null;
this.restSlugName = null;
this.optionalRestSlugName = null;
- this.isMiddleware = false;
}
_createClass(UrlNode, [
{
@@ -7550,9 +7362,6 @@
if (this.optionalRestSlugName !== null) {
childrenPaths.splice(childrenPaths.indexOf("[[...]]"), 1);
}
- if (this.isMiddleware) {
- childrenPaths.splice(childrenPaths.indexOf("_middleware"), 1);
- }
var routes = childrenPaths
.map(function(c) {
return _this.children
@@ -7589,21 +7398,10 @@
}
routes.unshift(r);
}
- if (this.isMiddleware) {
+ if (this.restSlugName !== null) {
var _routes1;
- (_routes1 = routes).unshift.apply(
+ (_routes1 = routes).push.apply(
_routes1,
- _toConsumableArray(
- this.children
- .get("_middleware")
- ._smoosh("".concat(prefix, "_middleware/"))
- )
- );
- }
- if (this.restSlugName !== null) {
- var _routes2;
- (_routes2 = routes).push.apply(
- _routes2,
_toConsumableArray(
this.children
.get("[...]")
@@ -7616,9 +7414,9 @@
);
}
if (this.optionalRestSlugName !== null) {
- var _routes3;
- (_routes3 = routes).push.apply(
- _routes3,
+ var _routes2;
+ (_routes2 = routes).push.apply(
+ _routes2,
_toConsumableArray(
this.children
.get("[[...]]")
@@ -7759,11 +7557,6 @@
// nextSegment is overwritten to [] so that it can later be sorted specifically
nextSegment = "[]";
}
- } else if (
- nextSegment === "_middleware" &&
- urlPaths.length === 1
- ) {
- this.isMiddleware = true;
}
// If this UrlNode doesn't have the nextSegment yet we create a new child UrlNode
if (!this.children.has(nextSegment)) {
Diff for index.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-46a1f19b7b7698c4.js"
+ src="/_next/static/chunks/main-4f97673b68e1ad2a.js"
defer=""
></script>
<script
Diff for link.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-46a1f19b7b7698c4.js"
+ src="/_next/static/chunks/main-4f97673b68e1ad2a.js"
defer=""
></script>
<script
Diff for withRouter.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-46a1f19b7b7698c4.js"
+ src="/_next/static/chunks/main-4f97673b68e1ad2a.js"
defer=""
></script>
<script
Default Build with SWC (Increase detected ⚠️ )
General Overall decrease ✓
vercel/next.js canary | nkzawa/next.js revert-32601-fix-dynamic-middleware-routing.patch | Change | |
---|---|---|---|
buildDuration | 21.3s | 21.1s | -247ms |
buildDurationCached | 7.2s | 7.2s | |
nodeModulesSize | 477 MB | 477 MB | -9.66 kB |
Page Load Tests Overall increase ✓
vercel/next.js canary | nkzawa/next.js revert-32601-fix-dynamic-middleware-routing.patch | Change | |
---|---|---|---|
/ failed reqs | 0 | 0 | ✓ |
/ total time (seconds) | 3.736 | 3.766 | |
/ avg req/sec | 669.1 | 663.91 | |
/error-in-render failed reqs | 0 | 0 | ✓ |
/error-in-render total time (seconds) | 1.71 | 1.642 | -0.07 |
/error-in-render avg req/sec | 1462.28 | 1522.67 | +60.39 |
Client Bundles (main, webpack) Overall decrease ✓
vercel/next.js canary | nkzawa/next.js revert-32601-fix-dynamic-middleware-routing.patch | Change | |
---|---|---|---|
925.HASH.js gzip | 178 B | 178 B | ✓ |
framework-HASH.js gzip | 42.3 kB | 42.3 kB | ✓ |
main-HASH.js gzip | 28.8 kB | 28.3 kB | -536 B |
webpack-HASH.js gzip | 1.45 kB | 1.45 kB | ✓ |
Overall change | 72.7 kB | 72.2 kB | -536 B |
Legacy Client Bundles (polyfills)
vercel/next.js canary | nkzawa/next.js revert-32601-fix-dynamic-middleware-routing.patch | Change | |
---|---|---|---|
polyfills-HASH.js gzip | 31 kB | 31 kB | ✓ |
Overall change | 31 kB | 31 kB | ✓ |
Client Pages
vercel/next.js canary | nkzawa/next.js revert-32601-fix-dynamic-middleware-routing.patch | Change | |
---|---|---|---|
_app-HASH.js gzip | 1.35 kB | 1.35 kB | ✓ |
_error-HASH.js gzip | 179 B | 179 B | ✓ |
amp-HASH.js gzip | 313 B | 313 B | ✓ |
css-HASH.js gzip | 325 B | 325 B | ✓ |
dynamic-HASH.js gzip | 3.03 kB | 3.03 kB | ✓ |
head-HASH.js gzip | 351 B | 351 B | ✓ |
hooks-HASH.js gzip | 921 B | 921 B | ✓ |
image-HASH.js gzip | 5.7 kB | 5.7 kB | ✓ |
index-HASH.js gzip | 261 B | 261 B | ✓ |
link-HASH.js gzip | 2.38 kB | 2.38 kB | ✓ |
routerDirect..HASH.js gzip | 322 B | 322 B | ✓ |
script-HASH.js gzip | 388 B | 388 B | ✓ |
withRouter-HASH.js gzip | 317 B | 317 B | ✓ |
85e02e95b279..7e3.css gzip | 107 B | 107 B | ✓ |
Overall change | 15.9 kB | 15.9 kB | ✓ |
Client Build Manifests
vercel/next.js canary | nkzawa/next.js revert-32601-fix-dynamic-middleware-routing.patch | Change | |
---|---|---|---|
_buildManifest.js gzip | 459 B | 459 B | ✓ |
Overall change | 459 B | 459 B | ✓ |
Rendered Page Sizes
vercel/next.js canary | nkzawa/next.js revert-32601-fix-dynamic-middleware-routing.patch | Change | |
---|---|---|---|
index.html gzip | 531 B | 531 B | ✓ |
link.html gzip | 544 B | 544 B | ✓ |
withRouter.html gzip | 526 B | 526 B | ✓ |
Overall change | 1.6 kB | 1.6 kB | ✓ |
Diffs
Diff for main-HASH.js
@@ -473,7 +473,7 @@
var _routeAnnouncer = __webpack_require__(8483);
var _router1 = __webpack_require__(880);
var _isError = __webpack_require__(676);
- var _vitals = __webpack_require__(4564);
+ var _vitals = __webpack_require__(7185);
var _refresh = __webpack_require__(2129);
var _imageConfigContext = __webpack_require__(8730);
function asyncGeneratorStep(
@@ -3199,7 +3199,7 @@
/***/
},
- /***/ 4564: /***/ function(
+ /***/ 7185: /***/ function(
__unused_webpack_module,
exports,
__webpack_require__
@@ -4353,8 +4353,8 @@
var _resolveRewrites = _interopRequireDefault1(__webpack_require__(2431));
var _routeMatcher = __webpack_require__(3156);
var _routeRegex = __webpack_require__(4903);
+ var _getMiddlewareRegex = __webpack_require__(3072);
var _formatUrl = __webpack_require__(7795);
- var _routingItems = __webpack_require__(7185);
function _interopRequireDefault1(obj) {
return obj && obj.__esModule
? obj
@@ -6395,16 +6395,8 @@
_runtimeJs.default.mark(function _callee() {
var asPathname,
cleanedAs,
- middlewareList,
- middleware,
- routingItems,
+ fns,
requiresPreflight,
- _iteratorNormalCompletion,
- _didIteratorError,
- _iteratorError,
- _iterator,
- _step,
- item,
preflight,
parsed,
fsPathname,
@@ -6429,116 +6421,58 @@
_ctx.next = 4;
return _this.pageLoader.getMiddlewareList();
case 4:
- middlewareList = _ctx.sent;
- middleware = middlewareList.map(function(param) {
+ fns = _ctx.sent;
+ requiresPreflight = fns.some(function(param) {
var _param = _slicedToArray(param, 2),
- page = _param[0],
- ssr = _param[1];
- return {
- page: page,
- ssr: ssr
- };
+ middleware = _param[0],
+ isSSR = _param[1];
+ return (0, _routeMatcher).getRouteMatcher(
+ (0, _getMiddlewareRegex).getMiddlewareRegex(
+ middleware,
+ !isSSR
+ )
+ )(cleanedAs);
});
- routingItems = (0, _routingItems).getRoutingItems(
- options.pages,
- middleware
- );
- requiresPreflight = false;
- (_iteratorNormalCompletion = true),
- (_didIteratorError = false),
- (_iteratorError = undefined);
- _ctx.prev = 9;
- _iterator = routingItems[Symbol.iterator]();
- case 11:
- if (
- (_iteratorNormalCompletion = (_step = _iterator.next())
- .done)
- ) {
- _ctx.next = 19;
- break;
- }
- item = _step.value;
- if (!item.match(cleanedAs)) {
- _ctx.next = 16;
- break;
- }
- if (item.isMiddleware) {
- requiresPreflight = true;
- }
- return _ctx.abrupt("break", 19);
- case 16:
- _iteratorNormalCompletion = true;
- _ctx.next = 11;
- break;
- case 19:
- _ctx.next = 25;
- break;
- case 21:
- _ctx.prev = 21;
- _ctx.t0 = _ctx["catch"](9);
- _didIteratorError = true;
- _iteratorError = _ctx.t0;
- case 25:
- _ctx.prev = 25;
- _ctx.prev = 26;
- if (
- !_iteratorNormalCompletion &&
- _iterator.return != null
- ) {
- _iterator.return();
- }
- case 28:
- _ctx.prev = 28;
- if (!_didIteratorError) {
- _ctx.next = 31;
- break;
- }
- throw _iteratorError;
- case 31:
- return _ctx.finish(28);
- case 32:
- return _ctx.finish(25);
- case 33:
if (requiresPreflight) {
- _ctx.next = 35;
+ _ctx.next = 8;
break;
}
return _ctx.abrupt("return", {
type: "next"
});
- case 35:
- _ctx.prev = 36;
- _ctx.next = 39;
+ case 8:
+ _ctx.prev = 9;
+ _ctx.next = 12;
return _this._getPreflightData({
preflightHref: options.as,
shouldCache: options.cache,
isPreview: options.isPreview
});
- case 39:
+ case 12:
preflight = _ctx.sent;
- _ctx.next = 45;
+ _ctx.next = 18;
break;
- case 42:
- _ctx.prev = 42;
- _ctx.t1 = _ctx["catch"](36);
+ case 15:
+ _ctx.prev = 15;
+ _ctx.t0 = _ctx["catch"](9);
return _ctx.abrupt("return", {
type: "redirect",
destination: options.as
});
- case 45:
+ case 18:
if (!preflight.rewrite) {
- _ctx.next = 54;
+ _ctx.next = 27;
break;
}
if (preflight.rewrite.startsWith("/")) {
- _ctx.next = 48;
+ _ctx.next = 21;
break;
}
return _ctx.abrupt("return", {
type: "redirect",
destination: options.as
});
- case 48:
+ case 21:
parsed = (0, _parseRelativeUrl).parseRelativeUrl(
(0, _normalizeLocalePath).normalizeLocalePath(
hasBasePath(preflight.rewrite)
@@ -6573,13 +6507,13 @@
matchedPage: matchedPage,
resolvedHref: resolvedHref
});
- case 54:
+ case 27:
if (!preflight.redirect) {
- _ctx.next = 60;
+ _ctx.next = 33;
break;
}
if (!preflight.redirect.startsWith("/")) {
- _ctx.next = 59;
+ _ctx.next = 32;
break;
}
cleanRedirect = (0,
@@ -6603,35 +6537,31 @@
newUrl: newUrl,
newAs: newAs
});
- case 59:
+ case 32:
return _ctx.abrupt("return", {
type: "redirect",
destination: preflight.redirect
});
- case 60:
+ case 33:
if (!(preflight.refresh && !preflight.ssr)) {
- _ctx.next = 62;
+ _ctx.next = 35;
break;
}
return _ctx.abrupt("return", {
type: "refresh"
});
- case 62:
+ case 35:
return _ctx.abrupt("return", {
type: "next"
});
- case 63:
+ case 36:
case "end":
return _ctx.stop();
}
},
_callee,
null,
- [
- [9, 21, 25, 33],
- [26, , 28, 32],
- [36, 42]
- ]
+ [[9, 15]]
);
})
)();
@@ -6903,17 +6833,11 @@
});
exports.getMiddlewareRegex = getMiddlewareRegex;
var _routeRegex = __webpack_require__(4903);
- // Identify ^/[param]/ in route string
- var FIRST_SEGMENT_DYNAMIC = /^\/\[[^/]+?\](?=\/|$)/;
- var NOT_API_ROUTE = "(?!/api(?:/|$))";
function getMiddlewareRegex(normalizedRoute) {
var catchAll =
arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
var result = (0, _routeRegex).getParametrizedRoute(normalizedRoute);
- var notApiRegex = FIRST_SEGMENT_DYNAMIC.test(normalizedRoute)
- ? NOT_API_ROUTE
- : "";
- var catchAllRegex = catchAll ? "(?!_next($|/)).*" : "";
+ var catchAllRegex = catchAll ? "(?!_next).*" : "";
var catchAllGroupedRegex = catchAll ? "(?:(/.*)?)" : "";
if ("routeKeys" in result) {
if (result.parameterizedRoute === "/") {
@@ -6927,12 +6851,10 @@
return {
groups: result.groups,
namedRegex: "^"
- .concat(notApiRegex)
.concat(result.namedParameterizedRoute)
.concat(catchAllGroupedRegex, "$"),
re: new RegExp(
"^"
- .concat(notApiRegex)
.concat(result.parameterizedRoute)
.concat(catchAllGroupedRegex, "$")
),
@@ -6949,7 +6871,6 @@
groups: {},
re: new RegExp(
"^"
- .concat(notApiRegex)
.concat(result.parameterizedRoute)
.concat(catchAllGroupedRegex, "$")
)
@@ -6987,18 +6908,6 @@
return _routeRegex.getRouteRegex;
}
});
- Object.defineProperty(exports, "getRoutingItems", {
- enumerable: true,
- get: function get() {
- return _routingItems.getRoutingItems;
- }
- });
- Object.defineProperty(exports, "RoutingItem", {
- enumerable: true,
- get: function get() {
- return _routingItems.RoutingItem;
- }
- });
Object.defineProperty(exports, "getSortedRoutes", {
enumerable: true,
get: function get() {
@@ -7014,7 +6923,6 @@
var _getMiddlewareRegex = __webpack_require__(3072);
var _routeMatcher = __webpack_require__(3156);
var _routeRegex = __webpack_require__(4903);
- var _routingItems = __webpack_require__(7185);
var _sortedRoutes = __webpack_require__(566);
var _isDynamic = __webpack_require__(6238); //# sourceMappingURL=index.js.map
@@ -7346,101 +7254,6 @@
/***/
},
- /***/ 7185: /***/ function(
- __unused_webpack_module,
- exports,
- __webpack_require__
- ) {
- "use strict";
-
- function _arrayLikeToArray(arr, len) {
- if (len == null || len > arr.length) len = arr.length;
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
- return arr2;
- }
- function _arrayWithoutHoles(arr) {
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
- }
- function _iterableToArray(iter) {
- if (
- (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null) ||
- iter["@@iterator"] != null
- )
- return Array.from(iter);
- }
- function _nonIterableSpread() {
- throw new TypeError(
- "Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."
- );
- }
- function _toConsumableArray(arr) {
- return (
- _arrayWithoutHoles(arr) ||
- _iterableToArray(arr) ||
- _unsupportedIterableToArray(arr) ||
- _nonIterableSpread()
- );
- }
- function _unsupportedIterableToArray(o, minLen) {
- if (!o) return;
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
- var n = Object.prototype.toString.call(o).slice(8, -1);
- if (n === "Object" && o.constructor) n = o.constructor.name;
- if (n === "Map" || n === "Set") return Array.from(n);
- if (
- n === "Arguments" ||
- /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)
- )
- return _arrayLikeToArray(o, minLen);
- }
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.getRoutingItems = getRoutingItems;
- var _getMiddlewareRegex = __webpack_require__(3072);
- var _routeMatcher = __webpack_require__(3156);
- var _routeRegex = __webpack_require__(4903);
- var _sortedRoutes = __webpack_require__(566);
- var MIDDLEWARE_SUFFIX = "/_middleware";
- function getRoutingItems(pages, middleware) {
- // append the suffix so that `getSortedRoutes()` can handle middleware properly
- var middlewarePages = middleware.map(function(m) {
- return "".concat(m.page).concat(MIDDLEWARE_SUFFIX);
- });
- var middlewareMap = new Map(
- middleware.map(function(m) {
- return [m.page, m];
- })
- );
- var sortedRoutes = (0, _sortedRoutes).getSortedRoutes(
- _toConsumableArray(pages).concat(_toConsumableArray(middlewarePages))
- );
- return sortedRoutes.map(function(page) {
- if (page.endsWith(MIDDLEWARE_SUFFIX)) {
- var p = page.slice(0, -MIDDLEWARE_SUFFIX.length) || "/";
- var ssr = middlewareMap.get(p).ssr;
- return {
- match: (0, _routeMatcher).getRouteMatcher(
- (0, _getMiddlewareRegex).getMiddlewareRegex(p, !ssr)
- ),
- page: p,
- ssr: ssr,
- isMiddleware: true
- };
- } else {
- return {
- match: (0, _routeMatcher).getRouteMatcher(
- (0, _routeRegex).getRouteRegex(page)
- ),
- page: page
- };
- }
- });
- } //# sourceMappingURL=routing-items.js.map
-
- /***/
- },
-
/***/ 566: /***/ function(__unused_webpack_module, exports) {
"use strict";
@@ -7515,7 +7328,6 @@
this.slugName = null;
this.restSlugName = null;
this.optionalRestSlugName = null;
- this.isMiddleware = false;
}
_createClass(UrlNode, [
{
@@ -7550,9 +7362,6 @@
if (this.optionalRestSlugName !== null) {
childrenPaths.splice(childrenPaths.indexOf("[[...]]"), 1);
}
- if (this.isMiddleware) {
- childrenPaths.splice(childrenPaths.indexOf("_middleware"), 1);
- }
var routes = childrenPaths
.map(function(c) {
return _this.children
@@ -7589,21 +7398,10 @@
}
routes.unshift(r);
}
- if (this.isMiddleware) {
+ if (this.restSlugName !== null) {
var _routes1;
- (_routes1 = routes).unshift.apply(
+ (_routes1 = routes).push.apply(
_routes1,
- _toConsumableArray(
- this.children
- .get("_middleware")
- ._smoosh("".concat(prefix, "_middleware/"))
- )
- );
- }
- if (this.restSlugName !== null) {
- var _routes2;
- (_routes2 = routes).push.apply(
- _routes2,
_toConsumableArray(
this.children
.get("[...]")
@@ -7616,9 +7414,9 @@
);
}
if (this.optionalRestSlugName !== null) {
- var _routes3;
- (_routes3 = routes).push.apply(
- _routes3,
+ var _routes2;
+ (_routes2 = routes).push.apply(
+ _routes2,
_toConsumableArray(
this.children
.get("[[...]]")
@@ -7759,11 +7557,6 @@
// nextSegment is overwritten to [] so that it can later be sorted specifically
nextSegment = "[]";
}
- } else if (
- nextSegment === "_middleware" &&
- urlPaths.length === 1
- ) {
- this.isMiddleware = true;
}
// If this UrlNode doesn't have the nextSegment yet we create a new child UrlNode
if (!this.children.has(nextSegment)) {
Diff for index.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-46a1f19b7b7698c4.js"
+ src="/_next/static/chunks/main-4f97673b68e1ad2a.js"
defer=""
></script>
<script
Diff for link.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-46a1f19b7b7698c4.js"
+ src="/_next/static/chunks/main-4f97673b68e1ad2a.js"
defer=""
></script>
<script
Diff for withRouter.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-46a1f19b7b7698c4.js"
+ src="/_next/static/chunks/main-4f97673b68e1ad2a.js"
defer=""
></script>
<script
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reverts #32601