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

Fix asPath of rewrite without basePath #15760

Merged
merged 1 commit into from
Aug 1, 2020
Merged

Conversation

Janpot
Copy link
Contributor

@Janpot Janpot commented Aug 1, 2020

Fixes #15755

@ijjk ijjk added the type: next label Aug 1, 2020
@ijjk
Copy link
Member

ijjk commented Aug 1, 2020

Stats from current PR

Default Server Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary Janpot/next.js basepath2 Change
buildDuration 14.5s 15s ⚠️ +453ms
nodeModulesSize 65.5 MB 65.5 MB ⚠️ +192 B
Page Load Tests Overall decrease ⚠️
vercel/next.js canary Janpot/next.js basepath2 Change
/ failed reqs 0 0
/ total time (seconds) 2.676 2.783 ⚠️ +0.11
/ avg req/sec 934.34 898.17 ⚠️ -36.17
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.657 1.691 ⚠️ +0.03
/error-in-render avg req/sec 1508.63 1478.12 ⚠️ -30.51
Client Bundles (main, webpack, commons) Overall decrease ✓
vercel/next.js canary Janpot/next.js basepath2 Change
677f882d2ed8..9e81.js gzip 10.2 kB 10.2 kB ⚠️ +22 B
framework.HASH.js gzip 39.1 kB 39.1 kB
main-8dccf8c..edef.js gzip 6.76 kB 6.73 kB -33 B
webpack-488d..c0e7.js gzip 751 B 751 B
Overall change 56.8 kB 56.8 kB -11 B
Client Bundles (main, webpack, commons) Modern Overall decrease ✓
vercel/next.js canary Janpot/next.js basepath2 Change
677f882d2ed8..dule.js gzip 6.09 kB 6.12 kB ⚠️ +27 B
framework.HA..dule.js gzip 39.1 kB 39.1 kB
main-85e7a5d..dule.js gzip 5.84 kB 5.81 kB -31 B
webpack-4f62..dule.js gzip 751 B 751 B
Overall change 51.8 kB 51.8 kB -4 B
Legacy Client Bundles (polyfills)
vercel/next.js canary Janpot/next.js basepath2 Change
polyfills-05..1236.js gzip 30.8 kB 30.8 kB
Overall change 30.8 kB 30.8 kB
Client Pages
vercel/next.js canary Janpot/next.js basepath2 Change
_app-8f5f611..1f7b.js gzip 1.28 kB 1.28 kB
_error-a98d9..5cb7.js gzip 3.45 kB 3.45 kB
hooks-f7f3d0..7465.js gzip 887 B 887 B
index-08fb3f..c0e9.js gzip 227 B 227 B
link-6f8445b..99e1.js gzip 1.3 kB 1.3 kB
routerDirect..8aa1.js gzip 284 B 284 B
withRouter-f..e777.js gzip 284 B 284 B
Overall change 7.72 kB 7.72 kB
Client Pages Modern
vercel/next.js canary Janpot/next.js basepath2 Change
_app-669dbe5..dule.js gzip 626 B 626 B
_error-d5979..dule.js gzip 2.3 kB 2.3 kB
hooks-805c40..dule.js gzip 387 B 387 B
index-6ba5a4..dule.js gzip 226 B 226 B
link-91516ae..dule.js gzip 1.25 kB 1.25 kB
routerDirect..dule.js gzip 284 B 284 B
withRouter-d..dule.js gzip 282 B 282 B
Overall change 5.36 kB 5.36 kB
Client Build Manifests
vercel/next.js canary Janpot/next.js basepath2 Change
_buildManifest.js gzip 274 B 274 B
_buildManife..dule.js gzip 282 B 282 B
Overall change 556 B 556 B
Rendered Page Sizes Overall increase ⚠️
vercel/next.js canary Janpot/next.js basepath2 Change
index.html gzip 944 B 948 B ⚠️ +4 B
link.html gzip 951 B 953 B ⚠️ +2 B
withRouter.html gzip 939 B 940 B ⚠️ +1 B
Overall change 2.83 kB 2.84 kB ⚠️ +7 B

