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

[next] Fix to not call middleware with shallow push, fix middleware call wit… #35047

Merged

Conversation

nkzawa
Copy link
Contributor

@nkzawa nkzawa commented Mar 4, 2022

…h query parameter

Fixes #32655 and fixes #35006

Bug

  • Related issues linked using fixes #number
  • Integration tests added
  • Errors have helpful link attached, see contributing.md

@ijjk ijjk added the type: next label Mar 4, 2022
@nkzawa nkzawa changed the title ix to not call middleware with shallow push, fix middleware call wit… [next] Fix to not call middleware with shallow push, fix middleware call wit… Mar 4, 2022
const cleanedAs = delLocale(
hasBasePath(options.as) ? delBasePath(options.as) : options.as,
hasBasePath(asPathname) ? delBasePath(asPathname) : asPathname,
Copy link
Contributor Author

@nkzawa nkzawa Mar 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix for #35006
It's fixed at the same time since it's needed for the added test

javivelasco
javivelasco previously approved these changes Mar 4, 2022
@ijjk
Copy link
Member

ijjk commented Mar 4, 2022

Failing test suites

Commit: 49c06bd

yarn testheadless test/integration/router-prefetch/test/index.test.js

  • Router prefetch > production mode > should resolve prefetch promise with invalid href
Expand output

● Router prefetch › production mode › should resolve prefetch promise with invalid href

page.waitForSelector: Timeout 30000ms exceeded.
=========================== logs ===========================
waiting for selector "#hidden-until-click"
============================================================

  304 |     return this.chain(() => {
  305 |       return page
> 306 |         .waitForSelector(selector, { timeout, state: 'attached' })
      |          ^
  307 |         .then(async (el) => {
  308 |           // it seems selenium waits longer and tests rely on this behavior
  309 |           // so we wait for the load event fire before returning

  at lib/browsers/playwright.ts:306:10
  at didResolveAfterPrefetch (integration/router-prefetch/test/index.test.js:19:16)
  at Object.<anonymous> (integration/router-prefetch/test/index.test.js:61:7)

Read more about building and testing Next.js in contributing.md.

@ijjk

This comment has been minimized.

@nkzawa nkzawa requested a review from javivelasco March 8, 2022 07:02
@ijjk

This comment has been minimized.

@kodiakhq kodiakhq bot merged commit d141376 into vercel:canary Mar 8, 2022
@ijjk
Copy link
Member

ijjk commented Mar 8, 2022

Stats from current PR

Default Build (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary nkzawa/next.js fix-do-not-call-middleware-with-shallow-push Change
buildDuration 15.1s 15.1s -35ms
buildDurationCached 6s 6.1s ⚠️ +38ms
nodeModulesSize 372 MB 372 MB ⚠️ +179 B
Page Load Tests Overall decrease ⚠️
vercel/next.js canary nkzawa/next.js fix-do-not-call-middleware-with-shallow-push Change
/ failed reqs 0 0
/ total time (seconds) 2.914 2.94 ⚠️ +0.03
/ avg req/sec 857.82 850.3 ⚠️ -7.52
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.16 1.175 ⚠️ +0.02
/error-in-render avg req/sec 2155.67 2127.4 ⚠️ -28.27
Client Bundles (main, webpack) Overall increase ⚠️
vercel/next.js canary nkzawa/next.js fix-do-not-call-middleware-with-shallow-push Change
925.HASH.js gzip 179 B 179 B
framework-HASH.js gzip 42 kB 42 kB
main-HASH.js gzip 27.9 kB 27.9 kB ⚠️ +8 B
webpack-HASH.js gzip 1.44 kB 1.44 kB
Overall change 71.5 kB 71.5 kB ⚠️ +8 B
Legacy Client Bundles (polyfills)
vercel/next.js canary nkzawa/next.js fix-do-not-call-middleware-with-shallow-push Change
polyfills-HASH.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary nkzawa/next.js fix-do-not-call-middleware-with-shallow-push 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 2.57 kB 2.57 kB
head-HASH.js gzip 351 B 351 B
hooks-HASH.js gzip 920 B 920 B
image-HASH.js gzip 5.09 kB 5.09 kB
index-HASH.js gzip 263 B 263 B
link-HASH.js gzip 2.26 kB 2.26 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 14.8 kB 14.8 kB
Client Build Manifests
vercel/next.js canary nkzawa/next.js fix-do-not-call-middleware-with-shallow-push Change
_buildManifest.js gzip 460 B 460 B
Overall change 460 B 460 B
Rendered Page Sizes Overall decrease ✓
vercel/next.js canary nkzawa/next.js fix-do-not-call-middleware-with-shallow-push Change
index.html gzip 531 B 530 B -1 B
link.html gzip 545 B 544 B -1 B
withRouter.html gzip 526 B 524 B -2 B
Overall change 1.6 kB 1.6 kB -4 B

Diffs

Diff for main-HASH.js
@@ -5302,13 +5302,14 @@
                             );
                             if (
                               !(
-                                options._h !== 1 ||
-                                (0, _isDynamic).isDynamicRoute(
-                                  (0,
-                                  _normalizeTrailingSlash).removePathTrailingSlash(
-                                    pathname
-                                  )
-                                )
+                                (!options.shallow || options._h === 1) &&
+                                (options._h !== 1 ||
+                                  (0, _isDynamic).isDynamicRoute(
+                                    (0,
+                                    _normalizeTrailingSlash).removePathTrailingSlash(
+                                      pathname
+                                    )
+                                  ))
                               )
                             ) {
                               _ctx.next = 96;
@@ -6371,7 +6372,8 @@
               var _this = this;
               return _asyncToGenerator(
                 _runtimeJs.default.mark(function _callee() {
-                  var cleanedAs,
+                  var asPathname,
+                    cleanedAs,
                     fns,
                     requiresPreflight,
                     preflight,
@@ -6387,15 +6389,16 @@
                     while (1)
                       switch ((_ctx.prev = _ctx.next)) {
                         case 0:
+                          asPathname = pathNoQueryHash(options.as);
                           cleanedAs = delLocale(
-                            hasBasePath(options.as)
-                              ? delBasePath(options.as)
-                              : options.as,
+                            hasBasePath(asPathname)
+                              ? delBasePath(asPathname)
+                              : asPathname,
                             options.locale
                           );
-                          _ctx.next = 3;
+                          _ctx.next = 4;
                           return _this.pageLoader.getMiddlewareList();
-                        case 3:
+                        case 4:
                           fns = _ctx.sent;
                           requiresPreflight = fns.some(function(param) {
                             var _param = _slicedToArray(param, 2),
@@ -6409,34 +6412,34 @@
                             )(cleanedAs);
                           });
                           if (requiresPreflight) {
-                            _ctx.next = 7;
+                            _ctx.next = 8;
                             break;
                           }
                           return _ctx.abrupt("return", {
                             type: "next"
                           });
-                        case 7:
-                          _ctx.next = 9;
+                        case 8:
+                          _ctx.next = 10;
                           return _this._getPreflightData({
                             preflightHref: options.as,
                             shouldCache: options.cache,
                             isPreview: options.isPreview
                           });
-                        case 9:
+                        case 10:
                           preflight = _ctx.sent;
                           if (!preflight.rewrite) {
-                            _ctx.next = 19;
+                            _ctx.next = 20;
                             break;
                           }
                           if (preflight.rewrite.startsWith("/")) {
-                            _ctx.next = 13;
+                            _ctx.next = 14;
                             break;
                           }
                           return _ctx.abrupt("return", {
                             type: "redirect",
                             destination: options.as
                           });
-                        case 13:
+                        case 14:
                           parsed = (0, _parseRelativeUrl).parseRelativeUrl(
                             (0, _normalizeLocalePath).normalizeLocalePath(
                               hasBasePath(preflight.rewrite)
@@ -6471,13 +6474,13 @@
                             matchedPage: matchedPage,
                             resolvedHref: resolvedHref
                           });
-                        case 19:
+                        case 20:
                           if (!preflight.redirect) {
-                            _ctx.next = 25;
+                            _ctx.next = 26;
                             break;
                           }
                           if (!preflight.redirect.startsWith("/")) {
-                            _ctx.next = 24;
+                            _ctx.next = 25;
                             break;
                           }
                           cleanRedirect = (0,
@@ -6501,24 +6504,24 @@
                             newUrl: newUrl,
                             newAs: newAs
                           });
-                        case 24:
+                        case 25:
                           return _ctx.abrupt("return", {
                             type: "redirect",
                             destination: preflight.redirect
                           });
-                        case 25:
+                        case 26:
                           if (!(preflight.refresh && !preflight.ssr)) {
-                            _ctx.next = 27;
+                            _ctx.next = 28;
                             break;
                           }
                           return _ctx.abrupt("return", {
                             type: "refresh"
                           });
-                        case 27:
+                        case 28:
                           return _ctx.abrupt("return", {
                             type: "next"
                           });
-                        case 28:
+                        case 29:
                         case "end":
                           return _ctx.stop();
                       }
Diff for index.html
@@ -19,7 +19,7 @@
       defer=""
     ></script>
     <script
-      src="/_next/static/chunks/main-a9622e10c1f28000.js"
+      src="/_next/static/chunks/main-5ef02dfc5c89364b.js"
       defer=""
     ></script>
     <script
Diff for link.html
@@ -19,7 +19,7 @@
       defer=""
     ></script>
     <script
-      src="/_next/static/chunks/main-a9622e10c1f28000.js"
+      src="/_next/static/chunks/main-5ef02dfc5c89364b.js"
       defer=""
     ></script>
     <script
Diff for withRouter.html
@@ -19,7 +19,7 @@
       defer=""
     ></script>
     <script
-      src="/_next/static/chunks/main-a9622e10c1f28000.js"
+      src="/_next/static/chunks/main-5ef02dfc5c89364b.js"
       defer=""
     ></script>
     <script

Default Build with SWC (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary nkzawa/next.js fix-do-not-call-middleware-with-shallow-push Change
buildDuration 18.4s 18.5s ⚠️ +86ms
buildDurationCached 6s 6s ⚠️ +8ms
nodeModulesSize 372 MB 372 MB ⚠️ +179 B
Page Load Tests Overall increase ✓
vercel/next.js canary nkzawa/next.js fix-do-not-call-middleware-with-shallow-push Change
/ failed reqs 0 0
/ total time (seconds) 2.924 2.921 0
/ avg req/sec 854.95 855.91 +0.96
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.2 1.199 0
/error-in-render avg req/sec 2082.97 2085.43 +2.46
Client Bundles (main, webpack) Overall increase ⚠️
vercel/next.js canary nkzawa/next.js fix-do-not-call-middleware-with-shallow-push Change
925.HASH.js gzip 178 B 178 B
framework-HASH.js gzip 42.3 kB 42.3 kB
main-HASH.js gzip 28.2 kB 28.2 kB ⚠️ +17 B
webpack-HASH.js gzip 1.45 kB 1.45 kB
Overall change 72.1 kB 72.1 kB ⚠️ +17 B
Legacy Client Bundles (polyfills)
vercel/next.js canary nkzawa/next.js fix-do-not-call-middleware-with-shallow-push Change
polyfills-HASH.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary nkzawa/next.js fix-do-not-call-middleware-with-shallow-push 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 324 B 324 B
dynamic-HASH.js gzip 2.56 kB 2.56 kB
head-HASH.js gzip 351 B 351 B
hooks-HASH.js gzip 921 B 921 B
image-HASH.js gzip 5.23 kB 5.23 kB
index-HASH.js gzip 261 B 261 B
link-HASH.js gzip 2.33 kB 2.33 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 kB 15 kB
Client Build Manifests
vercel/next.js canary nkzawa/next.js fix-do-not-call-middleware-with-shallow-push Change
_buildManifest.js gzip 459 B 459 B
Overall change 459 B 459 B
Rendered Page Sizes Overall increase ⚠️
vercel/next.js canary nkzawa/next.js fix-do-not-call-middleware-with-shallow-push Change
index.html gzip 530 B 532 B ⚠️ +2 B
link.html gzip 544 B 546 B ⚠️ +2 B
withRouter.html gzip 525 B 527 B ⚠️ +2 B
Overall change 1.6 kB 1.6 kB ⚠️ +6 B

Diffs

Diff for main-HASH.js
@@ -5302,13 +5302,14 @@
                             );
                             if (
                               !(
-                                options._h !== 1 ||
-                                (0, _isDynamic).isDynamicRoute(
-                                  (0,
-                                  _normalizeTrailingSlash).removePathTrailingSlash(
-                                    pathname
-                                  )
-                                )
+                                (!options.shallow || options._h === 1) &&
+                                (options._h !== 1 ||
+                                  (0, _isDynamic).isDynamicRoute(
+                                    (0,
+                                    _normalizeTrailingSlash).removePathTrailingSlash(
+                                      pathname
+                                    )
+                                  ))
                               )
                             ) {
                               _ctx.next = 96;
@@ -6371,7 +6372,8 @@
               var _this = this;
               return _asyncToGenerator(
                 _runtimeJs.default.mark(function _callee() {
-                  var cleanedAs,
+                  var asPathname,
+                    cleanedAs,
                     fns,
                     requiresPreflight,
                     preflight,
@@ -6387,15 +6389,16 @@
                     while (1)
                       switch ((_ctx.prev = _ctx.next)) {
                         case 0:
+                          asPathname = pathNoQueryHash(options.as);
                           cleanedAs = delLocale(
-                            hasBasePath(options.as)
-                              ? delBasePath(options.as)
-                              : options.as,
+                            hasBasePath(asPathname)
+                              ? delBasePath(asPathname)
+                              : asPathname,
                             options.locale
                           );
-                          _ctx.next = 3;
+                          _ctx.next = 4;
                           return _this.pageLoader.getMiddlewareList();
-                        case 3:
+                        case 4:
                           fns = _ctx.sent;
                           requiresPreflight = fns.some(function(param) {
                             var _param = _slicedToArray(param, 2),
@@ -6409,34 +6412,34 @@
                             )(cleanedAs);
                           });
                           if (requiresPreflight) {
-                            _ctx.next = 7;
+                            _ctx.next = 8;
                             break;
                           }
                           return _ctx.abrupt("return", {
                             type: "next"
                           });
-                        case 7:
-                          _ctx.next = 9;
+                        case 8:
+                          _ctx.next = 10;
                           return _this._getPreflightData({
                             preflightHref: options.as,
                             shouldCache: options.cache,
                             isPreview: options.isPreview
                           });
-                        case 9:
+                        case 10:
                           preflight = _ctx.sent;
                           if (!preflight.rewrite) {
-                            _ctx.next = 19;
+                            _ctx.next = 20;
                             break;
                           }
                           if (preflight.rewrite.startsWith("/")) {
-                            _ctx.next = 13;
+                            _ctx.next = 14;
                             break;
                           }
                           return _ctx.abrupt("return", {
                             type: "redirect",
                             destination: options.as
                           });
-                        case 13:
+                        case 14:
                           parsed = (0, _parseRelativeUrl).parseRelativeUrl(
                             (0, _normalizeLocalePath).normalizeLocalePath(
                               hasBasePath(preflight.rewrite)
@@ -6471,13 +6474,13 @@
                             matchedPage: matchedPage,
                             resolvedHref: resolvedHref
                           });
-                        case 19:
+                        case 20:
                           if (!preflight.redirect) {
-                            _ctx.next = 25;
+                            _ctx.next = 26;
                             break;
                           }
                           if (!preflight.redirect.startsWith("/")) {
-                            _ctx.next = 24;
+                            _ctx.next = 25;
                             break;
                           }
                           cleanRedirect = (0,
@@ -6501,24 +6504,24 @@
                             newUrl: newUrl,
                             newAs: newAs
                           });
-                        case 24:
+                        case 25:
                           return _ctx.abrupt("return", {
                             type: "redirect",
                             destination: preflight.redirect
                           });
-                        case 25:
+                        case 26:
                           if (!(preflight.refresh && !preflight.ssr)) {
-                            _ctx.next = 27;
+                            _ctx.next = 28;
                             break;
                           }
                           return _ctx.abrupt("return", {
                             type: "refresh"
                           });
-                        case 27:
+                        case 28:
                           return _ctx.abrupt("return", {
                             type: "next"
                           });
-                        case 28:
+                        case 29:
                         case "end":
                           return _ctx.stop();
                       }
Diff for index.html
@@ -19,7 +19,7 @@
       defer=""
     ></script>
     <script
-      src="/_next/static/chunks/main-a9622e10c1f28000.js"
+      src="/_next/static/chunks/main-5ef02dfc5c89364b.js"
       defer=""
     ></script>
     <script
Diff for link.html
@@ -19,7 +19,7 @@
       defer=""
     ></script>
     <script
-      src="/_next/static/chunks/main-a9622e10c1f28000.js"
+      src="/_next/static/chunks/main-5ef02dfc5c89364b.js"
       defer=""
     ></script>
     <script
Diff for withRouter.html
@@ -19,7 +19,7 @@
       defer=""
     ></script>
     <script
-      src="/_next/static/chunks/main-a9622e10c1f28000.js"
+      src="/_next/static/chunks/main-5ef02dfc5c89364b.js"
       defer=""
     ></script>
     <script
Commit: 1f270b1

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants