-
Notifications
You must be signed in to change notification settings - Fork 27k
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: Catch hash change errors, and emit a routeChangeError
event
#36828
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
icyJoseph
requested review from
timneutkens,
ijjk,
shuding and
huozhi
as code owners
May 11, 2022 07:07
Stats from current PRDefault Build (Increase detected
|
vercel/next.js canary | icyJoseph/next.js fix/handle-hash-change-error | Change | |
---|---|---|---|
buildDuration | 15.8s | 16.1s | |
buildDurationCached | 6.6s | 6.6s | -1ms |
nodeModulesSize | 478 MB | 478 MB |
Page Load Tests Overall decrease ⚠️
vercel/next.js canary | icyJoseph/next.js fix/handle-hash-change-error | Change | |
---|---|---|---|
/ failed reqs | 0 | 0 | ✓ |
/ total time (seconds) | 3.848 | 3.862 | |
/ avg req/sec | 649.7 | 647.39 | |
/error-in-render failed reqs | 0 | 0 | ✓ |
/error-in-render total time (seconds) | 1.346 | 1.368 | |
/error-in-render avg req/sec | 1857.55 | 1827.66 |
Client Bundles (main, webpack) Overall increase ⚠️
vercel/next.js canary | icyJoseph/next.js fix/handle-hash-change-error | Change | |
---|---|---|---|
925.HASH.js gzip | 179 B | 179 B | ✓ |
framework-HASH.js gzip | 42 kB | 42 kB | ✓ |
main-HASH.js gzip | 28.7 kB | 28.8 kB | |
webpack-HASH.js gzip | 1.44 kB | 1.44 kB | ✓ |
Overall change | 72.4 kB | 72.5 kB |
Legacy Client Bundles (polyfills)
vercel/next.js canary | icyJoseph/next.js fix/handle-hash-change-error | Change | |
---|---|---|---|
polyfills-HASH.js gzip | 31 kB | 31 kB | ✓ |
Overall change | 31 kB | 31 kB | ✓ |
Client Pages
vercel/next.js canary | icyJoseph/next.js fix/handle-hash-change-error | 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.7 kB | 2.7 kB | ✓ |
head-HASH.js gzip | 359 B | 359 B | ✓ |
hooks-HASH.js gzip | 920 B | 920 B | ✓ |
image-HASH.js gzip | 5.71 kB | 5.71 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 | 15.9 kB | 15.9 kB | ✓ |
Client Build Manifests
vercel/next.js canary | icyJoseph/next.js fix/handle-hash-change-error | Change | |
---|---|---|---|
_buildManifest.js gzip | 458 B | 458 B | ✓ |
Overall change | 458 B | 458 B | ✓ |
Rendered Page Sizes Overall decrease ✓
vercel/next.js canary | icyJoseph/next.js fix/handle-hash-change-error | Change | |
---|---|---|---|
index.html gzip | 532 B | 532 B | ✓ |
link.html gzip | 544 B | 543 B | -1 B |
withRouter.html gzip | 528 B | 527 B | -1 B |
Overall change | 1.6 kB | 1.6 kB | -2 B |
Diffs
Diff for main-HASH.js
@@ -5355,7 +5355,7 @@
!localeChange
)
) {
- _ctx.next = 36;
+ _ctx.next = 46;
break;
}
nextState.asPath = cleanedAs;
@@ -5376,49 +5376,76 @@
if (scroll) {
_this.scrollToHash(cleanedAs);
}
- _this.set(
+ _ctx.prev = 33;
+ _ctx.next = 36;
+ return _this.set(
nextState,
_this.components[nextState.route],
null
);
+ case 36:
+ _ctx.next = 44;
+ break;
+ case 38:
+ _ctx.prev = 38;
+ _ctx.t0 = _ctx["catch"](33);
+ if (
+ !(
+ (0, _isError).default(_ctx.t0) &&
+ _ctx.t0.cancelled
+ )
+ ) {
+ _ctx.next = 43;
+ break;
+ }
+ Router.events.emit(
+ "routeChangeError",
+ _ctx.t0,
+ cleanedAs,
+ routeProps
+ );
+ return _ctx.abrupt("return", false);
+ case 43:
+ throw _ctx.t0;
+ case 44:
Router.events.emit(
"hashChangeComplete",
as,
routeProps
);
return _ctx.abrupt("return", true);
- case 36:
+ case 46:
parsed = (0, _parseRelativeUrl).parseRelativeUrl(
url
);
(pathname = parsed.pathname),
(query = parsed.query);
- _ctx.prev = 39;
- _ctx.t0 = _slicedToArray;
- _ctx.next = 44;
+ _ctx.prev = 49;
+ _ctx.t1 = _slicedToArray;
+ _ctx.next = 54;
return Promise.all([
_this.pageLoader.getPageList(),
(0, _routeLoader).getClientBuildManifest(),
_this.pageLoader.getMiddlewareList()
]);
- case 44:
- _ctx.t1 = _ctx.sent;
- ref1 = (0, _ctx.t0)(_ctx.t1, 2);
+ case 54:
+ _ctx.t2 = _ctx.sent;
+ ref1 = (0, _ctx.t1)(_ctx.t2, 2);
pages = ref1[0];
(ref2 = ref1[1]),
(rewrites = ref2.__rewrites),
ref2;
ref1;
- _ctx.next = 55;
+ _ctx.next = 65;
break;
- case 51:
- _ctx.prev = 51;
- _ctx.t2 = _ctx["catch"](39);
+ case 61:
+ _ctx.prev = 61;
+ _ctx.t3 = _ctx["catch"](49);
// If we fail to resolve the page list or client-build manifest, we must
// do a server-side transition:
window.location.href = as;
return _ctx.abrupt("return", false);
- case 55:
+ case 65:
// 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
@@ -5440,12 +5467,12 @@
if (
!(shouldResolveHref && pathname !== "/_error")
) {
- _ctx.next = 70;
+ _ctx.next = 80;
break;
}
options._shouldResolveHref = true;
if (true) {
- _ctx.next = 69;
+ _ctx.next = 79;
break;
}
rewritesResult = (0, _resolveRewrites).default(
@@ -5462,12 +5489,12 @@
_this.locales
);
if (!rewritesResult.externalDest) {
- _ctx.next = 65;
+ _ctx.next = 75;
break;
}
location.href = as;
return _ctx.abrupt("return", true);
- case 65:
+ case 75:
resolvedAs = rewritesResult.asPath;
if (
rewritesResult.matchedPage &&
@@ -5481,9 +5508,9 @@
parsed
);
}
- _ctx.next = 70;
+ _ctx.next = 80;
break;
- case 69: {
+ case 79: {
parsed.pathname = resolveDynamicRoute(
pathname,
pages
@@ -5496,13 +5523,13 @@
);
}
}
- case 70:
+ case 80:
if (isLocalURL(as)) {
- _ctx.next = 75;
+ _ctx.next = 85;
break;
}
if (true) {
- _ctx.next = 73;
+ _ctx.next = 83;
break;
}
throw new Error(
@@ -5514,10 +5541,10 @@
) +
"\nSee more info: https://nextjs.org/docs/messages/invalid-relative-url-external-as"
);
- case 73:
+ case 83:
window.location.href = as;
return _ctx.abrupt("return", false);
- case 75:
+ case 85:
resolvedAs = delLocale(
delBasePath(resolvedAs),
nextState.locale
@@ -5534,10 +5561,10 @@
))
)
) {
- _ctx.next = 96;
+ _ctx.next = 106;
break;
}
- _ctx.next = 79;
+ _ctx.next = 89;
return _this._preflightRequest({
as: as,
cache: "production" === "production",
@@ -5547,10 +5574,10 @@
locale: nextState.locale,
isPreview: nextState.isPreview
});
- case 79:
+ case 89:
effect = _ctx.sent;
if (!(effect.type === "rewrite")) {
- _ctx.next = 84;
+ _ctx.next = 94;
break;
}
{
@@ -5566,11 +5593,11 @@
parsed
);
}
- _ctx.next = 96;
+ _ctx.next = 106;
break;
- case 84:
+ case 94:
if (!(effect.type === "redirect" && effect.newAs)) {
- _ctx.next = 88;
+ _ctx.next = 98;
break;
}
return _ctx.abrupt(
@@ -5582,13 +5609,13 @@
options
)
);
- case 88:
+ case 98:
if (
!(
effect.type === "redirect" && effect.destination
)
) {
- _ctx.next = 93;
+ _ctx.next = 103;
break;
}
window.location.href = effect.destination;
@@ -5596,14 +5623,14 @@
"return",
new Promise(function() {})
);
- case 93:
+ case 103:
if (
!(
effect.type === "refresh" &&
as !== window.location.pathname
)
) {
- _ctx.next = 96;
+ _ctx.next = 106;
break;
}
window.location.href = as;
@@ -5611,13 +5638,13 @@
"return",
new Promise(function() {})
);
- case 96:
+ case 106:
route = (0,
_normalizeTrailingSlash).removePathTrailingSlash(
pathname
);
if (!(0, _isDynamic).isDynamicRoute(route)) {
- _ctx.next = 112;
+ _ctx.next = 122;
break;
}
parsedAs1 = (0, _parseRelativeUrl).parseRelativeUrl(
@@ -5638,7 +5665,7 @@
(shouldInterpolate && !interpolatedAs.result)
)
) {
- _ctx.next = 111;
+ _ctx.next = 121;
break;
}
missingParams = Object.keys(
@@ -5647,7 +5674,7 @@
return !query[param];
});
if (!(missingParams.length > 0)) {
- _ctx.next = 109;
+ _ctx.next = 119;
break;
}
if (false) {
@@ -5675,10 +5702,10 @@
: "incompatible-href-as"
)
);
- case 109:
- _ctx.next = 112;
+ case 119:
+ _ctx.next = 122;
break;
- case 111:
+ case 121:
if (shouldInterpolate) {
as = (0, _formatUrl).formatWithValidation(
Object.assign({}, parsedAs1, {
@@ -5693,14 +5720,14 @@
// Merge params into `query`, overwriting any specified in search
Object.assign(query, routeMatch);
}
- case 112:
+ case 122:
Router.events.emit(
"routeChangeStart",
as,
routeProps
);
- _ctx.prev = 113;
- _ctx.next = 117;
+ _ctx.prev = 123;
+ _ctx.next = 127;
return _this.getRouteInfo(
route,
pathname,
@@ -5711,7 +5738,7 @@
nextState.locale,
nextState.isPreview
);
- case 117:
+ case 127:
routeInfo = _ctx.sent;
(error = routeInfo.error),
(props = routeInfo.props),
@@ -5729,13 +5756,13 @@
});
}
if (!((__N_SSG || __N_SSP) && props)) {
- _ctx.next = 146;
+ _ctx.next = 156;
break;
}
if (
!(props.pageProps && props.pageProps.__N_REDIRECT)
) {
- _ctx.next = 131;
+ _ctx.next = 141;
break;
}
destination = props.pageProps.__N_REDIRECT;
@@ -5745,7 +5772,7 @@
props.pageProps.__N_REDIRECT_BASE_PATH !== false
)
) {
- _ctx.next = 129;
+ _ctx.next = 139;
break;
}
parsedHref = (0,
@@ -5765,31 +5792,31 @@
"return",
_this.change(method, newUrl, newAs, options)
);
- case 129:
+ case 139:
window.location.href = destination;
return _ctx.abrupt(
"return",
new Promise(function() {})
);
- case 131:
+ case 141:
nextState.isPreview = !!props.__N_PREVIEW;
if (!(props.notFound === SSG_DATA_NOT_FOUND)) {
- _ctx.next = 146;
+ _ctx.next = 156;
break;
}
- _ctx.prev = 134;
- _ctx.next = 137;
+ _ctx.prev = 144;
+ _ctx.next = 147;
return _this.fetchComponent("/404");
- case 137:
+ case 147:
notFoundRoute = "/404";
- _ctx.next = 143;
+ _ctx.next = 153;
break;
- case 140:
- _ctx.prev = 140;
- _ctx.t3 = _ctx["catch"](134);
+ case 150:
+ _ctx.prev = 150;
+ _ctx.t4 = _ctx["catch"](144);
notFoundRoute = "/_error";
- case 143:
- _ctx.next = 145;
+ case 153:
+ _ctx.next = 155;
return _this.getRouteInfo(
notFoundRoute,
notFoundRoute,
@@ -5802,9 +5829,9 @@
nextState.locale,
nextState.isPreview
);
- case 145:
+ case 155:
routeInfo = _ctx.sent;
- case 146:
+ case 156:
Router.events.emit(
"beforeHistoryChange",
as,
@@ -5842,7 +5869,7 @@
y: 0
}
: null;
- _ctx.next = 155;
+ _ctx.next = 165;
return _this
.set(
_objectSpread({}, nextState, {
@@ -5861,9 +5888,9 @@
if (e.cancelled) error = error || e;
else throw e;
});
- case 155:
+ case 165:
if (!error) {
- _ctx.next = 158;
+ _ctx.next = 168;
break;
}
Router.events.emit(
@@ -5873,7 +5900,7 @@
routeProps
);
throw error;
- case 158:
+ case 168:
if (false) {
}
Router.events.emit(
@@ -5882,22 +5909,22 @@
routeProps
);
return _ctx.abrupt("return", true);
- case 163:
- _ctx.prev = 163;
- _ctx.t4 = _ctx["catch"](113);
+ case 173:
+ _ctx.prev = 173;
+ _ctx.t5 = _ctx["catch"](123);
if (
!(
- (0, _isError).default(_ctx.t4) &&
- _ctx.t4.cancelled
+ (0, _isError).default(_ctx.t5) &&
+ _ctx.t5.cancelled
)
) {
- _ctx.next = 167;
+ _ctx.next = 177;
break;
}
return _ctx.abrupt("return", false);
- case 167:
- throw _ctx.t4;
- case 168:
+ case 177:
+ throw _ctx.t5;
+ case 178:
case "end":
return _ctx.stop();
}
@@ -5905,9 +5932,10 @@
_callee,
null,
[
- [39, 51],
- [113, 163],
- [134, 140]
+ [33, 38],
+ [49, 61],
+ [123, 173],
+ [144, 150]
]
);
})
Diff for index.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-157d3228bb171564.js"
+ src="/_next/static/chunks/main-a2d2d9cfd240ac1f.js"
defer=""
></script>
<script
Diff for link.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-157d3228bb171564.js"
+ src="/_next/static/chunks/main-a2d2d9cfd240ac1f.js"
defer=""
></script>
<script
Diff for withRouter.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-157d3228bb171564.js"
+ src="/_next/static/chunks/main-a2d2d9cfd240ac1f.js"
defer=""
></script>
<script
Default Build with SWC (Increase detected ⚠️ )
General Overall increase ⚠️
vercel/next.js canary | icyJoseph/next.js fix/handle-hash-change-error | Change | |
---|---|---|---|
buildDuration | 18.8s | 22.9s | |
buildDurationCached | 6.5s | 6.6s | |
nodeModulesSize | 478 MB | 478 MB |
Page Load Tests Overall decrease ⚠️
vercel/next.js canary | icyJoseph/next.js fix/handle-hash-change-error | Change | |
---|---|---|---|
/ failed reqs | 0 | 0 | ✓ |
/ total time (seconds) | 3.89 | 3.855 | -0.04 |
/ avg req/sec | 642.73 | 648.53 | +5.8 |
/error-in-render failed reqs | 0 | 0 | ✓ |
/error-in-render total time (seconds) | 1.352 | 1.361 | |
/error-in-render avg req/sec | 1848.79 | 1837.42 |
Client Bundles (main, webpack) Overall increase ⚠️
vercel/next.js canary | icyJoseph/next.js fix/handle-hash-change-error | Change | |
---|---|---|---|
925.HASH.js gzip | 178 B | 178 B | ✓ |
framework-HASH.js gzip | 42.7 kB | 42.7 kB | ✓ |
main-HASH.js gzip | 29.2 kB | 29.3 kB | |
webpack-HASH.js gzip | 1.45 kB | 1.45 kB | ✓ |
Overall change | 73.5 kB | 73.6 kB |
Legacy Client Bundles (polyfills)
vercel/next.js canary | icyJoseph/next.js fix/handle-hash-change-error | Change | |
---|---|---|---|
polyfills-HASH.js gzip | 31 kB | 31 kB | ✓ |
Overall change | 31 kB | 31 kB | ✓ |
Client Pages
vercel/next.js canary | icyJoseph/next.js fix/handle-hash-change-error | 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.8 kB | 5.8 kB | ✓ |
index-HASH.js gzip | 261 B | 261 B | ✓ |
link-HASH.js gzip | 2.77 kB | 2.77 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 | icyJoseph/next.js fix/handle-hash-change-error | Change | |
---|---|---|---|
_buildManifest.js gzip | 457 B | 457 B | ✓ |
Overall change | 457 B | 457 B | ✓ |
Rendered Page Sizes
vercel/next.js canary | icyJoseph/next.js fix/handle-hash-change-error | Change | |
---|---|---|---|
index.html gzip | 532 B | 532 B | ✓ |
link.html gzip | 547 B | 547 B | ✓ |
withRouter.html gzip | 528 B | 528 B | ✓ |
Overall change | 1.61 kB | 1.61 kB | ✓ |
Diffs
Diff for main-HASH.js
@@ -5355,7 +5355,7 @@
!localeChange
)
) {
- _ctx.next = 36;
+ _ctx.next = 46;
break;
}
nextState.asPath = cleanedAs;
@@ -5376,49 +5376,76 @@
if (scroll) {
_this.scrollToHash(cleanedAs);
}
- _this.set(
+ _ctx.prev = 33;
+ _ctx.next = 36;
+ return _this.set(
nextState,
_this.components[nextState.route],
null
);
+ case 36:
+ _ctx.next = 44;
+ break;
+ case 38:
+ _ctx.prev = 38;
+ _ctx.t0 = _ctx["catch"](33);
+ if (
+ !(
+ (0, _isError).default(_ctx.t0) &&
+ _ctx.t0.cancelled
+ )
+ ) {
+ _ctx.next = 43;
+ break;
+ }
+ Router.events.emit(
+ "routeChangeError",
+ _ctx.t0,
+ cleanedAs,
+ routeProps
+ );
+ return _ctx.abrupt("return", false);
+ case 43:
+ throw _ctx.t0;
+ case 44:
Router.events.emit(
"hashChangeComplete",
as,
routeProps
);
return _ctx.abrupt("return", true);
- case 36:
+ case 46:
parsed = (0, _parseRelativeUrl).parseRelativeUrl(
url
);
(pathname = parsed.pathname),
(query = parsed.query);
- _ctx.prev = 39;
- _ctx.t0 = _slicedToArray;
- _ctx.next = 44;
+ _ctx.prev = 49;
+ _ctx.t1 = _slicedToArray;
+ _ctx.next = 54;
return Promise.all([
_this.pageLoader.getPageList(),
(0, _routeLoader).getClientBuildManifest(),
_this.pageLoader.getMiddlewareList()
]);
- case 44:
- _ctx.t1 = _ctx.sent;
- ref1 = (0, _ctx.t0)(_ctx.t1, 2);
+ case 54:
+ _ctx.t2 = _ctx.sent;
+ ref1 = (0, _ctx.t1)(_ctx.t2, 2);
pages = ref1[0];
(ref2 = ref1[1]),
(rewrites = ref2.__rewrites),
ref2;
ref1;
- _ctx.next = 55;
+ _ctx.next = 65;
break;
- case 51:
- _ctx.prev = 51;
- _ctx.t2 = _ctx["catch"](39);
+ case 61:
+ _ctx.prev = 61;
+ _ctx.t3 = _ctx["catch"](49);
// If we fail to resolve the page list or client-build manifest, we must
// do a server-side transition:
window.location.href = as;
return _ctx.abrupt("return", false);
- case 55:
+ case 65:
// 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
@@ -5440,12 +5467,12 @@
if (
!(shouldResolveHref && pathname !== "/_error")
) {
- _ctx.next = 70;
+ _ctx.next = 80;
break;
}
options._shouldResolveHref = true;
if (true) {
- _ctx.next = 69;
+ _ctx.next = 79;
break;
}
rewritesResult = (0, _resolveRewrites).default(
@@ -5462,12 +5489,12 @@
_this.locales
);
if (!rewritesResult.externalDest) {
- _ctx.next = 65;
+ _ctx.next = 75;
break;
}
location.href = as;
return _ctx.abrupt("return", true);
- case 65:
+ case 75:
resolvedAs = rewritesResult.asPath;
if (
rewritesResult.matchedPage &&
@@ -5481,9 +5508,9 @@
parsed
);
}
- _ctx.next = 70;
+ _ctx.next = 80;
break;
- case 69: {
+ case 79: {
parsed.pathname = resolveDynamicRoute(
pathname,
pages
@@ -5496,13 +5523,13 @@
);
}
}
- case 70:
+ case 80:
if (isLocalURL(as)) {
- _ctx.next = 75;
+ _ctx.next = 85;
break;
}
if (true) {
- _ctx.next = 73;
+ _ctx.next = 83;
break;
}
throw new Error(
@@ -5514,10 +5541,10 @@
) +
"\nSee more info: https://nextjs.org/docs/messages/invalid-relative-url-external-as"
);
- case 73:
+ case 83:
window.location.href = as;
return _ctx.abrupt("return", false);
- case 75:
+ case 85:
resolvedAs = delLocale(
delBasePath(resolvedAs),
nextState.locale
@@ -5534,10 +5561,10 @@
))
)
) {
- _ctx.next = 96;
+ _ctx.next = 106;
break;
}
- _ctx.next = 79;
+ _ctx.next = 89;
return _this._preflightRequest({
as: as,
cache: "production" === "production",
@@ -5547,10 +5574,10 @@
locale: nextState.locale,
isPreview: nextState.isPreview
});
- case 79:
+ case 89:
effect = _ctx.sent;
if (!(effect.type === "rewrite")) {
- _ctx.next = 84;
+ _ctx.next = 94;
break;
}
{
@@ -5566,11 +5593,11 @@
parsed
);
}
- _ctx.next = 96;
+ _ctx.next = 106;
break;
- case 84:
+ case 94:
if (!(effect.type === "redirect" && effect.newAs)) {
- _ctx.next = 88;
+ _ctx.next = 98;
break;
}
return _ctx.abrupt(
@@ -5582,13 +5609,13 @@
options
)
);
- case 88:
+ case 98:
if (
!(
effect.type === "redirect" && effect.destination
)
) {
- _ctx.next = 93;
+ _ctx.next = 103;
break;
}
window.location.href = effect.destination;
@@ -5596,14 +5623,14 @@
"return",
new Promise(function() {})
);
- case 93:
+ case 103:
if (
!(
effect.type === "refresh" &&
as !== window.location.pathname
)
) {
- _ctx.next = 96;
+ _ctx.next = 106;
break;
}
window.location.href = as;
@@ -5611,13 +5638,13 @@
"return",
new Promise(function() {})
);
- case 96:
+ case 106:
route = (0,
_normalizeTrailingSlash).removePathTrailingSlash(
pathname
);
if (!(0, _isDynamic).isDynamicRoute(route)) {
- _ctx.next = 112;
+ _ctx.next = 122;
break;
}
parsedAs1 = (0, _parseRelativeUrl).parseRelativeUrl(
@@ -5638,7 +5665,7 @@
(shouldInterpolate && !interpolatedAs.result)
)
) {
- _ctx.next = 111;
+ _ctx.next = 121;
break;
}
missingParams = Object.keys(
@@ -5647,7 +5674,7 @@
return !query[param];
});
if (!(missingParams.length > 0)) {
- _ctx.next = 109;
+ _ctx.next = 119;
break;
}
if (false) {
@@ -5675,10 +5702,10 @@
: "incompatible-href-as"
)
);
- case 109:
- _ctx.next = 112;
+ case 119:
+ _ctx.next = 122;
break;
- case 111:
+ case 121:
if (shouldInterpolate) {
as = (0, _formatUrl).formatWithValidation(
Object.assign({}, parsedAs1, {
@@ -5693,14 +5720,14 @@
// Merge params into `query`, overwriting any specified in search
Object.assign(query, routeMatch);
}
- case 112:
+ case 122:
Router.events.emit(
"routeChangeStart",
as,
routeProps
);
- _ctx.prev = 113;
- _ctx.next = 117;
+ _ctx.prev = 123;
+ _ctx.next = 127;
return _this.getRouteInfo(
route,
pathname,
@@ -5711,7 +5738,7 @@
nextState.locale,
nextState.isPreview
);
- case 117:
+ case 127:
routeInfo = _ctx.sent;
(error = routeInfo.error),
(props = routeInfo.props),
@@ -5729,13 +5756,13 @@
});
}
if (!((__N_SSG || __N_SSP) && props)) {
- _ctx.next = 146;
+ _ctx.next = 156;
break;
}
if (
!(props.pageProps && props.pageProps.__N_REDIRECT)
) {
- _ctx.next = 131;
+ _ctx.next = 141;
break;
}
destination = props.pageProps.__N_REDIRECT;
@@ -5745,7 +5772,7 @@
props.pageProps.__N_REDIRECT_BASE_PATH !== false
)
) {
- _ctx.next = 129;
+ _ctx.next = 139;
break;
}
parsedHref = (0,
@@ -5765,31 +5792,31 @@
"return",
_this.change(method, newUrl, newAs, options)
);
- case 129:
+ case 139:
window.location.href = destination;
return _ctx.abrupt(
"return",
new Promise(function() {})
);
- case 131:
+ case 141:
nextState.isPreview = !!props.__N_PREVIEW;
if (!(props.notFound === SSG_DATA_NOT_FOUND)) {
- _ctx.next = 146;
+ _ctx.next = 156;
break;
}
- _ctx.prev = 134;
- _ctx.next = 137;
+ _ctx.prev = 144;
+ _ctx.next = 147;
return _this.fetchComponent("/404");
- case 137:
+ case 147:
notFoundRoute = "/404";
- _ctx.next = 143;
+ _ctx.next = 153;
break;
- case 140:
- _ctx.prev = 140;
- _ctx.t3 = _ctx["catch"](134);
+ case 150:
+ _ctx.prev = 150;
+ _ctx.t4 = _ctx["catch"](144);
notFoundRoute = "/_error";
- case 143:
- _ctx.next = 145;
+ case 153:
+ _ctx.next = 155;
return _this.getRouteInfo(
notFoundRoute,
notFoundRoute,
@@ -5802,9 +5829,9 @@
nextState.locale,
nextState.isPreview
);
- case 145:
+ case 155:
routeInfo = _ctx.sent;
- case 146:
+ case 156:
Router.events.emit(
"beforeHistoryChange",
as,
@@ -5842,7 +5869,7 @@
y: 0
}
: null;
- _ctx.next = 155;
+ _ctx.next = 165;
return _this
.set(
_objectSpread({}, nextState, {
@@ -5861,9 +5888,9 @@
if (e.cancelled) error = error || e;
else throw e;
});
- case 155:
+ case 165:
if (!error) {
- _ctx.next = 158;
+ _ctx.next = 168;
break;
}
Router.events.emit(
@@ -5873,7 +5900,7 @@
routeProps
);
throw error;
- case 158:
+ case 168:
if (false) {
}
Router.events.emit(
@@ -5882,22 +5909,22 @@
routeProps
);
return _ctx.abrupt("return", true);
- case 163:
- _ctx.prev = 163;
- _ctx.t4 = _ctx["catch"](113);
+ case 173:
+ _ctx.prev = 173;
+ _ctx.t5 = _ctx["catch"](123);
if (
!(
- (0, _isError).default(_ctx.t4) &&
- _ctx.t4.cancelled
+ (0, _isError).default(_ctx.t5) &&
+ _ctx.t5.cancelled
)
) {
- _ctx.next = 167;
+ _ctx.next = 177;
break;
}
return _ctx.abrupt("return", false);
- case 167:
- throw _ctx.t4;
- case 168:
+ case 177:
+ throw _ctx.t5;
+ case 178:
case "end":
return _ctx.stop();
}
@@ -5905,9 +5932,10 @@
_callee,
null,
[
- [39, 51],
- [113, 163],
- [134, 140]
+ [33, 38],
+ [49, 61],
+ [123, 173],
+ [144, 150]
]
);
})
Diff for index.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-157d3228bb171564.js"
+ src="/_next/static/chunks/main-a2d2d9cfd240ac1f.js"
defer=""
></script>
<script
Diff for link.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-157d3228bb171564.js"
+ src="/_next/static/chunks/main-a2d2d9cfd240ac1f.js"
defer=""
></script>
<script
Diff for withRouter.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-157d3228bb171564.js"
+ src="/_next/static/chunks/main-a2d2d9cfd240ac1f.js"
defer=""
></script>
<script
I'll try to go over the failed tests this weekend! However if someone wants to help, please do. |
ijjk
approved these changes
May 22, 2022
1 task
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #36830
Hi,
The discussion #36499, brought about an interesting case after a few weeks of exploration.
Under certain circumstances, it is possible to trigger route cancellation for
hash
urls. Here's an exact list of steps to trigger the error: #36499 (reply in thread).To sum up, on a two page setup,
/blog
and/
,starting from the/blog
page, go back to the/
page, and click a button which looks, either like:or
Would trigger an unhandled rejection, from
lastRenderReject
. I looked onto how this is normally cleaned, and it seems like it is not necessarily possible from thechangeState
method.I then looked at how non-hash urls handle this situation and noticed that the call to
this.set
is wrapped on a try/catch, andawait
'ed.I replicated the same for the hash url case, and now this, doesn't trigger any errors:
While, this snippet, still triggers an error, but it is handled.
I'll try to fill up the information down below throughout the day.
I am not sure if an integration test is warranted, nor how to go about creating one in this code base, will try to look it up as well.
Bug
fixes #36830
Documentation / Examples
yarn lint