Skip to content
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

Ensure rewrites work with manual href/as correctly #25112

Merged
merged 8 commits into from
May 14, 2021

Conversation

ijjk
Copy link
Member

@ijjk ijjk commented May 13, 2021

This ensures rewrites don't override manually provided href/as by only applying the automatic resolve handling when the href is the same as the as value provided

Bug

  • Related issues linked using fixes #number
  • Integration tests added

@ijjk

This comment has been minimized.

@ijjk

This comment has been minimized.

@ijjk

This comment has been minimized.

@ijjk

This comment has been minimized.

@ijjk

This comment has been minimized.

@ijjk

This comment has been minimized.

@ijjk

This comment has been minimized.

@ijjk
Copy link
Member Author

ijjk commented May 13, 2021

Stats from current PR

Default Server Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary ijjk/next.js fix/rewrites-manual-href-as Change
buildDuration 11.1s 11.3s ⚠️ +133ms
buildDurationCached 3.4s 3.1s -297ms
nodeModulesSize 46.6 MB 46.6 MB ⚠️ +260 B
Page Load Tests Overall increase ✓
vercel/next.js canary ijjk/next.js fix/rewrites-manual-href-as Change
/ failed reqs 0 0
/ total time (seconds) 1.92 1.943 ⚠️ +0.02
/ avg req/sec 1302.11 1286.47 ⚠️ -15.64
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.023 1.006 -0.02
/error-in-render avg req/sec 2444.11 2485.91 +41.8
Client Bundles (main, webpack, commons) Overall increase ⚠️
vercel/next.js canary ijjk/next.js fix/rewrites-manual-href-as Change
framework-HASH.js gzip 39.3 kB 39.3 kB
main-HASH.js gzip 19.4 kB 19.4 kB ⚠️ +16 B
webpack-HASH.js gzip 994 B 994 B
Overall change 59.7 kB 59.7 kB ⚠️ +16 B
Legacy Client Bundles (polyfills)
vercel/next.js canary ijjk/next.js fix/rewrites-manual-href-as Change
polyfills-HASH.js gzip 31.1 kB 31.1 kB
Overall change 31.1 kB 31.1 kB
Client Pages
vercel/next.js canary ijjk/next.js fix/rewrites-manual-href-as Change
_app-HASH.js gzip 1.02 kB 1.02 kB
_error-HASH.js gzip 3.06 kB 3.06 kB
amp-HASH.js gzip 526 B 526 B
css-HASH.js gzip 334 B 334 B
hooks-HASH.js gzip 890 B 890 B
index-HASH.js gzip 262 B 262 B
link-HASH.js gzip 1.65 kB 1.65 kB
routerDirect..HASH.js gzip 331 B 331 B
withRouter-HASH.js gzip 329 B 329 B
bb14e60e810b..30f.css gzip 125 B 125 B
Overall change 8.54 kB 8.54 kB
Client Build Manifests
vercel/next.js canary ijjk/next.js fix/rewrites-manual-href-as Change
_buildManifest.js gzip 390 B 390 B
Overall change 390 B 390 B
Rendered Page Sizes Overall increase ⚠️
vercel/next.js canary ijjk/next.js fix/rewrites-manual-href-as Change
index.html gzip 559 B 561 B ⚠️ +2 B
link.html gzip 567 B 570 B ⚠️ +3 B
withRouter.html gzip 555 B 557 B ⚠️ +2 B
Overall change 1.68 kB 1.69 kB ⚠️ +7 B

Diffs