Diffs

Diff for 677f882d2ed8..a64f02486.js
@@ -667,6 +667,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
       var _createClass = __webpack_require__("W8MJ");
 
       exports.__esModule = true;
+      exports.hasBasePath = hasBasePath;
       exports.addBasePath = addBasePath;
       exports.delBasePath = delBasePath;
       exports.resolveHref = resolveHref;
@@ -706,6 +707,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
         });
       }
 
+      function hasBasePath(path) {
+        return path === basePath || path.startsWith(basePath + "/");
+      }
+
       function addBasePath(path) {
         return basePath
           ? path === "/"
@@ -1107,7 +1112,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                                 this.abortComponentLoad(this._inFlightRoute);
                               }
 
-                              cleanedAs = delBasePath(as);
+                              cleanedAs = hasBasePath(as)
+                                ? delBasePath(as)
+                                : as;
                               this._inFlightRoute = as; // If the url change is only related to a hash change
                               // We should not proceed. We should only change the state.
                               // WARNING: `_h` is an internal option for handing Next.js client-side
Diff for 677f882d2ed8..e4.module.js
@@ -536,6 +536,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
       "use strict";
 
       exports.__esModule = true;
+      exports.hasBasePath = hasBasePath;
       exports.addBasePath = addBasePath;
       exports.delBasePath = delBasePath;
       exports.resolveHref = resolveHref;
@@ -575,6 +576,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
         });
       }
 
+      function hasBasePath(path) {
+        return path === basePath || path.startsWith(basePath + "/");
+      }
+
       function addBasePath(path) {
         return basePath
           ? path === "/"
@@ -919,7 +924,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
             this.abortComponentLoad(this._inFlightRoute);
           }
 
-          var cleanedAs = delBasePath(as);
+          var cleanedAs = hasBasePath(as) ? delBasePath(as) : as;
           this._inFlightRoute = as; // If the url change is only related to a hash change
           // We should not proceed. We should only change the state.
           // WARNING: `_h` is an internal option for handing Next.js client-side
Diff for main-092ccd6..1a29504b9.js
@@ -317,15 +317,7 @@ _N_E = (window["webpackJsonp_N_E"] = window["webpackJsonp_N_E"] || []).push([
       });
       var asPath = (0, _utils.getURL)(); // make sure not to attempt stripping basePath for 404s
 
-      if (
-        page !== "/404" &&
-        !(
-          page === "/_error" &&
-          hydrateProps &&
-          hydrateProps.pageProps &&
-          hydrateProps.pageProps.statusCode === 404
-        )
-      ) {
+      if ((0, _router2.hasBasePath)(asPath)) {
         asPath = (0, _router2.delBasePath)(asPath);
       }
Diff for main-62a1247..37.module.js
@@ -237,15 +237,7 @@
       });
       var asPath = (0, _utils.getURL)(); // make sure not to attempt stripping basePath for 404s
 
