-
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 with-msw example #17695
Fix with-msw example #17695
Conversation
Stats from current PRDefault Server Mode (Increase detected
|
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
buildDuration | 12.6s | 12.4s | -259ms |
nodeModulesSize | 63.2 MB | 63.2 MB | ✓ |
Page Load Tests Overall increase ✓
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
/ failed reqs | 0 | 0 | ✓ |
/ total time (seconds) | 2.282 | 2.288 | |
/ avg req/sec | 1095.42 | 1092.8 | |
/error-in-render failed reqs | 0 | 0 | ✓ |
/error-in-render total time (seconds) | 1.294 | 1.18 | -0.11 |
/error-in-render avg req/sec | 1932.3 | 2117.97 | +185.67 |
Client Bundles (main, webpack, commons)
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
677f882d2ed8..9339.js gzip | 10.9 kB | 10.9 kB | ✓ |
framework.HASH.js gzip | 39 kB | 39 kB | ✓ |
main-e5f5aee..31e1.js gzip | 7.17 kB | 7.17 kB | ✓ |
webpack-e067..f178.js gzip | 751 B | 751 B | ✓ |
Overall change | 57.8 kB | 57.8 kB | ✓ |
Client Bundles (main, webpack, commons) Modern
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
677f882d2ed8..dule.js gzip | 6.77 kB | 6.77 kB | ✓ |
framework.HA..dule.js gzip | 39 kB | 39 kB | ✓ |
main-ff4dea7..dule.js gzip | 6.24 kB | 6.24 kB | ✓ |
webpack-07c5..dule.js gzip | 751 B | 751 B | ✓ |
Overall change | 52.7 kB | 52.7 kB | ✓ |
Legacy Client Bundles (polyfills)
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
polyfills-4b..e242.js gzip | 31 kB | 31 kB | ✓ |
Overall change | 31 kB | 31 kB | ✓ |
Client Pages
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
_app-9a0b9e1..b37e.js gzip | 1.28 kB | 1.28 kB | ✓ |
_error-ed1b0..8fbd.js gzip | 3.44 kB | 3.44 kB | ✓ |
hooks-89731c..c609.js gzip | 887 B | 887 B | ✓ |
index-17468f..5d83.js gzip | 227 B | 227 B | ✓ |
link-d2344ce..8b36.js gzip | 1.3 kB | 1.3 kB | ✓ |
routerDirect..924c.js gzip | 284 B | 284 B | ✓ |
withRouter-7..c13d.js gzip | 284 B | 284 B | ✓ |
Overall change | 7.71 kB | 7.71 kB | ✓ |
Client Pages Modern
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
_app-75d3a82..dule.js gzip | 625 B | 625 B | ✓ |
_error-4469a..dule.js gzip | 2.29 kB | 2.29 kB | ✓ |
hooks-cbf13f..dule.js gzip | 387 B | 387 B | ✓ |
index-b9a643..dule.js gzip | 226 B | 226 B | ✓ |
link-f8c0daf..dule.js gzip | 1.26 kB | 1.26 kB | ✓ |
routerDirect..dule.js gzip | 284 B | 284 B | ✓ |
withRouter-f..dule.js gzip | 282 B | 282 B | ✓ |
Overall change | 5.36 kB | 5.36 kB | ✓ |
Client Build Manifests
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
_buildManifest.js gzip | 322 B | 322 B | ✓ |
_buildManife..dule.js gzip | 329 B | 329 B | ✓ |
Overall change | 651 B | 651 B | ✓ |
Rendered Page Sizes
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
index.html gzip | 1 kB | 1 kB | ✓ |
link.html gzip | 1.01 kB | 1.01 kB | ✓ |
withRouter.html gzip | 996 B | 996 B | ✓ |
Overall change | 3.01 kB | 3.01 kB | ✓ |
Serverless Mode
General
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
buildDuration | 13.9s | 14.2s | |
nodeModulesSize | 63.2 MB | 63.2 MB | ✓ |
Client Bundles (main, webpack, commons)
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
677f882d2ed8..9339.js gzip | 10.9 kB | 10.9 kB | ✓ |
framework.HASH.js gzip | 39 kB | 39 kB | ✓ |
main-e5f5aee..31e1.js gzip | 7.17 kB | 7.17 kB | ✓ |
webpack-e067..f178.js gzip | 751 B | 751 B | ✓ |
Overall change | 57.8 kB | 57.8 kB | ✓ |
Client Bundles (main, webpack, commons) Modern
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
677f882d2ed8..dule.js gzip | 6.77 kB | 6.77 kB | ✓ |
framework.HA..dule.js gzip | 39 kB | 39 kB | ✓ |
main-ff4dea7..dule.js gzip | 6.24 kB | 6.24 kB | ✓ |
webpack-07c5..dule.js gzip | 751 B | 751 B | ✓ |
Overall change | 52.7 kB | 52.7 kB | ✓ |
Legacy Client Bundles (polyfills)
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
polyfills-4b..e242.js gzip | 31 kB | 31 kB | ✓ |
Overall change | 31 kB | 31 kB | ✓ |
Client Pages
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
_app-9a0b9e1..b37e.js gzip | 1.28 kB | 1.28 kB | ✓ |
_error-ed1b0..8fbd.js gzip | 3.44 kB | 3.44 kB | ✓ |
hooks-89731c..c609.js gzip | 887 B | 887 B | ✓ |
index-17468f..5d83.js gzip | 227 B | 227 B | ✓ |
link-d2344ce..8b36.js gzip | 1.3 kB | 1.3 kB | ✓ |
routerDirect..924c.js gzip | 284 B | 284 B | ✓ |
withRouter-7..c13d.js gzip | 284 B | 284 B | ✓ |
Overall change | 7.71 kB | 7.71 kB | ✓ |
Client Pages Modern
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
_app-75d3a82..dule.js gzip | 625 B | 625 B | ✓ |
_error-4469a..dule.js gzip | 2.29 kB | 2.29 kB | ✓ |
hooks-cbf13f..dule.js gzip | 387 B | 387 B | ✓ |
index-b9a643..dule.js gzip | 226 B | 226 B | ✓ |
link-f8c0daf..dule.js gzip | 1.26 kB | 1.26 kB | ✓ |
routerDirect..dule.js gzip | 284 B | 284 B | ✓ |
withRouter-f..dule.js gzip | 282 B | 282 B | ✓ |
Overall change | 5.36 kB | 5.36 kB | ✓ |
Client Build Manifests
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
_buildManifest.js gzip | 322 B | 322 B | ✓ |
_buildManife..dule.js gzip | 329 B | 329 B | ✓ |
Overall change | 651 B | 651 B | ✓ |
Serverless bundles
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
_error.js | 1.05 MB | 1.05 MB | ✓ |
404.html | 4.34 kB | 4.34 kB | ✓ |
hooks.html | 3.92 kB | 3.92 kB | ✓ |
index.js | 1.05 MB | 1.05 MB | ✓ |
link.js | 1.1 MB | 1.1 MB | ✓ |
routerDirect.js | 1.09 MB | 1.09 MB | ✓ |
withRouter.js | 1.09 MB | 1.09 MB | ✓ |
Overall change | 5.4 MB | 5.4 MB | ✓ |
Stats from current PRDefault Server ModeGeneral
Page Load Tests Overall increase ✓
Client Bundles (main, webpack, commons)
Client Bundles (main, webpack, commons) Modern
Legacy Client Bundles (polyfills)
Client Pages
Client Pages Modern
Client Build Manifests
Rendered Page Sizes
Serverless ModeGeneral
Client Bundles (main, webpack, commons)
Client Bundles (main, webpack, commons) Modern
Legacy Client Bundles (polyfills)
Client Pages
Client Pages Modern
Client Build Manifests
Serverless bundles
|
Stats from current PRDefault Server Mode (Increase detected
|
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
buildDuration | 13.3s | 13.4s | |
nodeModulesSize | 63.4 MB | 63.4 MB | ✓ |
Page Load Tests Overall increase ✓
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
/ failed reqs | 0 | 0 | ✓ |
/ total time (seconds) | 2.408 | 2.398 | -0.01 |
/ avg req/sec | 1038.2 | 1042.74 | +4.54 |
/error-in-render failed reqs | 0 | 0 | ✓ |
/error-in-render total time (seconds) | 1.302 | 1.292 | -0.01 |
/error-in-render avg req/sec | 1920.77 | 1935.56 | +14.79 |
Client Bundles (main, webpack, commons)
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
677f882d2ed8..9b19.js gzip | 11.1 kB | 11.1 kB | ✓ |
framework.HASH.js gzip | 39 kB | 39 kB | ✓ |
main-310f69a..b28a.js gzip | 7.23 kB | 7.23 kB | ✓ |
webpack-e067..f178.js gzip | 751 B | 751 B | ✓ |
Overall change | 58 kB | 58 kB | ✓ |
Client Bundles (main, webpack, commons) Modern
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
677f882d2ed8..dule.js gzip | 6.9 kB | 6.9 kB | ✓ |
framework.HA..dule.js gzip | 39 kB | 39 kB | ✓ |
main-fbbf49e..dule.js gzip | 6.29 kB | 6.29 kB | ✓ |
webpack-07c5..dule.js gzip | 751 B | 751 B | ✓ |
Overall change | 52.9 kB | 52.9 kB | ✓ |
Legacy Client Bundles (polyfills)
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
polyfills-4b..e242.js gzip | 31 kB | 31 kB | ✓ |
Overall change | 31 kB | 31 kB | ✓ |
Client Pages
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
_app-9a0b9e1..b37e.js gzip | 1.28 kB | 1.28 kB | ✓ |
_error-ed1b0..8fbd.js gzip | 3.44 kB | 3.44 kB | ✓ |
hooks-89731c..c609.js gzip | 887 B | 887 B | ✓ |
index-17468f..5d83.js gzip | 227 B | 227 B | ✓ |
link-409b283..e3ab.js gzip | 1.32 kB | 1.32 kB | ✓ |
routerDirect..924c.js gzip | 284 B | 284 B | ✓ |
withRouter-7..c13d.js gzip | 284 B | 284 B | ✓ |
Overall change | 7.73 kB | 7.73 kB | ✓ |
Client Pages Modern
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
_app-75d3a82..dule.js gzip | 625 B | 625 B | ✓ |
_error-4469a..dule.js gzip | 2.29 kB | 2.29 kB | ✓ |
hooks-cbf13f..dule.js gzip | 387 B | 387 B | ✓ |
index-b9a643..dule.js gzip | 226 B | 226 B | ✓ |
link-92d3016..dule.js gzip | 1.28 kB | 1.28 kB | ✓ |
routerDirect..dule.js gzip | 284 B | 284 B | ✓ |
withRouter-f..dule.js gzip | 282 B | 282 B | ✓ |
Overall change | 5.37 kB | 5.37 kB | ✓ |
Client Build Manifests
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
_buildManifest.js gzip | 323 B | 323 B | ✓ |
_buildManife..dule.js gzip | 329 B | 329 B | ✓ |
Overall change | 652 B | 652 B | ✓ |
Rendered Page Sizes
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
index.html gzip | 1 kB | 1 kB | ✓ |
link.html gzip | 1.01 kB | 1.01 kB | ✓ |
withRouter.html gzip | 996 B | 996 B | ✓ |
Overall change | 3.01 kB | 3.01 kB | ✓ |
Serverless Mode
General
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
buildDuration | 14.7s | 14.4s | -301ms |
nodeModulesSize | 63.4 MB | 63.4 MB | ✓ |
Client Bundles (main, webpack, commons)
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
677f882d2ed8..9b19.js gzip | 11.1 kB | 11.1 kB | ✓ |
framework.HASH.js gzip | 39 kB | 39 kB | ✓ |
main-310f69a..b28a.js gzip | 7.23 kB | 7.23 kB | ✓ |
webpack-e067..f178.js gzip | 751 B | 751 B | ✓ |
Overall change | 58 kB | 58 kB | ✓ |
Client Bundles (main, webpack, commons) Modern
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
677f882d2ed8..dule.js gzip | 6.9 kB | 6.9 kB | ✓ |
framework.HA..dule.js gzip | 39 kB | 39 kB | ✓ |
main-fbbf49e..dule.js gzip | 6.29 kB | 6.29 kB | ✓ |
webpack-07c5..dule.js gzip | 751 B | 751 B | ✓ |
Overall change | 52.9 kB | 52.9 kB | ✓ |
Legacy Client Bundles (polyfills)
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
polyfills-4b..e242.js gzip | 31 kB | 31 kB | ✓ |
Overall change | 31 kB | 31 kB | ✓ |
Client Pages
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
_app-9a0b9e1..b37e.js gzip | 1.28 kB | 1.28 kB | ✓ |
_error-ed1b0..8fbd.js gzip | 3.44 kB | 3.44 kB | ✓ |
hooks-89731c..c609.js gzip | 887 B | 887 B | ✓ |
index-17468f..5d83.js gzip | 227 B | 227 B | ✓ |
link-409b283..e3ab.js gzip | 1.32 kB | 1.32 kB | ✓ |
routerDirect..924c.js gzip | 284 B | 284 B | ✓ |
withRouter-7..c13d.js gzip | 284 B | 284 B | ✓ |
Overall change | 7.73 kB | 7.73 kB | ✓ |
Client Pages Modern
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
_app-75d3a82..dule.js gzip | 625 B | 625 B | ✓ |
_error-4469a..dule.js gzip | 2.29 kB | 2.29 kB | ✓ |
hooks-cbf13f..dule.js gzip | 387 B | 387 B | ✓ |
index-b9a643..dule.js gzip | 226 B | 226 B | ✓ |
link-92d3016..dule.js gzip | 1.28 kB | 1.28 kB | ✓ |
routerDirect..dule.js gzip | 284 B | 284 B | ✓ |
withRouter-f..dule.js gzip | 282 B | 282 B | ✓ |
Overall change | 5.37 kB | 5.37 kB | ✓ |
Client Build Manifests
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
_buildManifest.js gzip | 323 B | 323 B | ✓ |
_buildManife..dule.js gzip | 329 B | 329 B | ✓ |
Overall change | 652 B | 652 B | ✓ |
Serverless bundles
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
_error.js | 1.05 MB | 1.05 MB | ✓ |
404.html | 4.34 kB | 4.34 kB | ✓ |
hooks.html | 3.92 kB | 3.92 kB | ✓ |
index.js | 1.05 MB | 1.05 MB | ✓ |
link.js | 1.1 MB | 1.1 MB | ✓ |
routerDirect.js | 1.09 MB | 1.09 MB | ✓ |
withRouter.js | 1.09 MB | 1.09 MB | ✓ |
Overall change | 5.41 MB | 5.41 MB | ✓ |
examples/with-msw/pages/index.js
Outdated
const [reviews, setReviews] = useState(null) | ||
|
||
const handleGetReviews = () => { | ||
// Client-side request are mocked by `mocks/browser.js`. | ||
// This request will fail in production, as MSW is only run in development. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This statement is not entirely true. It's run everywhere except production. Perhaps, we can drop this line altogether, and only mention that in production this request would hit the actual backend?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋 Added my final review 🕵️
examples/with-msw/pages/index.js
Outdated
return { | ||
props: { | ||
error: true, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's return something more friendly, like
props: {
inProduction: true,
},
We don't have an error here, it's expected to fail because there's no real endpoint
examples/with-msw/pages/index.js
Outdated
if (error) { | ||
return ( | ||
<div> | ||
<p>Failed to fetch book</p> | ||
</div> | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here don't handle it as an error, instead render a paragraph that explains why it will only work in localhost, you shouldn't be testing MSW in production.
examples/with-msw/pages/index.js
Outdated
// This request will fail in production, as MSW is only run in development. | ||
// In a real-world app this request would hit the actual backend. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These comments aren't needed because this request won't be executed in production due to the check below.
@lfades I implemented the requested changes. Thanks for the review! |
Stats from current PRDefault Server Mode (Increase detected
|
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
buildDuration | 13.9s | 13.8s | -84ms |
nodeModulesSize | 63.4 MB | 63.4 MB | ✓ |
Page Load Tests Overall increase ✓
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
/ failed reqs | 0 | 0 | ✓ |
/ total time (seconds) | 2.739 | 2.697 | -0.04 |
/ avg req/sec | 912.89 | 927.02 | +14.13 |
/error-in-render failed reqs | 0 | 0 | ✓ |
/error-in-render total time (seconds) | 1.609 | 1.538 | -0.07 |
/error-in-render avg req/sec | 1553.84 | 1626 | +72.16 |
Client Bundles (main, webpack, commons)
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
677f882d2ed8..9b19.js gzip | 11.1 kB | 11.1 kB | ✓ |
framework.HASH.js gzip | 39 kB | 39 kB | ✓ |
main-310f69a..b28a.js gzip | 7.23 kB | 7.23 kB | ✓ |
webpack-e067..f178.js gzip | 751 B | 751 B | ✓ |
Overall change | 58 kB | 58 kB | ✓ |
Client Bundles (main, webpack, commons) Modern
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
677f882d2ed8..dule.js gzip | 6.9 kB | 6.9 kB | ✓ |
framework.HA..dule.js gzip | 39 kB | 39 kB | ✓ |
main-fbbf49e..dule.js gzip | 6.29 kB | 6.29 kB | ✓ |
webpack-07c5..dule.js gzip | 751 B | 751 B | ✓ |
Overall change | 52.9 kB | 52.9 kB | ✓ |
Legacy Client Bundles (polyfills)
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
polyfills-4b..e242.js gzip | 31 kB | 31 kB | ✓ |
Overall change | 31 kB | 31 kB | ✓ |
Client Pages
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
_app-9a0b9e1..b37e.js gzip | 1.28 kB | 1.28 kB | ✓ |
_error-ed1b0..8fbd.js gzip | 3.44 kB | 3.44 kB | ✓ |
hooks-89731c..c609.js gzip | 887 B | 887 B | ✓ |
index-17468f..5d83.js gzip | 227 B | 227 B | ✓ |
link-409b283..e3ab.js gzip | 1.32 kB | 1.32 kB | ✓ |
routerDirect..924c.js gzip | 284 B | 284 B | ✓ |
withRouter-7..c13d.js gzip | 284 B | 284 B | ✓ |
Overall change | 7.73 kB | 7.73 kB | ✓ |
Client Pages Modern
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
_app-75d3a82..dule.js gzip | 625 B | 625 B | ✓ |
_error-4469a..dule.js gzip | 2.29 kB | 2.29 kB | ✓ |
hooks-cbf13f..dule.js gzip | 387 B | 387 B | ✓ |
index-b9a643..dule.js gzip | 226 B | 226 B | ✓ |
link-92d3016..dule.js gzip | 1.28 kB | 1.28 kB | ✓ |
routerDirect..dule.js gzip | 284 B | 284 B | ✓ |
withRouter-f..dule.js gzip | 282 B | 282 B | ✓ |
Overall change | 5.37 kB | 5.37 kB | ✓ |
Client Build Manifests
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
_buildManifest.js gzip | 323 B | 323 B | ✓ |
_buildManife..dule.js gzip | 329 B | 329 B | ✓ |
Overall change | 652 B | 652 B | ✓ |
Rendered Page Sizes
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
index.html gzip | 1 kB | 1 kB | ✓ |
link.html gzip | 1.01 kB | 1.01 kB | ✓ |
withRouter.html gzip | 996 B | 996 B | ✓ |
Overall change | 3.01 kB | 3.01 kB | ✓ |
Serverless Mode
General
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
buildDuration | 15.6s | 16s | |
nodeModulesSize | 63.4 MB | 63.4 MB | ✓ |
Client Bundles (main, webpack, commons)
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
677f882d2ed8..9b19.js gzip | 11.1 kB | 11.1 kB | ✓ |
framework.HASH.js gzip | 39 kB | 39 kB | ✓ |
main-310f69a..b28a.js gzip | 7.23 kB | 7.23 kB | ✓ |
webpack-e067..f178.js gzip | 751 B | 751 B | ✓ |
Overall change | 58 kB | 58 kB | ✓ |
Client Bundles (main, webpack, commons) Modern
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
677f882d2ed8..dule.js gzip | 6.9 kB | 6.9 kB | ✓ |
framework.HA..dule.js gzip | 39 kB | 39 kB | ✓ |
main-fbbf49e..dule.js gzip | 6.29 kB | 6.29 kB | ✓ |
webpack-07c5..dule.js gzip | 751 B | 751 B | ✓ |
Overall change | 52.9 kB | 52.9 kB | ✓ |
Legacy Client Bundles (polyfills)
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
polyfills-4b..e242.js gzip | 31 kB | 31 kB | ✓ |
Overall change | 31 kB | 31 kB | ✓ |
Client Pages
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
_app-9a0b9e1..b37e.js gzip | 1.28 kB | 1.28 kB | ✓ |
_error-ed1b0..8fbd.js gzip | 3.44 kB | 3.44 kB | ✓ |
hooks-89731c..c609.js gzip | 887 B | 887 B | ✓ |
index-17468f..5d83.js gzip | 227 B | 227 B | ✓ |
link-409b283..e3ab.js gzip | 1.32 kB | 1.32 kB | ✓ |
routerDirect..924c.js gzip | 284 B | 284 B | ✓ |
withRouter-7..c13d.js gzip | 284 B | 284 B | ✓ |
Overall change | 7.73 kB | 7.73 kB | ✓ |
Client Pages Modern
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
_app-75d3a82..dule.js gzip | 625 B | 625 B | ✓ |
_error-4469a..dule.js gzip | 2.29 kB | 2.29 kB | ✓ |
hooks-cbf13f..dule.js gzip | 387 B | 387 B | ✓ |
index-b9a643..dule.js gzip | 226 B | 226 B | ✓ |
link-92d3016..dule.js gzip | 1.28 kB | 1.28 kB | ✓ |
routerDirect..dule.js gzip | 284 B | 284 B | ✓ |
withRouter-f..dule.js gzip | 282 B | 282 B | ✓ |
Overall change | 5.37 kB | 5.37 kB | ✓ |
Client Build Manifests
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
_buildManifest.js gzip | 323 B | 323 B | ✓ |
_buildManife..dule.js gzip | 329 B | 329 B | ✓ |
Overall change | 652 B | 652 B | ✓ |
Serverless bundles
vercel/next.js canary | jensmeindertsma/next.js fix/with-msw-example | Change | |
---|---|---|---|
_error.js | 1.05 MB | 1.05 MB | ✓ |
404.html | 4.34 kB | 4.34 kB | ✓ |
hooks.html | 3.92 kB | 3.92 kB | ✓ |
index.js | 1.05 MB | 1.05 MB | ✓ |
link.js | 1.1 MB | 1.1 MB | ✓ |
routerDirect.js | 1.09 MB | 1.09 MB | ✓ |
withRouter.js | 1.09 MB | 1.09 MB | ✓ |
Overall change | 5.41 MB | 5.41 MB | ✓ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jensmeindertsma Thank you!
Any thoughts on updating the README to reflect this PR? |
Hey @williamyeny this is actually not the approach would recommend anymore. I might open a PR to change the example when I have time. I don't think it makes sense updating the README until then. |
@jensmeindertsma Thank you! |
@jensmeindertsma please do! I'm struggling to get MSW set up correctly with Next.js, the service worker doesn't finish activating before my Next.js app starts attempting data fetch requests, there seems to be a race condition and I'm not sure how to educate Next.js to wait until the worker is started |
@christemple give me 72 hours, I'll get back to you! |
@christemple as promised, I've set up a basic example with TypeScript here: https://github.com/jensmeindertsma/next-app-msw. I'll flesh it out a bit more and then I'll open a PR to reflect these changes in this repo. Basically, I switched back to using environment variables to control MSW. To disable MSW in production you need |
I just opened #20335 to implement the new example and update the README. |
When using the
with-msw
example I noticed it increased my bundle size in production, even through MSW is meant to be used in development only.Build size before implementing MSW
Build size after implementing MSW according to the
with-msw
exampleThere was a 12.7 kB large increase in the
_app
First Load JS which increased the pages' First Load JS size. I tracked the problem down to the following code:Removing this reduces the
_app
First Load JS to what it was previously. TheNEXT_PUBLIC_API_MOCKING
environment variable is defined in the.env.development
file, as this means that Next.js will only activate MSW during development/testing, which is what MSW is intended for.After discussing with @kettanaito, the author of MSW, I did some investigation. This dynamic require statement is intended to allow tree-shaking of the MSW package for production. Unfortunately this did not seem to be working. To fix this, I changed the code to the following:
This means I could remove the
NEXT_PUBLIC_API_MOCKING
environment variable from.env.development
, as it is no longer used.It is important to note that this still achieves the same functionality as before: MSW runs in development / testing, and not in production. If MSW must be enabled in production for some reason, the following code can be used to run MSW regardless of the environment:
If possible, I'd love to hear from the Next.js maintainers regarding the tree-shaking process when using environment variables.
Lastly, I made the necessary changes to have the example work in production mode as well, because there is no real backend. Of course there is a comment explaining what should be changed in a real world app.