Diff for main-HASH.js
@@ -3754,6 +3754,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                   forcedScroll
                 ) {
                   var _options$scroll,
+                    shouldResolveHref,
                     localeChange,
                     parsedAs,
                     localePathResult,
@@ -3812,8 +3813,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             return _context.abrupt("return", false);
 
                           case 3:
-                            // for static pages with query params in the URL we delay
+                            shouldResolveHref = url === as || options._h; // for static pages with query params in the URL we delay
                             // marking the router ready until after the query is updated
+
                             if (options._h) {
                               this.isReady = true;
                             } // Default to scroll reset behavior unless explicitly specified to be
@@ -3827,7 +3829,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             localeChange = options.locale !== this.locale;
 
                             if (true) {
-                              _context.next = 18;
+                              _context.next = 19;
                               break;
                             }
 
@@ -3880,7 +3882,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             }
 
                             if (!didNavigate) {
-                              _context.next = 18;
+                              _context.next = 19;
                               break;
                             }
 
@@ -3889,7 +3891,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               new Promise(function() {})
                             );
 
-                          case 18:
+                          case 19:
                             if (!options._h) {
                               this.isSsr = false;
                             } // marking route changes as a navigation start entry
@@ -3934,7 +3936,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             if (
                               !(!options._h && this.onlyAHashChange(cleanedAs))
                             ) {
-                              _context.next = 34;
+                              _context.next = 35;
                               break;
                             }
 
@@ -3955,7 +3957,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             );
                             return _context.abrupt("return", true);
 
-                          case 34:
+                          case 35:
                             parsed = (0, _parseRelativeUrl.parseRelativeUrl)(
                               url
                             );
@@ -3964,30 +3966,30 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             // get their query parameters to allow ensuring they can be parsed properly
                             // when rewritten to
 
-                            _context.prev = 36;
-                            _context.next = 39;
+                            _context.prev = 37;
+                            _context.next = 40;
                             return this.pageLoader.getPageList();
 
-                          case 39:
+                          case 40:
                             pages = _context.sent;
-                            _context.next = 42;
+                            _context.next = 43;
                             return (0, _routeLoader.getClientBuildManifest)();
 
-                          case 42:
+                          case 43:
                             _yield = _context.sent;
                             rewrites = _yield.__rewrites;
-                            _context.next = 50;
+                            _context.next = 51;
                             break;
 
-                          case 46:
-                            _context.prev = 46;
-                            _context.t0 = _context["catch"](36);
+                          case 47:
+                            _context.prev = 47;
+                            _context.t0 = _context["catch"](37);
                             // If we fail to resolve the page list or client-build manifest, we must
                             // do a server-side transition:
                             window.location.href = as;
                             return _context.abrupt("return", false);
 
-                          case 50:
+                          case 51:
                             // If asked to change the current URL we should reload the current page
                             // (not location.reload() but reload getInitialProps and other Next.js stuffs)
                             // We also need to set the method = replaceState always
@@ -4009,7 +4011,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                                 )
                               : pathname;
 
-                            if (pathname !== "/_error") {
+                            if (shouldResolveHref && pathname !== "/_error") {
                               if (false) {
                               } else {
                                 parsed.pathname = resolveDynamicRoute(
@@ -4032,12 +4034,12 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             );
 
                             if (isLocalURL(as)) {
-                              _context.next = 60;
+                              _context.next = 61;
                               break;
                             }
 
                             if (true) {
-                              _context.next = 58;
+                              _context.next = 59;
                               break;
                             }
 
@@ -4051,18 +4053,18 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                                 "\nSee more info: https://nextjs.org/docs/messages/invalid-relative-url-external-as"
                             );
 
-                          case 58:
+                          case 59:
                             window.location.href = as;
                             return _context.abrupt("return", false);
 
-                          case 60:
+                          case 61:
                             resolvedAs = delLocale(
                               delBasePath(resolvedAs),
                               this.locale
                             );
 
                             if (!(0, _isDynamic.isDynamicRoute)(route)) {
-                              _context.next = 76;
+                              _context.next = 77;
                               break;
                             }
 
@@ -4085,7 +4087,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                                 (shouldInterpolate && !interpolatedAs.result)
                               )
                             ) {
-                              _context.next = 75;
+                              _context.next = 76;
                               break;
                             }
 
