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(Link): Do not ignore onMouseEnter prop with absolute href #32012

Merged
merged 2 commits into from
Dec 1, 2021

Conversation

ericmatthys
Copy link
Contributor

@ericmatthys ericmatthys commented Dec 1, 2021

Fixes #22733

Regardless of whether it's recommended that Link be used with external href values or not, they can be used and onMouseEnter being swallowed with an external href value is unexpected behavior.

Bug

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

Documentation / Examples

  • Make sure the linting passes by running yarn lint

Copy link
Member

@ijjk ijjk left a comment

Choose a reason for hiding this comment

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

Hi, can you add a test for this? It can go in this test suite

@ericmatthys
Copy link
Contributor Author

@ijjk I added a test. I wasn't sure where exactly it fit best since there weren't others like it, but let me know if it should be moved.

@ijjk
Copy link
Member

ijjk commented Dec 1, 2021

Stats from current PR

Default Build (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary ericmatthys/next.js external-link-mouse-enter Change
buildDuration 26.3s 26.5s ⚠️ +171ms
buildDurationCached 4.7s 4.6s -116ms
nodeModulesSize 347 MB 347 MB ⚠️ +25 B
Page Load Tests Overall increase ✓
vercel/next.js canary ericmatthys/next.js external-link-mouse-enter Change
/ failed reqs 0 0
/ total time (seconds) 4.267 4.342 ⚠️ +0.07
/ avg req/sec 585.88 575.83 ⚠️ -10.05
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 2.325 2.204 -0.12
/error-in-render avg req/sec 1075.37 1134.35 +58.98
Client Bundles (main, webpack, commons)
vercel/next.js canary ericmatthys/next.js external-link-mouse-enter Change
450.HASH.js gzip 179 B 179 B
framework-HASH.js gzip 42.2 kB 42.2 kB
main-HASH.js gzip 28.4 kB 28.4 kB
webpack-HASH.js gzip 1.45 kB 1.45 kB
Overall change 72.3 kB 72.3 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary ericmatthys/next.js external-link-mouse-enter Change
polyfills-HASH.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages Overall decrease ✓
vercel/next.js canary ericmatthys/next.js external-link-mouse-enter Change
_app-HASH.js gzip 1.37 kB 1.37 kB
_error-HASH.js gzip 194 B 194 B
amp-HASH.js gzip 312 B 312 B
css-HASH.js gzip 326 B 326 B
dynamic-HASH.js gzip 2.38 kB 2.38 kB
head-HASH.js gzip 350 B 350 B
hooks-HASH.js gzip 635 B 635 B
image-HASH.js gzip 4.49 kB 4.49 kB
index-HASH.js gzip 263 B 263 B
link-HASH.js gzip 1.87 kB 1.87 kB -4 B
routerDirect..HASH.js gzip 321 B 321 B
script-HASH.js gzip 383 B 383 B
withRouter-HASH.js gzip 318 B 318 B
85e02e95b279..7e3.css gzip 107 B 107 B
Overall change 13.3 kB 13.3 kB -4 B
Client Build Manifests
vercel/next.js canary ericmatthys/next.js external-link-mouse-enter Change
_buildManifest.js gzip 460 B 460 B
Overall change 460 B 460 B
Rendered Page Sizes Overall decrease ✓
vercel/next.js canary ericmatthys/next.js external-link-mouse-enter Change
index.html gzip 532 B 532 B
link.html gzip 546 B 545 B -1 B
withRouter.html gzip 527 B 527 B
Overall change 1.6 kB 1.6 kB -1 B

Diffs

Diff for _buildManifest.js
@@ -13,7 +13,7 @@ self.__BUILD_MANIFEST = {
   "/head": ["static\u002Fchunks\u002Fpages\u002Fhead-7100d3b2a548f0e4.js"],
   "/hooks": ["static\u002Fchunks\u002Fpages\u002Fhooks-ff60bc61acd2698b.js"],
   "/image": ["static\u002Fchunks\u002Fpages\u002Fimage-f207079640969086.js"],
-  "/link": ["static\u002Fchunks\u002Fpages\u002Flink-678af336607f5345.js"],
+  "/link": ["static\u002Fchunks\u002Fpages\u002Flink-b57fa5abc6a43d15.js"],
   "/routerDirect": [
     "static\u002Fchunks\u002Fpages\u002FrouterDirect-76232dd6bc335a24.js"
   ],
Diff for link-HASH.js
@@ -255,13 +255,14 @@
           }
         };
         childProps.onMouseEnter = function(e) {
-          if (!(0, _router).isLocalURL(href)) return;
           if (child.props && typeof child.props.onMouseEnter === "function") {
             child.props.onMouseEnter(e);
           }
-          prefetch(router, href, as, {
-            priority: true
-          });
+          if ((0, _router).isLocalURL(href)) {
+            prefetch(router, href, as, {
+              priority: true
+            });
+          }
         };
         // If child is an <a> tag and doesn't have a href attribute, or if the 'passHref' property is
         // defined, we specify the current 'href', so that repetition is not needed by the user
Diff for link.html
@@ -27,7 +27,7 @@
       defer=""
     ></script>
     <script
