-
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
Wait for getFilesForRoute promise to fulfill before timeout in dev mode #27395
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
jarvelov
requested review from
huozhi,
ijjk,
padmaia,
shuding,
styfle and
timneutkens
as code owners
July 22, 2021 11:40
8 tasks
The fix in PR vercel#25749 only works some of the time. The reason why it doesn't work all of the time is because the `devBuildResolve` function is called when the assets have been built, but this can happen before the `getFilesForRoute` promise chain has completed, and thus the `cancelled` variable could not yet have been updated. To fix this we wait for the `getFilesForRoute` promise chain to be fulfilled and then resolve the `devBuildPromise` promise afterwards. This allows the `getFilesForRoute` promise chain to be fulfilled before and the `cancelled` variable can be updated accordingly. If an error is thrown somewhere in the `getFilesForRoute` promise chain, i.e. due to a failed fetch request, then that will also resolve the `devBuildPromise` and the error will bubble up to ultimately become a `routeChangeError` which will reload the page. With this fix the need to listen for HMR events has become obsolete as regardless of when the HMR build/sync events complete we still want to ensure that the `getFilesForRoute` promise chain has been fulfilled before resolving the `devBuildPromise`.
jarvelov
force-pushed
the
fix-route-loader-dev
branch
from
July 22, 2021 19:33
efe66b6
to
7162aff
Compare
This comment has been minimized.
This comment has been minimized.
titan800
approved these changes
Jul 23, 2021
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ijjk
approved these changes
Jul 23, 2021
Stats from current PRDefault Build (Increase detected
|
vercel/next.js canary | jarvelov/next.js fix-route-loader-dev | Change | |
---|---|---|---|
buildDuration | 14.7s | 15.1s | |
buildDurationCached | 3.3s | 3.3s | -28ms |
nodeModulesSize | 49.5 MB | 49.5 MB | -1.35 kB |
Page Load Tests Overall increase ✓
vercel/next.js canary | jarvelov/next.js fix-route-loader-dev | Change | |
---|---|---|---|
/ failed reqs | 0 | 0 | ✓ |
/ total time (seconds) | 2.562 | 2.407 | -0.15 |
/ avg req/sec | 975.64 | 1038.56 | +62.92 |
/error-in-render failed reqs | 0 | 0 | ✓ |
/error-in-render total time (seconds) | 1.454 | 1.403 | -0.05 |
/error-in-render avg req/sec | 1719.38 | 1782.02 | +62.64 |
Client Bundles (main, webpack, commons)
vercel/next.js canary | jarvelov/next.js fix-route-loader-dev | Change | |
---|---|---|---|
359.HASH.js gzip | 2.96 kB | 2.96 kB | ✓ |
745.HASH.js gzip | 180 B | 180 B | ✓ |
framework-HASH.js gzip | 42.2 kB | 42.2 kB | ✓ |
main-HASH.js gzip | 21 kB | 21 kB | ✓ |
webpack-HASH.js gzip | 1.53 kB | 1.53 kB | ✓ |
Overall change | 67.9 kB | 67.9 kB | ✓ |
Legacy Client Bundles (polyfills)
vercel/next.js canary | jarvelov/next.js fix-route-loader-dev | Change | |
---|---|---|---|
polyfills-HASH.js gzip | 31.1 kB | 31.1 kB | ✓ |
Overall change | 31.1 kB | 31.1 kB | ✓ |
Client Pages
vercel/next.js canary | jarvelov/next.js fix-route-loader-dev | Change | |
---|---|---|---|
_app-HASH.js gzip | 803 B | 803 B | ✓ |
_error-HASH.js gzip | 3.06 kB | 3.06 kB | ✓ |
amp-HASH.js gzip | 554 B | 554 B | ✓ |
css-HASH.js gzip | 329 B | 329 B | ✓ |
dynamic-HASH.js gzip | 2.52 kB | 2.52 kB | ✓ |
head-HASH.js gzip | 2.28 kB | 2.28 kB | ✓ |
hooks-HASH.js gzip | 903 B | 903 B | ✓ |
image-HASH.js gzip | 5.63 kB | 5.63 kB | ✓ |
index-HASH.js gzip | 261 B | 261 B | ✓ |
link-HASH.js gzip | 1.66 kB | 1.66 kB | ✓ |
routerDirect..HASH.js gzip | 319 B | 319 B | ✓ |
script-HASH.js gzip | 387 B | 387 B | ✓ |
withRouter-HASH.js gzip | 320 B | 320 B | ✓ |
bb14e60e810b..30f.css gzip | 125 B | 125 B | ✓ |
Overall change | 19.1 kB | 19.1 kB | ✓ |
Client Build Manifests
vercel/next.js canary | jarvelov/next.js fix-route-loader-dev | Change | |
---|---|---|---|
_buildManifest.js gzip | 489 B | 489 B | ✓ |
Overall change | 489 B | 489 B | ✓ |
Rendered Page Sizes
vercel/next.js canary | jarvelov/next.js fix-route-loader-dev | Change | |
---|---|---|---|
index.html gzip | 530 B | 530 B | ✓ |
link.html gzip | 544 B | 544 B | ✓ |
withRouter.html gzip | 525 B | 525 B | ✓ |
Overall change | 1.6 kB | 1.6 kB | ✓ |
Diffs
Diff for main-HASH.js
@@ -2482,12 +2482,7 @@
} // We wait for pages to be built in dev before we start the route transition
// timeout to prevent an un-necessary hard navigation in development.
- var devBuildPromise;
- var devBuildResolve;
-
- if (false) {
- var _require, addMessageListener;
- } // Resolve a promise that times out after given amount of milliseconds.
+ var devBuildPromise; // Resolve a promise that times out after given amount of milliseconds.
function resolvePromiseWithTimeout(p, ms, err) {
return new Promise(function(resolve, reject) {
@@ -2647,31 +2642,31 @@
var _this = this;
return withFuture(route, routes, function() {
+ var routeFilesPromise = getFilesForRoute(assetPrefix, route)
+ .then(function(_ref) {
+ var scripts = _ref.scripts,
+ css = _ref.css;
+ return Promise.all([
+ entrypoints.has(route)
+ ? []
+ : Promise.all(scripts.map(maybeExecuteScript)),
+ Promise.all(css.map(fetchStyleSheet))
+ ]);
+ })
+ .then(function(res) {
+ return _this.whenEntrypoint(route).then(function(entrypoint) {
+ return {
+ entrypoint: entrypoint,
+ styles: res[1]
+ };
+ });
+ });
+
if (false) {
}
return resolvePromiseWithTimeout(
- getFilesForRoute(assetPrefix, route)
- .then(function(_ref) {
- var scripts = _ref.scripts,
- css = _ref.css;
- return Promise.all([
- entrypoints.has(route)
- ? []
- : Promise.all(scripts.map(maybeExecuteScript)),
- Promise.all(css.map(fetchStyleSheet))
- ]);
- })
- .then(function(res) {
- return _this
- .whenEntrypoint(route)
- .then(function(entrypoint) {
- return {
- entrypoint: entrypoint,
- styles: res[1]
- };
- });
- }),
+ routeFilesPromise,
MS_MAX_IDLE_DELAY,
markAssetError(
new Error("Route did not complete loading: ".concat(route))
Diff for index.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-54b2d7f5f69d6013116e.js"
+ src="/_next/static/chunks/main-e6e63898e6ec74ba0378.js"
defer=""
></script>
<script
Diff for link.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-54b2d7f5f69d6013116e.js"
+ src="/_next/static/chunks/main-e6e63898e6ec74ba0378.js"
defer=""
></script>
<script
Diff for withRouter.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/main-54b2d7f5f69d6013116e.js"
+ src="/_next/static/chunks/main-e6e63898e6ec74ba0378.js"
defer=""
></script>
<script
Webpack 4 Mode (Increase detected ⚠️ )
General Overall decrease ✓
vercel/next.js canary | jarvelov/next.js fix-route-loader-dev | Change | |
---|---|---|---|
buildDuration | 11.7s | 11.8s | |
buildDurationCached | 4.5s | 4.6s | |
nodeModulesSize | 49.5 MB | 49.5 MB | -1.35 kB |
Page Load Tests Overall increase ✓
vercel/next.js canary | jarvelov/next.js fix-route-loader-dev | Change | |
---|---|---|---|
/ failed reqs | 0 | 0 | ✓ |
/ total time (seconds) | 2.506 | 2.492 | -0.01 |
/ avg req/sec | 997.49 | 1003.35 | +5.86 |
/error-in-render failed reqs | 0 | 0 | ✓ |
/error-in-render total time (seconds) | 1.438 | 1.401 | -0.04 |
/error-in-render avg req/sec | 1737.93 | 1784.79 | +46.86 |
Client Bundles (main, webpack, commons)
vercel/next.js canary | jarvelov/next.js fix-route-loader-dev | Change | |
---|---|---|---|
17.HASH.js gzip | 2.98 kB | 2.98 kB | ✓ |
18.HASH.js gzip | 185 B | 185 B | ✓ |
677f882d2ed8..HASH.js gzip | 13.8 kB | 13.8 kB | ✓ |
framework.HASH.js gzip | 41.9 kB | 41.9 kB | ✓ |
main-HASH.js gzip | 8.4 kB | 8.4 kB | ✓ |
webpack-HASH.js gzip | 1.22 kB | 1.22 kB | ✓ |
Overall change | 68.5 kB | 68.5 kB | ✓ |
Legacy Client Bundles (polyfills)
vercel/next.js canary | jarvelov/next.js fix-route-loader-dev | Change | |
---|---|---|---|
polyfills-HASH.js gzip | 31.3 kB | 31.3 kB | ✓ |
Overall change | 31.3 kB | 31.3 kB | ✓ |
Client Pages
vercel/next.js canary | jarvelov/next.js fix-route-loader-dev | Change | |
---|---|---|---|
_app-HASH.js gzip | 791 B | 791 B | ✓ |
_error-HASH.js gzip | 3.76 kB | 3.76 kB | ✓ |
amp-HASH.js gzip | 552 B | 552 B | ✓ |
css-HASH.js gzip | 333 B | 333 B | ✓ |
dynamic-HASH.js gzip | 2.71 kB | 2.71 kB | ✓ |
head-HASH.js gzip | 2.97 kB | 2.97 kB | ✓ |
hooks-HASH.js gzip | 911 B | 911 B | ✓ |
index-HASH.js gzip | 231 B | 231 B | ✓ |
link-HASH.js gzip | 1.64 kB | 1.64 kB | ✓ |
routerDirect..HASH.js gzip | 298 B | 298 B | ✓ |
script-HASH.js gzip | 3.02 kB | 3.02 kB | ✓ |
withRouter-HASH.js gzip | 294 B | 294 B | ✓ |
e025d2764813..52f.css gzip | 125 B | 125 B | ✓ |
Overall change | 17.6 kB | 17.6 kB | ✓ |
Client Build Manifests
vercel/next.js canary | jarvelov/next.js fix-route-loader-dev | Change | |
---|---|---|---|
_buildManifest.js gzip | 500 B | 500 B | ✓ |
Overall change | 500 B | 500 B | ✓ |
Rendered Page Sizes Overall increase ⚠️
vercel/next.js canary | jarvelov/next.js fix-route-loader-dev | Change | |
---|---|---|---|
index.html gzip | 577 B | 577 B | ✓ |
link.html gzip | 589 B | 589 B | ✓ |
withRouter.html gzip | 569 B | 570 B | |
Overall change | 1.74 kB | 1.74 kB |
Diffs
Diff for 677f882d2ed8..c4df.HASH.js
@@ -867,12 +867,7 @@
} // We wait for pages to be built in dev before we start the route transition
// timeout to prevent an un-necessary hard navigation in development.
- var devBuildPromise;
- var devBuildResolve;
-
- if (false) {
- var _require, addMessageListener;
- } // Resolve a promise that times out after given amount of milliseconds.
+ var devBuildPromise; // Resolve a promise that times out after given amount of milliseconds.
function resolvePromiseWithTimeout(p, ms, err) {
return new Promise(function(resolve, reject) {
@@ -1032,31 +1027,31 @@
var _this = this;
return withFuture(route, routes, function() {
+ var routeFilesPromise = getFilesForRoute(assetPrefix, route)
+ .then(function(_ref) {
+ var scripts = _ref.scripts,
+ css = _ref.css;
+ return Promise.all([
+ entrypoints.has(route)
+ ? []
+ : Promise.all(scripts.map(maybeExecuteScript)),
+ Promise.all(css.map(fetchStyleSheet))
+ ]);
+ })
+ .then(function(res) {
+ return _this.whenEntrypoint(route).then(function(entrypoint) {
+ return {
+ entrypoint: entrypoint,
+ styles: res[1]
+ };
+ });
+ });
+
if (false) {
}
return resolvePromiseWithTimeout(
- getFilesForRoute(assetPrefix, route)
- .then(function(_ref) {
- var scripts = _ref.scripts,
- css = _ref.css;
- return Promise.all([
- entrypoints.has(route)
- ? []
- : Promise.all(scripts.map(maybeExecuteScript)),
- Promise.all(css.map(fetchStyleSheet))
- ]);
- })
- .then(function(res) {
- return _this
- .whenEntrypoint(route)
- .then(function(entrypoint) {
- return {
- entrypoint: entrypoint,
- styles: res[1]
- };
- });
- }),
+ routeFilesPromise,
MS_MAX_IDLE_DELAY,
markAssetError(
new Error("Route did not complete loading: ".concat(route))
Diff for index.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.bd3aee698f4a37984017.js"
+ src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.67199c98ca31edd10b07.js"
defer=""
></script>
<script
Diff for link.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.bd3aee698f4a37984017.js"
+ src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.67199c98ca31edd10b07.js"
defer=""
></script>
<script
Diff for withRouter.html
@@ -19,7 +19,7 @@
defer=""
></script>
<script
- src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.bd3aee698f4a37984017.js"
+ src="/_next/static/chunks/677f882d2ed86fa3467b8979053c1a4c3f8bc4df.67199c98ca31edd10b07.js"
defer=""
></script>
<script
flybayer
pushed a commit
to blitz-js/next.js
that referenced
this pull request
Aug 19, 2021
…de (vercel#27395) The fix in PR vercel#25749 only works some of the time. The reason why it doesn't work all of the time is because the `devBuildResolve` function is called when the assets have been built, but this can happen before the `getFilesForRoute` promise chain has completed, and thus the `cancelled` variable could not yet have been updated. To fix this we wait for the `getFilesForRoute` promise chain to be fulfilled and then resolve the `devBuildPromise` promise afterwards. This allows the `getFilesForRoute` promise chain to be fulfilled before and the `cancelled` variable can be updated accordingly. If an error is thrown somewhere in the `getFilesForRoute` promise chain, i.e. due to a failed fetch request, then that will also resolve the `devBuildPromise` and the error will bubble up to ultimately become a `routeChangeError` which will reload the page. With this fix the need to listen for HMR events has become obsolete as regardless of when the HMR build/sync events complete we still want to ensure that the `getFilesForRoute` promise chain has been fulfilled before resolving the `devBuildPromise`. Co-authored-by: Tobias Järvelöv <[email protected]> Co-authored-by: JJ Kasper <[email protected]>
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 #25675
The fix in PR #25749 for #25675 only works some of the times. The reason why it doesn't work all of the time is because the
devBuildResolve
function is called when the assets have been built, but this can happen before thegetFilesForRoute
promise chain has fulfilled, and thus thecancelled
variable in theresolvePromiseWithTimeout
function could potentially not have been updated yet.To fix this we wait for the
getFilesForRoute
promise chain to be fulfilled and then resolve thedevBuildPromise
promise afterwards. This allows thegetFilesForRoute
promise chain to be fulfilled before and thecancelled
variable can be updated accordingly.If an error is thrown somewhere in the
getFilesForRoute
promise chain, i.e. due to a failed fetch request, then that will also fulfill thedevBuildPromise
and the error will bubble up to ultimately become arouteChangeError
, which will reload the page, as expected.With this fix the need to listen for HMR events has become obsolete as regardless of when the HMR build/sync events complete we still want to ensure that the
getFilesForRoute
promise chain has been fulfilled before resolving thedevBuildPromise
.Bug
fixes #number
contributing.md
Feature
fixes #number
contributing.md
Documentation / Examples