@@ -4096,7 +4098,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             });
 
                             if (!(missingParams.length > 0)) {
-                              _context.next = 73;
+                              _context.next = 74;
                               break;
                             }
 
@@ -4127,11 +4129,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                                 )
                             );
 
-                          case 73:
-                            _context.next = 76;
+                          case 74:
+                            _context.next = 77;
                             break;
 
-                          case 75:
+                          case 76:
                             if (shouldInterpolate) {
                               as = (0, _utils.formatWithValidation)(
                                 Object.assign({}, _parsedAs, {
@@ -4147,14 +4149,14 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               Object.assign(query, routeMatch);
                             }
 
-                          case 76:
+                          case 77:
                             Router.events.emit(
                               "routeChangeStart",
                               as,
                               routeProps
                             );
-                            _context.prev = 77;
-                            _context.next = 80;
+                            _context.prev = 78;
+                            _context.next = 81;
                             return this.getRouteInfo(
                               route,
                               pathname,
@@ -4164,7 +4166,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               routeProps
                             );
 
-                          case 80:
+                          case 81:
                             routeInfo = _context.sent;
                             (_routeInfo = routeInfo),
                               (error = _routeInfo.error),
@@ -4173,14 +4175,14 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               (__N_SSP = _routeInfo.__N_SSP); // handle redirect on client-transition
 
                             if (!((__N_SSG || __N_SSP) && props)) {
-                              _context.next = 107;
+                              _context.next = 108;
                               break;
                             }
 
                             if (
                               !(props.pageProps && props.pageProps.__N_REDIRECT)
                             ) {
-                              _context.next = 93;
+                              _context.next = 94;
                               break;
                             }
 
@@ -4189,7 +4191,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             // it's not
 
                             if (!destination.startsWith("/")) {
-                              _context.next = 91;
+                              _context.next = 92;
                               break;
                             }
 
@@ -4201,7 +4203,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             );
 
                             if (!pages.includes(parsedHref.pathname)) {
-                              _context.next = 91;
+                              _context.next = 92;
                               break;
                             }
 
@@ -4217,37 +4219,37 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               this.change(method, newUrl, newAs, options)
                             );
 
-                          case 91:
+                          case 92:
                             window.location.href = destination;
                             return _context.abrupt(
                               "return",
                               new Promise(function() {})
                             );
 
-                          case 93:
+                          case 94:
                             this.isPreview = !!props.__N_PREVIEW; // handle SSG data 404
 
                             if (!(props.notFound === SSG_DATA_NOT_FOUND)) {
-                              _context.next = 107;
+                              _context.next = 108;
                               break;
                             }
 
-                            _context.prev = 95;
-                            _context.next = 98;
+                            _context.prev = 96;
+                            _context.next = 99;
                             return this.fetchComponent("/404");
 
-                          case 98:
+                          case 99:
                             notFoundRoute = "/404";
-                            _context.next = 104;
+                            _context.next = 105;
                             break;
 
-                          case 101:
-                            _context.prev = 101;
-                            _context.t1 = _context["catch"](95);
+                          case 102:
+                            _context.prev = 102;
+                            _context.t1 = _context["catch"](96);
                             notFoundRoute = "/_error";
 
-                          case 104:
-                            _context.next = 106;
+                          case 105:
+                            _context.next = 107;
                             return this.getRouteInfo(
                               notFoundRoute,
                               notFoundRoute,
@@ -4259,10 +4261,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               }
                             );
 
-                          case 106:
+                          case 107:
                             routeInfo = _context.sent;
 
-                          case 107:
+                          case 108:
                             Router.events.emit(
                               "beforeHistoryChange",
                               as,
@@ -4294,7 +4296,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               props.pageProps.statusCode = 500;
                             }
 
-                            _context.next = 114;
+                            _context.next = 115;
                             return this.set(
                               route,
                               pathname,
@@ -4313,9 +4315,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               else throw e;
                             });
 
-                          case 114:
+                          case 115:
                             if (!error) {
-                              _context.next = 117;
+                              _context.next = 118;
                               break;
                             }
 
@@ -4327,7 +4329,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             );
                             throw error;
 
-                          case 117:
+                          case 118:
                             if (false) {
                             }
 
@@ -4338,21 +4340,21 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             );
                             return _context.abrupt("return", true);
 
-                          case 122:
-                            _context.prev = 122;
-                            _context.t2 = _context["catch"](77);
+                          case 123:
+                            _context.prev = 123;
+                            _context.t2 = _context["catch"](78);
 
                             if (!_context.t2.cancelled) {
-                              _context.next = 126;
+                              _context.next = 127;
                               break;
                             }
 
                             return _context.abrupt("return", false);
 
-                          case 126:
+                          case 127:
                             throw _context.t2;
 
-                          case 127:
+                          case 128:
                           case "end":
                             return _context.stop();
                         }
@@ -4361,9 +4363,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                     _callee,
                     this,
                     [
-                      [36, 46],
-                      [77, 122],
-                      [95, 101]
+                      [37, 47],
+                      [78, 123],
+                      [96, 102]
                     ]
                   );
                 })
Diff for index.html
@@ -17,7 +17,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/main-851c852230eb6ff9a255.js"
+      href="/_next/static/chunks/main-05dd02e5d5ba130b8b94.js"
       as="script"
     />
     <link
@@ -56,7 +56,7 @@
       async=""
     ></script>
     <script
-      src="/_next/static/chunks/main-851c852230eb6ff9a255.js"
+      src="/_next/static/chunks/main-05dd02e5d5ba130b8b94.js"
       async=""
     ></script>
     <script
Diff for link.html
@@ -17,7 +17,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/main-851c852230eb6ff9a255.js"
+      href="/_next/static/chunks/main-05dd02e5d5ba130b8b94.js"
       as="script"
     />
     <link
@@ -61,7 +61,7 @@
       async=""
     ></script>
     <script
-      src="/_next/static/chunks/main-851c852230eb6ff9a255.js"
+      src="/_next/static/chunks/main-05dd02e5d5ba130b8b94.js"
       async=""
     ></script>
     <script
Diff for withRouter.html
@@ -17,7 +17,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/main-851c852230eb6ff9a255.js"
+      href="/_next/static/chunks/main-05dd02e5d5ba130b8b94.js"
       as="script"
     />
     <link
@@ -56,7 +56,7 @@
       async=""
     ></script>
     <script
-      src="/_next/static/chunks/main-851c852230eb6ff9a255.js"
+      src="/_next/static/chunks/main-05dd02e5d5ba130b8b94.js"
       async=""
     ></script>
     <script

Serverless Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary ijjk/next.js fix/rewrites-manual-href-as Change
buildDuration 13s 12.8s -247ms
buildDurationCached 4.7s 4.9s ⚠️ +110ms
nodeModulesSize 46.6 MB 46.6 MB ⚠️ +260 B
Client Bundles (main, webpack, commons) Overall increase ⚠️
vercel/next.js canary ijjk/next.js fix/rewrites-manual-href-as Change
framework-HASH.js gzip 39.3 kB 39.3 kB
main-HASH.js gzip 19.4 kB 19.4 kB ⚠️ +16 B
webpack-HASH.js gzip 994 B 994 B
Overall change 59.7 kB 59.7 kB ⚠️ +16 B
Legacy Client Bundles (polyfills)
vercel/next.js canary ijjk/next.js fix/rewrites-manual-href-as Change
polyfills-HASH.js gzip 31.1 kB 31.1 kB
Overall change 31.1 kB 31.1 kB
Client Pages
vercel/next.js canary ijjk/next.js fix/rewrites-manual-href-as Change
_app-HASH.js gzip 1.02 kB 1.02 kB
_error-HASH.js gzip 3.06 kB 3.06 kB
amp-HASH.js gzip 526 B 526 B
css-HASH.js gzip 334 B 334 B
hooks-HASH.js gzip 890 B 890 B
index-HASH.js gzip 262 B 262 B
link-HASH.js gzip 1.65 kB 1.65 kB
routerDirect..HASH.js gzip 331 B 331 B
withRouter-HASH.js gzip 329 B 329 B
bb14e60e810b..30f.css gzip 125 B 125 B
Overall change 8.54 kB 8.54 kB
Client Build Manifests
vercel/next.js canary ijjk/next.js fix/rewrites-manual-href-as Change
_buildManifest.js gzip 390 B 390 B
Overall change 390 B 390 B
Serverless bundles Overall increase ⚠️
vercel/next.js canary ijjk/next.js fix/rewrites-manual-href-as Change
_error.js 1.34 MB 1.34 MB
404.html 2.42 kB 2.42 kB
500.html 2.41 kB 2.41 kB
amp.amp.html 10.8 kB 10.8 kB
amp.html 1.61 kB 1.61 kB
css.html 1.79 kB 1.79 kB
hooks.html 1.67 kB 1.67 kB
index.js 1.34 MB 1.34 MB
link.js 1.4 MB 1.4 MB ⚠️ +77 B
routerDirect.js 1.4 MB 1.4 MB ⚠️ +77 B
withRouter.js 1.4 MB 1.4 MB ⚠️ +77 B
Overall change 6.91 MB 6.91 MB ⚠️ +231 B

Webpack 4 Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary ijjk/next.js fix/rewrites-manual-href-as Change
buildDuration 8.9s 8.9s ⚠️ +17ms
buildDurationCached 3.8s 3.7s -72ms
nodeModulesSize 46.6 MB 46.6 MB ⚠️ +260 B
Page Load Tests Overall increase ✓
vercel/next.js canary ijjk/next.js fix/rewrites-manual-href-as Change
/ failed reqs 0 0
/ total time (seconds) 1.789 1.801 ⚠️ +0.01
/ avg req/sec 1397.47 1387.81 ⚠️ -9.66
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 0.979 0.956 -0.02
/error-in-render avg req/sec 2553.46 2615.46 +62
Client Bundles (main, webpack, commons) Overall increase ⚠️
vercel/next.js canary ijjk/next.js fix/rewrites-manual-href-as Change
677f882d2ed8..HASH.js gzip 13.3 kB 13.3 kB ⚠️ +9 B
framework.HASH.js gzip 39 kB 39 kB
main-HASH.js gzip 7.26 kB 7.26 kB
webpack-HASH.js gzip 751 B 751 B
Overall change 60.3 kB 60.3 kB ⚠️ +9 B
Legacy Client Bundles (polyfills)
vercel/next.js canary ijjk/next.js fix/rewrites-manual-href-as Change
polyfills-HASH.js gzip 31.3 kB 31.3 kB
Overall change 31.3 kB 31.3 kB
Client Pages
vercel/next.js canary ijjk/next.js fix/rewrites-manual-href-as Change
_app-HASH.js gzip 1.28 kB 1.28 kB
_error-HASH.js gzip 3.74 kB 3.74 kB
amp-HASH.js gzip 536 B 536 B
css-HASH.js gzip 339 B 339 B
hooks-HASH.js gzip 887 B 887 B
index-HASH.js gzip 227 B 227 B
link-HASH.js gzip 1.64 kB 1.64 kB
routerDirect..HASH.js gzip 303 B 303 B
withRouter-HASH.js gzip 302 B 302 B
e025d2764813..52f.css gzip 125 B 125 B
Overall change 9.38 kB 9.38 kB
Client Build Manifests
vercel/next.js canary ijjk/next.js fix/rewrites-manual-href-as Change
_buildManifest.js gzip 420 B 420 B
Overall change 420 B 420 B
Rendered Page Sizes Overall increase ⚠️
vercel/next.js canary ijjk/next.js fix/rewrites-manual-href-as Change
index.html gzip 613 B 614 B ⚠️ +1 B
link.html gzip 619 B 620 B ⚠️ +1 B
withRouter.html gzip 606 B 606 B
Overall change 1.84 kB 1.84 kB ⚠️ +2 B