-      src="/_next/static/chunks/pages/link-678af336607f5345.js"
+      src="/_next/static/chunks/pages/link-b57fa5abc6a43d15.js"
       defer=""
     ></script>
     <script src="/_next/static/BUILD_ID/_buildManifest.js" defer=""></script>

Default Build with SWC (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary ericmatthys/next.js external-link-mouse-enter Change
buildDuration 28.6s 28.2s -326ms
buildDurationCached 4.7s 4.7s -8ms
nodeModulesSize 347 MB 347 MB ⚠️ +25 B
Page Load Tests Overall increase ✓
vercel/next.js canary ericmatthys/next.js external-link-mouse-enter Change
/ failed reqs 0 0
/ total time (seconds) 4.374 4.284 -0.09
/ avg req/sec 571.53 583.55 +12.02
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 2.324 2.245 -0.08
/error-in-render avg req/sec 1075.81 1113.79 +37.98
Client Bundles (main, webpack, commons)
vercel/next.js canary ericmatthys/next.js external-link-mouse-enter Change
450.HASH.js gzip 179 B 179 B
framework-HASH.js gzip 42.3 kB 42.3 kB
main-HASH.js gzip 28.6 kB 28.6 kB
webpack-HASH.js gzip 1.44 kB 1.44 kB
Overall change 72.5 kB 72.5 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary ericmatthys/next.js external-link-mouse-enter Change
polyfills-HASH.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages Overall decrease ✓
vercel/next.js canary ericmatthys/next.js external-link-mouse-enter Change
_app-HASH.js gzip 1.35 kB 1.35 kB
_error-HASH.js gzip 180 B 180 B
amp-HASH.js gzip 305 B 305 B
css-HASH.js gzip 321 B 321 B
dynamic-HASH.js gzip 2.37 kB 2.37 kB
head-HASH.js gzip 342 B 342 B
hooks-HASH.js gzip 622 B 622 B
image-HASH.js gzip 4.53 kB 4.53 kB
index-HASH.js gzip 256 B 256 B
link-HASH.js gzip 1.91 kB 1.9 kB -2 B
routerDirect..HASH.js gzip 314 B 314 B
script-HASH.js gzip 375 B 375 B
withRouter-HASH.js gzip 309 B 309 B
85e02e95b279..7e3.css gzip 107 B 107 B
Overall change 13.3 kB 13.3 kB -2 B
Client Build Manifests
vercel/next.js canary ericmatthys/next.js external-link-mouse-enter Change
_buildManifest.js gzip 458 B 458 B
Overall change 458 B 458 B
Rendered Page Sizes
vercel/next.js canary ericmatthys/next.js external-link-mouse-enter 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 _buildManifest.js
@@ -13,7 +13,7 @@ self.__BUILD_MANIFEST = {
   "/head": ["static\u002Fchunks\u002Fpages\u002Fhead-7100d3b2a548f0e4.js"],
   "/hooks": ["static\u002Fchunks\u002Fpages\u002Fhooks-ff60bc61acd2698b.js"],
   "/image": ["static\u002Fchunks\u002Fpages\u002Fimage-f207079640969086.js"],
-  "/link": ["static\u002Fchunks\u002Fpages\u002Flink-678af336607f5345.js"],
+  "/link": ["static\u002Fchunks\u002Fpages\u002Flink-b57fa5abc6a43d15.js"],
   "/routerDirect": [
     "static\u002Fchunks\u002Fpages\u002FrouterDirect-76232dd6bc335a24.js"
   ],
Diff for link-HASH.js
@@ -255,13 +255,14 @@
           }
         };
         childProps.onMouseEnter = function(e) {
-          if (!(0, _router).isLocalURL(href)) return;
           if (child.props && typeof child.props.onMouseEnter === "function") {
             child.props.onMouseEnter(e);
           }
-          prefetch(router, href, as, {
-            priority: true
-          });
+          if ((0, _router).isLocalURL(href)) {
+            prefetch(router, href, as, {
+              priority: true
+            });
+          }
         };
         // If child is an <a> tag and doesn't have a href attribute, or if the 'passHref' property is
         // defined, we specify the current 'href', so that repetition is not needed by the user
Diff for link.html
@@ -27,7 +27,7 @@
       defer=""
     ></script>
     <script
-      src="/_next/static/chunks/pages/link-678af336607f5345.js"
+      src="/_next/static/chunks/pages/link-b57fa5abc6a43d15.js"
       defer=""
     ></script>
     <script src="/_next/static/BUILD_ID/_buildManifest.js" defer=""></script>
Commit: b86fb43

Copy link
Member

@ijjk ijjk left a comment

Choose a reason for hiding this comment

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

Change and test look good, thanks for the PR!

@kodiakhq kodiakhq bot merged commit f225179 into vercel:canary Dec 1, 2021
@ericmatthys ericmatthys deleted the external-link-mouse-enter branch December 1, 2021 19:40
@vercel vercel locked as resolved and limited conversation to collaborators Jan 27, 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.

next/link: onMouseEnter etc. not called on inner <a> tag when href is external
2 participants