-      if (
-        page !== "/404" &&
-        !(
-          page === "/_error" &&
-          hydrateProps &&
-          hydrateProps.pageProps &&
-          hydrateProps.pageProps.statusCode === 404
-        )
-      ) {
+      if ((0, _router2.hasBasePath)(asPath)) {
         asPath = (0, _router2.delBasePath)(asPath);
       }
Diff for index.html
@@ -6,7 +6,7 @@
     <meta name="next-head-count" content="2" />
     <link
       rel="preload"
-      href="/_next/static/chunks/main-62a124753b6705b60b37.module.js"
+      href="/_next/static/chunks/main-63a645b327ebfc44d4e0.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -24,7 +24,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.ef6cc8889408a3d818e4.module.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.4e14fd48cc5b066cb405.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -81,13 +81,13 @@
       src="/_next/static/chunks/polyfills-cdbbd579644400b29b58.js"
     ></script>
     <script
-      src="/_next/static/chunks/main-092ccd6c8111a29504b9.js"
+      src="/_next/static/chunks/main-11db2adbacdc8afcd350.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/main-62a124753b6705b60b37.module.js"
+      src="/_next/static/chunks/main-63a645b327ebfc44d4e0.module.js"
       async=""
       crossorigin="anonymous"
       type="module"
@@ -117,13 +117,13 @@
       type="module"
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.41d5d7ded3aa64f02486.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.d37adacf5052ad5ed26c.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.ef6cc8889408a3d818e4.module.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.4e14fd48cc5b066cb405.module.js"
       async=""
       crossorigin="anonymous"
       type="module"
Diff for link.html
@@ -6,7 +6,7 @@
     <meta name="next-head-count" content="2" />
     <link
       rel="preload"
-      href="/_next/static/chunks/main-62a124753b6705b60b37.module.js"
+      href="/_next/static/chunks/main-63a645b327ebfc44d4e0.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -24,7 +24,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.ef6cc8889408a3d818e4.module.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.4e14fd48cc5b066cb405.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -86,13 +86,13 @@
       src="/_next/static/chunks/polyfills-cdbbd579644400b29b58.js"
     ></script>
     <script
-      src="/_next/static/chunks/main-092ccd6c8111a29504b9.js"
+      src="/_next/static/chunks/main-11db2adbacdc8afcd350.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/main-62a124753b6705b60b37.module.js"
+      src="/_next/static/chunks/main-63a645b327ebfc44d4e0.module.js"
       async=""
       crossorigin="anonymous"
       type="module"
@@ -122,13 +122,13 @@
       type="module"
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.41d5d7ded3aa64f02486.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.d37adacf5052ad5ed26c.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.ef6cc8889408a3d818e4.module.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.4e14fd48cc5b066cb405.module.js"
       async=""
       crossorigin="anonymous"
       type="module"
Diff for withRouter.html
@@ -6,7 +6,7 @@
     <meta name="next-head-count" content="2" />
     <link
       rel="preload"
-      href="/_next/static/chunks/main-62a124753b6705b60b37.module.js"
+      href="/_next/static/chunks/main-63a645b327ebfc44d4e0.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -24,7 +24,7 @@
     />
     <link
       rel="preload"
-      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.ef6cc8889408a3d818e4.module.js"
+      href="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.4e14fd48cc5b066cb405.module.js"
       as="script"
       crossorigin="anonymous"
     />
@@ -81,13 +81,13 @@
       src="/_next/static/chunks/polyfills-cdbbd579644400b29b58.js"
     ></script>
     <script
-      src="/_next/static/chunks/main-092ccd6c8111a29504b9.js"
+      src="/_next/static/chunks/main-11db2adbacdc8afcd350.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/main-62a124753b6705b60b37.module.js"
+      src="/_next/static/chunks/main-63a645b327ebfc44d4e0.module.js"
       async=""
       crossorigin="anonymous"
       type="module"
@@ -117,13 +117,13 @@
       type="module"
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.41d5d7ded3aa64f02486.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.d37adacf5052ad5ed26c.js"
       async=""
       crossorigin="anonymous"
       nomodule=""
     ></script>
     <script
-      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.ef6cc8889408a3d818e4.module.js"
+      src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.4e14fd48cc5b066cb405.module.js"
       async=""
       crossorigin="anonymous"
       type="module"

Serverless Mode (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary Janpot/next.js basepath2 Change
buildDuration 16.3s 16.5s ⚠️ +155ms
nodeModulesSize 65.5 MB 65.5 MB ⚠️ +192 B
Client Bundles (main, webpack, commons) Overall decrease ✓
vercel/next.js canary Janpot/next.js basepath2 Change
677f882d2ed8..9e81.js gzip 10.2 kB N/A N/A
framework.HASH.js gzip 39.1 kB 39.1 kB
main-8dccf8c..edef.js gzip 6.76 kB N/A N/A
webpack-488d..c0e7.js gzip 751 B 751 B
677f882d2ed8..70d8.js gzip N/A 10.2 kB N/A
main-06588f2..f65e.js gzip N/A 6.73 kB N/A
Overall change 56.8 kB 56.8 kB -11 B
Client Bundles (main, webpack, commons) Modern Overall decrease ✓
vercel/next.js canary Janpot/next.js basepath2 Change
677f882d2ed8..dule.js gzip 6.09 kB N/A N/A
framework.HA..dule.js gzip 39.1 kB 39.1 kB
main-85e7a5d..dule.js gzip 5.84 kB N/A N/A
webpack-4f62..dule.js gzip 751 B 751 B
677f882d2ed8..dule.js gzip N/A 6.12 kB N/A
main-62e1f09..dule.js gzip N/A 5.81 kB N/A
Overall change 51.8 kB 51.8 kB -4 B
Legacy Client Bundles (polyfills)
vercel/next.js canary Janpot/next.js basepath2 Change
polyfills-05..1236.js gzip 30.8 kB 30.8 kB
Overall change 30.8 kB 30.8 kB
Client Pages
vercel/next.js canary Janpot/next.js basepath2 Change
_app-8f5f611..1f7b.js gzip 1.28 kB 1.28 kB
_error-a98d9..5cb7.js gzip 3.45 kB 3.45 kB
hooks-f7f3d0..7465.js gzip 887 B 887 B
index-08fb3f..c0e9.js gzip 227 B 227 B
link-6f8445b..99e1.js gzip 1.3 kB 1.3 kB
routerDirect..8aa1.js gzip 284 B 284 B
withRouter-f..e777.js gzip 284 B 284 B
Overall change 7.72 kB 7.72 kB
Client Pages Modern
vercel/next.js canary Janpot/next.js basepath2 Change
_app-669dbe5..dule.js gzip 626 B 626 B
_error-d5979..dule.js gzip 2.3 kB 2.3 kB
hooks-805c40..dule.js gzip 387 B 387 B
index-6ba5a4..dule.js gzip 226 B 226 B
link-91516ae..dule.js gzip 1.25 kB 1.25 kB
routerDirect..dule.js gzip 284 B 284 B
withRouter-d..dule.js gzip 282 B 282 B
Overall change 5.36 kB 5.36 kB
Client Build Manifests
vercel/next.js canary Janpot/next.js basepath2 Change
_buildManifest.js gzip 274 B 274 B
_buildManife..dule.js gzip 282 B 282 B
Overall change 556 B 556 B
Serverless bundles Overall increase ⚠️
vercel/next.js canary Janpot/next.js basepath2 Change
_error.js 1.02 MB 1.02 MB
404.html 4.18 kB 4.18 kB
hooks.html 3.82 kB 3.82 kB
index.js 1.02 MB 1.02 MB
link.js 1.06 MB 1.06 MB ⚠️ +153 B
routerDirect.js 1.05 MB 1.05 MB ⚠️ +153 B
withRouter.js 1.05 MB 1.05 MB ⚠️ +153 B
Overall change 5.2 MB 5.2 MB ⚠️ +459 B
Commit: 9354bd1

@Janpot Janpot marked this pull request as ready for review August 1, 2020 02:59
@kodiakhq kodiakhq bot merged commit 1b03342 into vercel:canary Aug 1, 2020
@Janpot Janpot deleted the basepath2 branch August 1, 2020 11:54
@tm1000 tm1000 mentioned this pull request Aug 5, 2020
LauraBeatris pushed a commit to LauraBeatris/next.js that referenced this pull request Sep 1, 2020
@vercel vercel locked as resolved and limited conversation to collaborators Jan 30, 2022
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.

When using rewrites, client asPath is sliced by the basePath's length even when basePath config is false
3 participants