Diffs

Diff for 677f882d2ed8..c4df.HASH.js
@@ -1824,6 +1824,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                   forcedScroll
                 ) {
                   var _options$scroll,
+                    shouldResolveHref,
                     localeChange,
                     parsedAs,
                     localePathResult,
@@ -1882,8 +1883,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             return _context.abrupt("return", false);
 
                           case 3:
-                            // for static pages with query params in the URL we delay
+                            shouldResolveHref = url === as || options._h; // for static pages with query params in the URL we delay
                             // marking the router ready until after the query is updated
+
                             if (options._h) {
                               this.isReady = true;
                             } // Default to scroll reset behavior unless explicitly specified to be
@@ -1897,7 +1899,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             localeChange = options.locale !== this.locale;
 
                             if (true) {
-                              _context.next = 18;
+                              _context.next = 19;
                               break;
                             }
 
@@ -1950,7 +1952,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             }
 
                             if (!didNavigate) {
-                              _context.next = 18;
+                              _context.next = 19;
                               break;
                             }
 
@@ -1959,7 +1961,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               new Promise(function() {})
                             );
 
-                          case 18:
+                          case 19:
                             if (!options._h) {
                               this.isSsr = false;
                             } // marking route changes as a navigation start entry
@@ -2004,7 +2006,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             if (
                               !(!options._h && this.onlyAHashChange(cleanedAs))
                             ) {
-                              _context.next = 34;
+                              _context.next = 35;
                               break;
                             }
 
@@ -2025,7 +2027,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             );
                             return _context.abrupt("return", true);
 
-                          case 34:
+                          case 35:
                             parsed = (0, _parseRelativeUrl.parseRelativeUrl)(
                               url
                             );
@@ -2034,30 +2036,30 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             // get their query parameters to allow ensuring they can be parsed properly
                             // when rewritten to
 
-                            _context.prev = 36;
-                            _context.next = 39;
+                            _context.prev = 37;
+                            _context.next = 40;
                             return this.pageLoader.getPageList();
 
-                          case 39:
+                          case 40:
                             pages = _context.sent;
-                            _context.next = 42;
+                            _context.next = 43;
                             return (0, _routeLoader.getClientBuildManifest)();
 
-                          case 42:
+                          case 43:
                             _yield = _context.sent;
                             rewrites = _yield.__rewrites;
-                            _context.next = 50;
+                            _context.next = 51;
                             break;
 
-                          case 46:
-                            _context.prev = 46;
-                            _context.t0 = _context["catch"](36);
+                          case 47:
+                            _context.prev = 47;
+                            _context.t0 = _context["catch"](37);
                             // If we fail to resolve the page list or client-build manifest, we must
                             // do a server-side transition:
                             window.location.href = as;
                             return _context.abrupt("return", false);
 
-                          case 50:
+                          case 51:
                             // If asked to change the current URL we should reload the current page
                             // (not location.reload() but reload getInitialProps and other Next.js stuffs)
                             // We also need to set the method = replaceState always
@@ -2079,7 +2081,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                                 )
                               : pathname;
 
-                            if (pathname !== "/_error") {
+                            if (shouldResolveHref && pathname !== "/_error") {
                               if (false) {
                               } else {
                                 parsed.pathname = resolveDynamicRoute(
@@ -2102,12 +2104,12 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             );
 
                             if (isLocalURL(as)) {
-                              _context.next = 60;
+                              _context.next = 61;
                               break;
                             }
 
                             if (true) {
-                              _context.next = 58;
+                              _context.next = 59;
                               break;
                             }
 
@@ -2121,18 +2123,18 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                                 "\nSee more info: https://nextjs.org/docs/messages/invalid-relative-url-external-as"
                             );
 
-                          case 58:
+                          case 59:
                             window.location.href = as;
                             return _context.abrupt("return", false);
 
-                          case 60:
+                          case 61:
                             resolvedAs = delLocale(
                               delBasePath(resolvedAs),
                               this.locale
                             );
 
                             if (!(0, _isDynamic.isDynamicRoute)(route)) {
-                              _context.next = 76;
+                              _context.next = 77;
                               break;
                             }
 
@@ -2155,7 +2157,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                                 (shouldInterpolate && !interpolatedAs.result)
                               )
                             ) {
-                              _context.next = 75;
+                              _context.next = 76;
                               break;
                             }
 
@@ -2166,7 +2168,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             });
 
                             if (!(missingParams.length > 0)) {
-                              _context.next = 73;
+                              _context.next = 74;
                               break;
                             }
 
@@ -2197,11 +2199,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                                 )
                             );
 
-                          case 73:
-                            _context.next = 76;
+                          case 74:
+                            _context.next = 77;
                             break;
 
-                          case 75:
+                          case 76:
                             if (shouldInterpolate) {
                               as = (0, _utils.formatWithValidation)(
                                 Object.assign({}, _parsedAs, {
@@ -2217,14 +2219,14 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               Object.assign(query, routeMatch);
                             }
 
-                          case 76:
+                          case 77:
                             Router.events.emit(
                               "routeChangeStart",
                               as,
                               routeProps
                             );
-                            _context.prev = 77;
-                            _context.next = 80;
+                            _context.prev = 78;
+                            _context.next = 81;
                             return this.getRouteInfo(
                               route,
                               pathname,
@@ -2234,7 +2236,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               routeProps
                             );
 
-                          case 80:
+                          case 81:
                             routeInfo = _context.sent;
                             (_routeInfo = routeInfo),
                               (error = _routeInfo.error),
@@ -2243,14 +2245,14 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               (__N_SSP = _routeInfo.__N_SSP); // handle redirect on client-transition
 
                             if (!((__N_SSG || __N_SSP) && props)) {
-                              _context.next = 107;
+                              _context.next = 108;
                               break;
                             }
 
                             if (
                               !(props.pageProps && props.pageProps.__N_REDIRECT)
                             ) {
-                              _context.next = 93;
+                              _context.next = 94;
                               break;
                             }
 
@@ -2259,7 +2261,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             // it's not
 
                             if (!destination.startsWith("/")) {
-                              _context.next = 91;
+                              _context.next = 92;
                               break;
                             }
 
@@ -2271,7 +2273,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             );
 
                             if (!pages.includes(parsedHref.pathname)) {
-                              _context.next = 91;
+                              _context.next = 92;
                               break;
                             }
 
@@ -2287,37 +2289,37 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               this.change(method, newUrl, newAs, options)
                             );
 
-                          case 91:
+                          case 92:
                             window.location.href = destination;
                             return _context.abrupt(
                               "return",
                               new Promise(function() {})
                             );
 
-                          case 93:
+                          case 94:
                             this.isPreview = !!props.__N_PREVIEW; // handle SSG data 404
 
                             if (!(props.notFound === SSG_DATA_NOT_FOUND)) {
-                              _context.next = 107;
+                              _context.next = 108;
                               break;
                             }
 
-                            _context.prev = 95;
-                            _context.next = 98;
+                            _context.prev = 96;
+                            _context.next = 99;
                             return this.fetchComponent("/404");
 
-                          case 98:
+                          case 99:
                             notFoundRoute = "/404";
-                            _context.next = 104;
+                            _context.next = 105;
                             break;
 
-                          case 101:
-                            _context.prev = 101;
-                            _context.t1 = _context["catch"](95);
+                          case 102:
+                            _context.prev = 102;
+                            _context.t1 = _context["catch"](96);
                             notFoundRoute = "/_error";
 
-                          case 104:
-                            _context.next = 106;
+                          case 105:
+                            _context.next = 107;
                             return this.getRouteInfo(
                               notFoundRoute,
                               notFoundRoute,
@@ -2329,10 +2331,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               }
                             );
 
