-
Notifications
You must be signed in to change notification settings - Fork 26.7k
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 next/link can't jump to non-latin anchors #36430
Conversation
I have made it works for anchors in the same page, but got stuck with links from another page. Could anyone help me to work it out? Thanks. |
I think I figured it out. |
Failing test suitesCommit: 2900d7e
Expand output● Middleware base tests › production mode › should override with rewrite externally correctly
● Middleware base tests › production mode › should rewrite to Vercel
Read more about building and testing Next.js in contributing.md. |
Stats from current PRDefault Build (Increase detected
|
vercel/next.js canary | hulufei/next.js fix-11109 | Change | |
---|---|---|---|
buildDuration | 19.3s | 19.4s | |
buildDurationCached | 7.6s | 7.6s | |
nodeModulesSize | 479 MB | 479 MB |
Page Load Tests Overall increase ✓
vercel/next.js canary | hulufei/next.js fix-11109 | Change | |
---|---|---|---|
/ failed reqs | 0 | 0 | ✓ |
/ total time (seconds) | 5.172 | 5.107 | -0.06 |
/ avg req/sec | 483.34 | 489.48 | +6.14 |
/error-in-render failed reqs | 0 | 0 | ✓ |
/error-in-render total time (seconds) | 2 | 2.01 | |
/error-in-render avg req/sec | 1249.76 | 1243.78 |
Client Bundles (main, webpack) Overall increase ⚠️
vercel/next.js canary | hulufei/next.js fix-11109 | Change | |
---|---|---|---|
925.HASH.js gzip | 179 B | 179 B | ✓ |
framework-HASH.js gzip | 42 kB | 42 kB | ✓ |
main-HASH.js gzip | 29 kB | 29 kB | |
webpack-HASH.js gzip | 1.54 kB | 1.54 kB | ✓ |
Overall change | 72.7 kB | 72.8 kB |
Legacy Client Bundles (polyfills)
vercel/next.js canary | hulufei/next.js fix-11109 | Change | |
---|---|---|---|
polyfills-HASH.js gzip | 31 kB | 31 kB | ✓ |
Overall change | 31 kB | 31 kB | ✓ |
Client Pages
vercel/next.js canary | hulufei/next.js fix-11109 | Change | |
---|---|---|---|
_app-HASH.js gzip | 1.36 kB | 1.36 kB | ✓ |
_error-HASH.js gzip | 193 B | 193 B | ✓ |
amp-HASH.js gzip | 308 B | 308 B | ✓ |
css-HASH.js gzip | 327 B | 327 B | ✓ |
dynamic-HASH.js gzip | 2.71 kB | 2.71 kB | ✓ |
head-HASH.js gzip | 359 B | 359 B | ✓ |
hooks-HASH.js gzip | 920 B | 920 B | ✓ |
image-HASH.js gzip | 5.73 kB | 5.73 kB | ✓ |
index-HASH.js gzip | 263 B | 263 B | ✓ |
link-HASH.js gzip | 2.65 kB | 2.65 kB | ✓ |
routerDirect..HASH.js gzip | 320 B | 320 B | ✓ |
script-HASH.js gzip | 391 B | 391 B | ✓ |
withRouter-HASH.js gzip | 318 B | 318 B | ✓ |
85e02e95b279..7e3.css gzip | 107 B | 107 B | ✓ |
Overall change | 16 kB | 16 kB | ✓ |
Client Build Manifests
vercel/next.js canary | hulufei/next.js fix-11109 | Change | |
---|---|---|---|
_buildManifest.js gzip | 458 B | 458 B | ✓ |
Overall change | 458 B | 458 B | ✓ |
Rendered Page Sizes Overall decrease ✓
vercel/next.js canary | hulufei/next.js fix-11109 | Change | |
---|---|---|---|
index.html gzip | 533 B | 532 B | -1 B |
link.html gzip | 547 B | 546 B | -1 B |
withRouter.html gzip | 528 B | 527 B | -1 B |
Overall change | 1.61 kB | 1.6 kB | -3 B |
Diffs
Diff for main-HASH.js
@@ -5220,7 +5220,8 @@
isValidShallowRoute,
_scroll1,
shouldScroll,
- resetScroll;
+ resetScroll,
+ hashRegex;
return _runtimeJs.default.wrap(
function _callee$(_ctx) {
while (1)
@@ -5871,9 +5872,13 @@
as,
routeProps
);
+ hashRegex = /#.+$/;
+ if (shouldScroll && hashRegex.test(as)) {
+ _this.scrollToHash(as);
+ }
return _ctx.abrupt("return", true);
- case 164:
- _ctx.prev = 164;
+ case 166:
+ _ctx.prev = 166;
_ctx.t4 = _ctx["catch"](113);
if (
!(
@@ -5881,13 +5886,13 @@
_ctx.t4.cancelled
)
) {
- _ctx.next = 168;
+ _ctx.next = 170;
break;
}
return _ctx.abrupt("return", false);
- case 168:
+ case 170:
throw _ctx.t4;
- case 169:
+ case 171:
case "end":
return _ctx.stop();
}
@@ -5896,7 +5901,7 @@
null,
[
[39, 51],
- [113, 164],
+ [113, 166],
[135, 141]
]
);
@@ -6326,15 +6331,17 @@
window.scrollTo(0, 0);
return;
}
+ // Decode hash to make non-latin anchor works.
+ var rawHash = decodeURIComponent(hash);
// First we check if the element by id is found
- var idEl = document.getElementById(hash);
+ var idEl = document.getElementById(rawHash);
if (idEl) {
idEl.scrollIntoView();
return;
}
// If there's no element with the id, we check the `name` property
// To mirror browsers
- var nameEl = document.getElementsByName(hash)[0];
+ var nameEl = document.getElementsByName(rawHash)[0];
if (nameEl) {
nameEl.scrollIntoView();
}
Diff for index.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-d39b128be27dbb18.js"
+ src="/_next/static/chunks/main-7c48d7922fb4ac24.js"
defer=""
></script>
<script
Diff for link.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-d39b128be27dbb18.js"
+ src="/_next/static/chunks/main-7c48d7922fb4ac24.js"
defer=""
></script>
<script
Diff for withRouter.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-d39b128be27dbb18.js"
+ src="/_next/static/chunks/main-7c48d7922fb4ac24.js"
defer=""
></script>
<script
Default Build with SWC (Increase detected ⚠️ )
General Overall increase ⚠️
vercel/next.js canary | hulufei/next.js fix-11109 | Change | |
---|---|---|---|
buildDuration | 23.3s | 23.1s | -205ms |
buildDurationCached | 7.9s | 8s | |
nodeModulesSize | 479 MB | 479 MB |
Page Load Tests Overall increase ✓
vercel/next.js canary | hulufei/next.js fix-11109 | Change | |
---|---|---|---|
/ failed reqs | 0 | 0 | ✓ |
/ total time (seconds) | 5.418 | 5.399 | -0.02 |
/ avg req/sec | 461.39 | 463.04 | +1.65 |
/error-in-render failed reqs | 0 | 0 | ✓ |
/error-in-render total time (seconds) | 2.225 | 2.137 | -0.09 |
/error-in-render avg req/sec | 1123.69 | 1169.92 | +46.23 |
Client Bundles (main, webpack) Overall increase ⚠️
vercel/next.js canary | hulufei/next.js fix-11109 | Change | |
---|---|---|---|
925.HASH.js gzip | 178 B | 178 B | ✓ |
framework-HASH.js gzip | 42.7 kB | 42.7 kB | ✓ |
main-HASH.js gzip | 29.5 kB | 29.5 kB | |
webpack-HASH.js gzip | 1.54 kB | 1.54 kB | ✓ |
Overall change | 73.9 kB | 73.9 kB |
Legacy Client Bundles (polyfills)
vercel/next.js canary | hulufei/next.js fix-11109 | Change | |
---|---|---|---|
polyfills-HASH.js gzip | 31 kB | 31 kB | ✓ |
Overall change | 31 kB | 31 kB | ✓ |
Client Pages
vercel/next.js canary | hulufei/next.js fix-11109 | Change | |
---|---|---|---|
_app-HASH.js gzip | 1.35 kB | 1.35 kB | ✓ |
_error-HASH.js gzip | 179 B | 179 B | ✓ |
amp-HASH.js gzip | 311 B | 311 B | ✓ |
css-HASH.js gzip | 324 B | 324 B | ✓ |
dynamic-HASH.js gzip | 2.89 kB | 2.89 kB | ✓ |
head-HASH.js gzip | 357 B | 357 B | ✓ |
hooks-HASH.js gzip | 920 B | 920 B | ✓ |
image-HASH.js gzip | 5.82 kB | 5.82 kB | ✓ |
index-HASH.js gzip | 261 B | 261 B | ✓ |
link-HASH.js gzip | 2.78 kB | 2.78 kB | ✓ |
routerDirect..HASH.js gzip | 322 B | 322 B | ✓ |
script-HASH.js gzip | 392 B | 392 B | ✓ |
withRouter-HASH.js gzip | 317 B | 317 B | ✓ |
85e02e95b279..7e3.css gzip | 107 B | 107 B | ✓ |
Overall change | 16.3 kB | 16.3 kB | ✓ |
Client Build Manifests
vercel/next.js canary | hulufei/next.js fix-11109 | Change | |
---|---|---|---|
_buildManifest.js gzip | 457 B | 457 B | ✓ |
Overall change | 457 B | 457 B | ✓ |
Rendered Page Sizes Overall increase ⚠️
vercel/next.js canary | hulufei/next.js fix-11109 | Change | |
---|---|---|---|
index.html gzip | 532 B | 533 B | |
link.html gzip | 546 B | 547 B | |
withRouter.html gzip | 528 B | 529 B | |
Overall change | 1.61 kB | 1.61 kB |
Diffs
Diff for main-HASH.js
@@ -5220,7 +5220,8 @@
isValidShallowRoute,
_scroll1,
shouldScroll,
- resetScroll;
+ resetScroll,
+ hashRegex;
return _runtimeJs.default.wrap(
function _callee$(_ctx) {
while (1)
@@ -5871,9 +5872,13 @@
as,
routeProps
);
+ hashRegex = /#.+$/;
+ if (shouldScroll && hashRegex.test(as)) {
+ _this.scrollToHash(as);
+ }
return _ctx.abrupt("return", true);
- case 164:
- _ctx.prev = 164;
+ case 166:
+ _ctx.prev = 166;
_ctx.t4 = _ctx["catch"](113);
if (
!(
@@ -5881,13 +5886,13 @@
_ctx.t4.cancelled
)
) {
- _ctx.next = 168;
+ _ctx.next = 170;
break;
}
return _ctx.abrupt("return", false);
- case 168:
+ case 170:
throw _ctx.t4;
- case 169:
+ case 171:
case "end":
return _ctx.stop();
}
@@ -5896,7 +5901,7 @@
null,
[
[39, 51],
- [113, 164],
+ [113, 166],
[135, 141]
]
);
@@ -6326,15 +6331,17 @@
window.scrollTo(0, 0);
return;
}
+ // Decode hash to make non-latin anchor works.
+ var rawHash = decodeURIComponent(hash);
// First we check if the element by id is found
- var idEl = document.getElementById(hash);
+ var idEl = document.getElementById(rawHash);
if (idEl) {
idEl.scrollIntoView();
return;
}
// If there's no element with the id, we check the `name` property
// To mirror browsers
- var nameEl = document.getElementsByName(hash)[0];
+ var nameEl = document.getElementsByName(rawHash)[0];
if (nameEl) {
nameEl.scrollIntoView();
}
Diff for index.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-d39b128be27dbb18.js"
+ src="/_next/static/chunks/main-7c48d7922fb4ac24.js"
defer=""
></script>
<script
Diff for link.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-d39b128be27dbb18.js"
+ src="/_next/static/chunks/main-7c48d7922fb4ac24.js"
defer=""
></script>
<script
Diff for withRouter.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-d39b128be27dbb18.js"
+ src="/_next/static/chunks/main-7c48d7922fb4ac24.js"
defer=""
></script>
<script
@ijjk Could you check it again? Thanks. |
It's weird, I checked the failing log, and didn't find any assert failures. I had run Anything I can do to continue? |
Thanks for the PR! |
fixes #11109
Bug
fixes #number
contributing.md
Feature
fixes #number
contributing.md
Documentation / Examples
yarn lint