-                          case 106:
+                          case 107:
                             routeInfo = _context.sent;
 
-                          case 107:
+                          case 108:
                             Router.events.emit(
                               "beforeHistoryChange",
                               as,
@@ -2364,7 +2366,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               props.pageProps.statusCode = 500;
                             }
 
-                            _context.next = 114;
+                            _context.next = 115;
                             return this.set(
                               route,
                               pathname,
@@ -2383,9 +2385,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                               else throw e;
                             });
 
-                          case 114:
+                          case 115:
                             if (!error) {
-                              _context.next = 117;
+                              _context.next = 118;
                               break;
                             }
 
@@ -2397,7 +2399,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             );
                             throw error;
 
-                          case 117:
+                          case 118:
                             if (false) {
                             }
 
@@ -2408,21 +2410,21 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                             );
                             return _context.abrupt("return", true);
 
-                          case 122:
-                            _context.prev = 122;
-                            _context.t2 = _context["catch"](77);
+                          case 123:
+                            _context.prev = 123;
+                            _context.t2 = _context["catch"](78);
 
                             if (!_context.t2.cancelled) {
-                              _context.next = 126;
+                              _context.next = 127;
                               break;
                             }
 
                             return _context.abrupt("return", false);
 
-                          case 126:
+                          case 127:
                             throw _context.t2;
 
-                          case 127:
+                          case 128:
                           case "end":
                             return _context.stop();
                         }
@@ -2431,9 +2433,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                     _callee,
                     this,
                     [
-                      [36, 46],
-                      [77, 122],
-                      [95, 101]
+                      [37, 47],
+                      [78, 123],
+                      [96, 102]
                     ]
                   );
                 })
Diff for index.html
@@ -17,7 +17,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.316105931a71d2e2e072.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.26e6c0f15d34a1b1b821.js"
       as="script"
     />
     <link
@@ -61,7 +61,7 @@
       async=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.316105931a71d2e2e072.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.26e6c0f15d34a1b1b821.js"
       async=""
     ></script>
     <script
Diff for link.html
@@ -17,7 +17,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.316105931a71d2e2e072.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.26e6c0f15d34a1b1b821.js"
       as="script"
     />
     <link
@@ -66,7 +66,7 @@
       async=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.316105931a71d2e2e072.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.26e6c0f15d34a1b1b821.js"
       async=""
     ></script>
     <script
Diff for withRouter.html
@@ -17,7 +17,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.316105931a71d2e2e072.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.26e6c0f15d34a1b1b821.js"
       as="script"
     />
     <link
@@ -61,7 +61,7 @@
       async=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.316105931a71d2e2e072.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.26e6c0f15d34a1b1b821.js"
       async=""
     ></script>
     <script
Commit: 0cd9ad4

@ijjk ijjk marked this pull request as ready for review May 13, 2021 20:45
@timneutkens timneutkens merged commit 5bff9ea into vercel:canary May 14, 2021
@timneutkens timneutkens deleted the fix/rewrites-manual-href-as branch May 14, 2021 10:50
@PepijnSenders
Copy link
Contributor

PepijnSenders commented May 26, 2021

@ijjk I think this PR broke the back-button for us:

Screen Shot 2021-05-26 at 10 34 29 AM

Will investigate a bit and maybe open a PR if I can figure out why this started happening since this version.

flybayer pushed a commit to blitz-js/next.js that referenced this pull request Jun 1, 2021
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants