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

Support custom .toJSON when serializing SSR props #12156

Closed

Conversation

ericclemmons
Copy link

When returning class-based instances as props, users experience an error

SerializableError: Error serializing .data[0]returned fromgetServerSidePropsin "/reports/[report]/[start]/[end]". Reason:object ("[object Object]") cannot be serialized as JSON. Please only return JSON serializable data types.
– (Source):

// pages/index.tsx
export async function getServerSideProps(context) {
	const posts = await DataStore.query(Post);
   // [Post {...}, Post {...}, ...]

	return {
		props: {
			posts
		},
	};
}

As a way to opt-in to serialization (vs. requiring users to run JSON.parse(JSON.stringify(...)), this PR leverages the existing support for .toJSON.

This PR enforces the following contracts:

  • .toJSON() must return a plain object, since the expectation is that a class-based instance would return enumerable properties but without the instance. (e.g. Post { title: "Post #1 " } becomes { title: "Post #1" }).

    This is necessary for pathing to be consistent on both the server & client (e.g. post.title works on both Post instances and plain objects)

  • Date.toJSON() continues to throw, since it returns a string.

Fixes #11993

@ericclemmons ericclemmons changed the title Support .toJSON when serializing SSR props Support custom .toJSON when serializing SSR props Apr 23, 2020
@ijjk
Copy link
Member

ijjk commented Apr 23, 2020

Stats from current PR

Default Server Mode (Decrease detected ✓)
General Overall increase ⚠️
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
buildDuration 12.9s 12.6s -237ms
nodeModulesSize 55.2 MB 55.2 MB ⚠️ +273 B
Page Load Tests Overall decrease ⚠️
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
/ failed reqs 0 0
/ total time (seconds) 2.213 2.21 0
/ avg req/sec 1129.8 1131.2 ⚠️ +1.4
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.253 1.264 ⚠️ +0.01
/error-in-render avg req/sec 1995.89 1978.42 -17.47
Client Bundles (main, webpack, commons)
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
main-HASH.js gzip 6.25 kB 6.25 kB
webpack-HASH.js gzip 746 B 746 B
de003c3a9d30..45d6.js gzip 10.3 kB 10.3 kB
framework.a1..NSE.txt gzip 220 B 220 B
framework.a1..NSE.txt gzip 220 B 220 B
framework.HASH.js gzip 39 kB 39 kB
Overall change 56.7 kB 56.7 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
main-HASH.module.js gzip 4.79 kB 4.79 kB
webpack-HASH..dule.js gzip 746 B 746 B
de003c3a9d30..dule.js gzip 6.87 kB 6.87 kB
framework.HA..dule.js gzip 39 kB 39 kB
Overall change 51.4 kB 51.4 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
polyfills-HASH.js gzip 26.2 kB 26.2 kB
Overall change 26.2 kB 26.2 kB
Client Pages
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_app.js gzip 1.23 kB 1.23 kB
_error.js gzip 3.12 kB 3.12 kB
hooks.js gzip 663 B 663 B
index.js gzip 222 B 222 B
link.js gzip 2.06 kB 2.06 kB
routerDirect.js gzip 280 B 280 B
withRouter.js gzip 278 B 278 B
Overall change 7.85 kB 7.85 kB
Client Pages Modern
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_app.module.js gzip 598 B 598 B
_error.module.js gzip 2.09 kB 2.09 kB
hooks.module.js gzip 383 B 383 B
index.module.js gzip 223 B 223 B
link.module.js gzip 1.52 kB 1.52 kB
routerDirect..dule.js gzip 279 B 279 B
withRouter.m..dule.js gzip 278 B 278 B
Overall change 5.37 kB 5.37 kB
Client Build Manifests
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Rendered Page Sizes
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
index.html gzip 929 B 929 B
link.html gzip 938 B 938 B
withRouter.html gzip 925 B 925 B
Overall change 2.79 kB 2.79 kB

Serverless Mode (Increase detected ⚠️)
General Overall increase ⚠️
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
buildDuration 13.5s 13.4s -91ms
nodeModulesSize 55.2 MB 55.2 MB ⚠️ +273 B
Client Bundles (main, webpack, commons)
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
main-HASH.js gzip 6.25 kB 6.25 kB
webpack-HASH.js gzip 746 B 746 B
de003c3a9d30..45d6.js gzip 10.3 kB 10.3 kB
framework.a1..NSE.txt gzip 220 B 220 B
framework.a1..NSE.txt gzip 220 B 220 B
framework.HASH.js gzip 39 kB 39 kB
Overall change 56.7 kB 56.7 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
main-HASH.module.js gzip 4.79 kB 4.79 kB
webpack-HASH..dule.js gzip 746 B 746 B
de003c3a9d30..dule.js gzip 6.87 kB 6.87 kB
framework.HA..dule.js gzip 39 kB 39 kB
Overall change 51.4 kB 51.4 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
polyfills-HASH.js gzip 26.2 kB 26.2 kB
Overall change 26.2 kB 26.2 kB
Client Pages
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_app.js gzip 1.23 kB 1.23 kB
_error.js gzip 3.12 kB 3.12 kB
hooks.js gzip 663 B 663 B
index.js gzip 222 B 222 B
link.js gzip 2.06 kB 2.06 kB
routerDirect.js gzip 280 B 280 B
withRouter.js gzip 278 B 278 B
Overall change 7.85 kB 7.85 kB
Client Pages Modern
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_app.module.js gzip 598 B 598 B
_error.module.js gzip 2.09 kB 2.09 kB
hooks.module.js gzip 383 B 383 B
index.module.js gzip 223 B 223 B
link.module.js gzip 1.52 kB 1.52 kB
routerDirect..dule.js gzip 279 B 279 B
withRouter.m..dule.js gzip 278 B 278 B
Overall change 5.37 kB 5.37 kB
Client Build Manifests
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Serverless bundles Overall increase ⚠️
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_error.js 558 kB 558 kB ⚠️ +273 B
404.html 4.18 kB 4.18 kB
hooks.html 3.81 kB 3.81 kB
index.js 558 kB 558 kB ⚠️ +273 B
link.js 595 kB 595 kB ⚠️ +273 B
routerDirect.js 587 kB 587 kB ⚠️ +273 B
withRouter.js 587 kB 587 kB ⚠️ +273 B
Overall change 2.89 MB 2.89 MB ⚠️ +1.36 kB

Otherwise, if JSON.stringify(...) were used the test would incorrectly
pass.
@ijjk
Copy link
Member

ijjk commented Apr 24, 2020

Stats from current PR

Default Server Mode (Increase detected ⚠️)
General Overall increase ⚠️
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
buildDuration 11.7s 11.8s ⚠️ +80ms
nodeModulesSize 55.2 MB 55.2 MB ⚠️ +273 B
Page Load Tests Overall increase ✓
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
/ failed reqs 0 0
/ total time (seconds) 1.951 1.919 -0.03
/ avg req/sec 1281.7 1302.62 ⚠️ +20.92
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 0.999 0.984 -0.02
/error-in-render avg req/sec 2502.88 2540.78 ⚠️ +37.9
Client Bundles (main, webpack, commons)
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
main-HASH.js gzip 6.25 kB 6.25 kB
webpack-HASH.js gzip 746 B 746 B
de003c3a9d30..45d6.js gzip 10.3 kB 10.3 kB
framework.a1..NSE.txt gzip 220 B 220 B
framework.a1..NSE.txt gzip 220 B 220 B
framework.HASH.js gzip 39 kB 39 kB
Overall change 56.7 kB 56.7 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
main-HASH.module.js gzip 4.79 kB 4.79 kB
webpack-HASH..dule.js gzip 746 B 746 B
de003c3a9d30..dule.js gzip 6.87 kB 6.87 kB
framework.HA..dule.js gzip 39 kB 39 kB
Overall change 51.4 kB 51.4 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
polyfills-HASH.js gzip 26.2 kB 26.2 kB
Overall change 26.2 kB 26.2 kB
Client Pages
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_app.js gzip 1.23 kB 1.23 kB
_error.js gzip 3.12 kB 3.12 kB
hooks.js gzip 663 B 663 B
index.js gzip 222 B 222 B
link.js gzip 2.06 kB 2.06 kB
routerDirect.js gzip 280 B 280 B
withRouter.js gzip 278 B 278 B
Overall change 7.85 kB 7.85 kB
Client Pages Modern
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_app.module.js gzip 598 B 598 B
_error.module.js gzip 2.09 kB 2.09 kB
hooks.module.js gzip 383 B 383 B
index.module.js gzip 223 B 223 B
link.module.js gzip 1.52 kB 1.52 kB
routerDirect..dule.js gzip 279 B 279 B
withRouter.m..dule.js gzip 278 B 278 B
Overall change 5.37 kB 5.37 kB
Client Build Manifests
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Rendered Page Sizes
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
index.html gzip 929 B 929 B
link.html gzip 939 B 939 B
withRouter.html gzip 925 B 925 B
Overall change 2.79 kB 2.79 kB

Serverless Mode (Increase detected ⚠️)
General Overall increase ⚠️
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
buildDuration 12.6s 12.2s -419ms
nodeModulesSize 55.2 MB 55.2 MB ⚠️ +273 B
Client Bundles (main, webpack, commons)
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
main-HASH.js gzip 6.25 kB 6.25 kB
webpack-HASH.js gzip 746 B 746 B
de003c3a9d30..45d6.js gzip 10.3 kB 10.3 kB
framework.a1..NSE.txt gzip 220 B 220 B
framework.a1..NSE.txt gzip 220 B 220 B
framework.HASH.js gzip 39 kB 39 kB
Overall change 56.7 kB 56.7 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
main-HASH.module.js gzip 4.79 kB 4.79 kB
webpack-HASH..dule.js gzip 746 B 746 B
de003c3a9d30..dule.js gzip 6.87 kB 6.87 kB
framework.HA..dule.js gzip 39 kB 39 kB
Overall change 51.4 kB 51.4 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
polyfills-HASH.js gzip 26.2 kB 26.2 kB
Overall change 26.2 kB 26.2 kB
Client Pages
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_app.js gzip 1.23 kB 1.23 kB
_error.js gzip 3.12 kB 3.12 kB
hooks.js gzip 663 B 663 B
index.js gzip 222 B 222 B
link.js gzip 2.06 kB 2.06 kB
routerDirect.js gzip 280 B 280 B
withRouter.js gzip 278 B 278 B
Overall change 7.85 kB 7.85 kB
Client Pages Modern
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_app.module.js gzip 598 B 598 B
_error.module.js gzip 2.09 kB 2.09 kB
hooks.module.js gzip 383 B 383 B
index.module.js gzip 223 B 223 B
link.module.js gzip 1.52 kB 1.52 kB
routerDirect..dule.js gzip 279 B 279 B
withRouter.m..dule.js gzip 278 B 278 B
Overall change 5.37 kB 5.37 kB
Client Build Manifests
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Serverless bundles Overall increase ⚠️
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_error.js 558 kB 558 kB ⚠️ +273 B
404.html 4.18 kB 4.18 kB
hooks.html 3.81 kB 3.81 kB
index.js 558 kB 558 kB ⚠️ +273 B
link.js 595 kB 595 kB ⚠️ +273 B
routerDirect.js 587 kB 587 kB ⚠️ +273 B
withRouter.js 587 kB 587 kB ⚠️ +273 B
Overall change 2.89 MB 2.89 MB ⚠️ +1.36 kB

@ijjk
Copy link
Member

ijjk commented Apr 24, 2020

Stats from current PR

Default Server Mode (Decrease detected ✓)
General Overall increase ⚠️
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
buildDuration 12.3s 13.3s ⚠️ +1.1s
nodeModulesSize 55.2 MB 55.2 MB ⚠️ +273 B
Page Load Tests Overall decrease ⚠️
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
/ failed reqs 0 0
/ total time (seconds) 2.242 2.28 ⚠️ +0.04
/ avg req/sec 1114.87 1096.68 -18.19
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.254 1.354 ⚠️ +0.1
/error-in-render avg req/sec 1993.3 1845.77 -147.53
Client Bundles (main, webpack, commons)
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
main-HASH.js gzip 6.25 kB 6.25 kB
webpack-HASH.js gzip 746 B 746 B
de003c3a9d30..45d6.js gzip 10.3 kB 10.3 kB
framework.a1..NSE.txt gzip 220 B 220 B
framework.a1..NSE.txt gzip 220 B 220 B
framework.HASH.js gzip 39 kB 39 kB
Overall change 56.7 kB 56.7 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
main-HASH.module.js gzip 4.79 kB 4.79 kB
webpack-HASH..dule.js gzip 746 B 746 B
de003c3a9d30..dule.js gzip 6.87 kB 6.87 kB
framework.HA..dule.js gzip 39 kB 39 kB
Overall change 51.4 kB 51.4 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
polyfills-HASH.js gzip 26.2 kB 26.2 kB
Overall change 26.2 kB 26.2 kB
Client Pages
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_app.js gzip 1.23 kB 1.23 kB
_error.js gzip 3.12 kB 3.12 kB
hooks.js gzip 663 B 663 B
index.js gzip 222 B 222 B
link.js gzip 2.06 kB 2.06 kB
routerDirect.js gzip 280 B 280 B
withRouter.js gzip 278 B 278 B
Overall change 7.85 kB 7.85 kB
Client Pages Modern
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_app.module.js gzip 598 B 598 B
_error.module.js gzip 2.09 kB 2.09 kB
hooks.module.js gzip 383 B 383 B
index.module.js gzip 223 B 223 B
link.module.js gzip 1.52 kB 1.52 kB
routerDirect..dule.js gzip 279 B 279 B
withRouter.m..dule.js gzip 278 B 278 B
Overall change 5.37 kB 5.37 kB
Client Build Manifests
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Rendered Page Sizes
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
index.html gzip 929 B 929 B
link.html gzip 939 B 939 B
withRouter.html gzip 925 B 925 B
Overall change 2.79 kB 2.79 kB

Serverless Mode (Increase detected ⚠️)
General Overall increase ⚠️
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
buildDuration 13.6s 13.8s ⚠️ +223ms
nodeModulesSize 55.2 MB 55.2 MB ⚠️ +273 B
Client Bundles (main, webpack, commons)
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
main-HASH.js gzip 6.25 kB 6.25 kB
webpack-HASH.js gzip 746 B 746 B
de003c3a9d30..45d6.js gzip 10.3 kB 10.3 kB
framework.a1..NSE.txt gzip 220 B 220 B
framework.a1..NSE.txt gzip 220 B 220 B
framework.HASH.js gzip 39 kB 39 kB
Overall change 56.7 kB 56.7 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
main-HASH.module.js gzip 4.79 kB 4.79 kB
webpack-HASH..dule.js gzip 746 B 746 B
de003c3a9d30..dule.js gzip 6.87 kB 6.87 kB
framework.HA..dule.js gzip 39 kB 39 kB
Overall change 51.4 kB 51.4 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
polyfills-HASH.js gzip 26.2 kB 26.2 kB
Overall change 26.2 kB 26.2 kB
Client Pages
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_app.js gzip 1.23 kB 1.23 kB
_error.js gzip 3.12 kB 3.12 kB
hooks.js gzip 663 B 663 B
index.js gzip 222 B 222 B
link.js gzip 2.06 kB 2.06 kB
routerDirect.js gzip 280 B 280 B
withRouter.js gzip 278 B 278 B
Overall change 7.85 kB 7.85 kB
Client Pages Modern
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_app.module.js gzip 598 B 598 B
_error.module.js gzip 2.09 kB 2.09 kB
hooks.module.js gzip 383 B 383 B
index.module.js gzip 223 B 223 B
link.module.js gzip 1.52 kB 1.52 kB
routerDirect..dule.js gzip 279 B 279 B
withRouter.m..dule.js gzip 278 B 278 B
Overall change 5.37 kB 5.37 kB
Client Build Manifests
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Serverless bundles Overall increase ⚠️
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_error.js 558 kB 558 kB ⚠️ +273 B
404.html 4.18 kB 4.18 kB
hooks.html 3.81 kB 3.81 kB
index.js 558 kB 558 kB ⚠️ +273 B
link.js 595 kB 595 kB ⚠️ +273 B
routerDirect.js 587 kB 587 kB ⚠️ +273 B
withRouter.js 587 kB 587 kB ⚠️ +273 B
Overall change 2.89 MB 2.89 MB ⚠️ +1.36 kB

@ericclemmons
Copy link
Author

🤔 Unsure why the serverless mode has a size increase. Happy to debug it, though it could be the additional test in development mode with isSerializeableProps?

@ijjk
Copy link
Member

ijjk commented Apr 27, 2020

Failing test suites

test/integration/size-limit/test/index.test.js

  • Production response size > should not increase the overall response size of default build
Expand output

● Production response size › should not increase the overall response size of default build

expect(received).toBeLessThanOrEqual(expected)

Expected: <= 1024
Received:    1076

  82 |     // These numbers are without gzip compression!
  83 |     const delta = responseSizesBytes - 257 * 1024
> 84 |     expect(delta).toBeLessThanOrEqual(1024) // don't increase size more than 1kb
     |                   ^
  85 |     expect(delta).toBeGreaterThanOrEqual(-1024) // don't decrease size more than 1kb without updating target
  86 |   })
  87 | 

  at Object.<anonymous> (integration/size-limit/test/index.test.js:84:19)

@ijjk
Copy link
Member

ijjk commented Apr 27, 2020

Stats from current PR

Default Server Mode (Decrease detected ✓)
General Overall increase ⚠️
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
buildDuration 12.7s 12.2s -487ms
nodeModulesSize 55.2 MB 55.2 MB ⚠️ +273 B
Page Load Tests Overall decrease ⚠️
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
/ failed reqs 0 0
/ total time (seconds) 2.027 2.018 -0.01
/ avg req/sec 1233.51 1238.65 ⚠️ +5.14
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.052 1.062 ⚠️ +0.01
/error-in-render avg req/sec 2376.17 2353.43 -22.74
Client Bundles (main, webpack, commons)
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
main-HASH.js gzip 6.27 kB 6.27 kB
webpack-HASH.js gzip 746 B 746 B
de003c3a9d30..ac5e.js gzip 10.3 kB 10.3 kB
framework.a1..NSE.txt gzip 220 B 220 B
framework.a1..NSE.txt gzip 220 B 220 B
framework.HASH.js gzip 39 kB 39 kB
Overall change 56.8 kB 56.8 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
main-HASH.module.js gzip 4.82 kB 4.82 kB
webpack-HASH..dule.js gzip 746 B 746 B
de003c3a9d30..dule.js gzip 6.88 kB 6.88 kB
framework.HA..dule.js gzip 39 kB 39 kB
Overall change 51.5 kB 51.5 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
polyfills-HASH.js gzip 26.2 kB 26.2 kB
Overall change 26.2 kB 26.2 kB
Client Pages
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_app.js gzip 1.23 kB 1.23 kB
_error.js gzip 3.12 kB 3.12 kB
hooks.js gzip 663 B 663 B
index.js gzip 222 B 222 B
link.js gzip 2.06 kB 2.06 kB
routerDirect.js gzip 280 B 280 B
withRouter.js gzip 278 B 278 B
Overall change 7.85 kB 7.85 kB
Client Pages Modern
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_app.module.js gzip 598 B 598 B
_error.module.js gzip 2.09 kB 2.09 kB
hooks.module.js gzip 383 B 383 B
index.module.js gzip 223 B 223 B
link.module.js gzip 1.52 kB 1.52 kB
routerDirect..dule.js gzip 279 B 279 B
withRouter.m..dule.js gzip 278 B 278 B
Overall change 5.37 kB 5.37 kB
Client Build Manifests
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Rendered Page Sizes
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
index.html gzip 927 B 927 B
link.html gzip 937 B 937 B
withRouter.html gzip 926 B 926 B
Overall change 2.79 kB 2.79 kB

Serverless Mode (Increase detected ⚠️)
General Overall increase ⚠️
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
buildDuration 13.3s 13s -299ms
nodeModulesSize 55.2 MB 55.2 MB ⚠️ +273 B
Client Bundles (main, webpack, commons)
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
main-HASH.js gzip 6.27 kB 6.27 kB
webpack-HASH.js gzip 746 B 746 B
de003c3a9d30..ac5e.js gzip 10.3 kB 10.3 kB
framework.a1..NSE.txt gzip 220 B 220 B
framework.a1..NSE.txt gzip 220 B 220 B
framework.HASH.js gzip 39 kB 39 kB
Overall change 56.8 kB 56.8 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
main-HASH.module.js gzip 4.82 kB 4.82 kB
webpack-HASH..dule.js gzip 746 B 746 B
de003c3a9d30..dule.js gzip 6.88 kB 6.88 kB
framework.HA..dule.js gzip 39 kB 39 kB
Overall change 51.5 kB 51.5 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
polyfills-HASH.js gzip 26.2 kB 26.2 kB
Overall change 26.2 kB 26.2 kB
Client Pages
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_app.js gzip 1.23 kB 1.23 kB
_error.js gzip 3.12 kB 3.12 kB
hooks.js gzip 663 B 663 B
index.js gzip 222 B 222 B
link.js gzip 2.06 kB 2.06 kB
routerDirect.js gzip 280 B 280 B
withRouter.js gzip 278 B 278 B
Overall change 7.85 kB 7.85 kB
Client Pages Modern
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_app.module.js gzip 598 B 598 B
_error.module.js gzip 2.09 kB 2.09 kB
hooks.module.js gzip 383 B 383 B
index.module.js gzip 223 B 223 B
link.module.js gzip 1.52 kB 1.52 kB
routerDirect..dule.js gzip 279 B 279 B
withRouter.m..dule.js gzip 278 B 278 B
Overall change 5.37 kB 5.37 kB
Client Build Manifests
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Serverless bundles Overall increase ⚠️
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_error.js 558 kB 558 kB ⚠️ +273 B
404.html 4.18 kB 4.18 kB
hooks.html 3.81 kB 3.81 kB
index.js 558 kB 558 kB ⚠️ +273 B
link.js 595 kB 595 kB ⚠️ +273 B
routerDirect.js 587 kB 587 kB ⚠️ +273 B
withRouter.js 587 kB 587 kB ⚠️ +273 B
Overall change 2.89 MB 2.89 MB ⚠️ +1.36 kB

@ericclemmons
Copy link
Author

I'm going to investigate https://github.com/zeit/next.js/blob/canary/test/integration/size-limit/test/index.test.js & diff the output to determine what the increase actually is.

@ijjk
Copy link
Member

ijjk commented Apr 29, 2020

Stats from current PR

Default Server Mode (Decrease detected ✓)
General Overall increase ⚠️
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
buildDuration 12.7s 13s ⚠️ +233ms
nodeModulesSize 55.2 MB 55.2 MB ⚠️ +273 B
Page Load Tests Overall decrease ⚠️
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
/ failed reqs 0 0
/ total time (seconds) 2.292 2.176 -0.12
/ avg req/sec 1090.66 1148.88 ⚠️ +58.22
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.262 1.302 ⚠️ +0.04
/error-in-render avg req/sec 1981.13 1920.74 -60.39
Client Bundles (main, webpack, commons)
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
main-HASH.js gzip 6.26 kB 6.26 kB
webpack-HASH.js gzip 746 B 746 B
de003c3a9d30..e8e1.js gzip 10.3 kB 10.3 kB
framework.a1..NSE.txt gzip 220 B 220 B
framework.a1..NSE.txt gzip 220 B 220 B
framework.HASH.js gzip 39.2 kB 39.2 kB
Overall change 56.9 kB 56.9 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
main-HASH.module.js gzip 4.81 kB 4.81 kB
webpack-HASH..dule.js gzip 746 B 746 B
de003c3a9d30..dule.js gzip 6.88 kB 6.88 kB
framework.HA..dule.js gzip 39.2 kB 39.2 kB
Overall change 51.7 kB 51.7 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
polyfills-HASH.js gzip 26.3 kB 26.3 kB
Overall change 26.3 kB 26.3 kB
Client Pages
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_app.js gzip 1.23 kB 1.23 kB
_error.js gzip 3.15 kB 3.15 kB
hooks.js gzip 663 B 663 B
index.js gzip 222 B 222 B
link.js gzip 2.06 kB 2.06 kB
routerDirect.js gzip 280 B 280 B
withRouter.js gzip 278 B 278 B
Overall change 7.88 kB 7.88 kB
Client Pages Modern
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_app.module.js gzip 598 B 598 B
_error.module.js gzip 2.09 kB 2.09 kB
hooks.module.js gzip 383 B 383 B
index.module.js gzip 223 B 223 B
link.module.js gzip 1.52 kB 1.52 kB
routerDirect..dule.js gzip 279 B 279 B
withRouter.m..dule.js gzip 278 B 278 B
Overall change 5.37 kB 5.37 kB
Client Build Manifests
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Rendered Page Sizes
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
index.html gzip 927 B 927 B
link.html gzip 937 B 937 B
withRouter.html gzip 925 B 925 B
Overall change 2.79 kB 2.79 kB

Serverless Mode (Increase detected ⚠️)
General Overall increase ⚠️
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
buildDuration 13.6s 14s ⚠️ +336ms
nodeModulesSize 55.2 MB 55.2 MB ⚠️ +273 B
Client Bundles (main, webpack, commons)
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
main-HASH.js gzip 6.26 kB 6.26 kB
webpack-HASH.js gzip 746 B 746 B
de003c3a9d30..e8e1.js gzip 10.3 kB 10.3 kB
framework.a1..NSE.txt gzip 220 B 220 B
framework.a1..NSE.txt gzip 220 B 220 B
framework.HASH.js gzip 39.2 kB 39.2 kB
Overall change 56.9 kB 56.9 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
main-HASH.module.js gzip 4.81 kB 4.81 kB
webpack-HASH..dule.js gzip 746 B 746 B
de003c3a9d30..dule.js gzip 6.88 kB 6.88 kB
framework.HA..dule.js gzip 39.2 kB 39.2 kB
Overall change 51.7 kB 51.7 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
polyfills-HASH.js gzip 26.3 kB 26.3 kB
Overall change 26.3 kB 26.3 kB
Client Pages
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_app.js gzip 1.23 kB 1.23 kB
_error.js gzip 3.15 kB 3.15 kB
hooks.js gzip 663 B 663 B
index.js gzip 222 B 222 B
link.js gzip 2.06 kB 2.06 kB
routerDirect.js gzip 280 B 280 B
withRouter.js gzip 278 B 278 B
Overall change 7.88 kB 7.88 kB
Client Pages Modern
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_app.module.js gzip 598 B 598 B
_error.module.js gzip 2.09 kB 2.09 kB
hooks.module.js gzip 383 B 383 B
index.module.js gzip 223 B 223 B
link.module.js gzip 1.52 kB 1.52 kB
routerDirect..dule.js gzip 279 B 279 B
withRouter.m..dule.js gzip 278 B 278 B
Overall change 5.37 kB 5.37 kB
Client Build Manifests
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Serverless bundles Overall increase ⚠️
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_error.js 557 kB 558 kB ⚠️ +273 B
404.html 4.18 kB 4.18 kB
hooks.html 3.81 kB 3.81 kB
index.js 557 kB 558 kB ⚠️ +273 B
link.js 595 kB 595 kB ⚠️ +273 B
routerDirect.js 587 kB 588 kB ⚠️ +273 B
withRouter.js 588 kB 588 kB ⚠️ +273 B
Overall change 2.89 MB 2.89 MB ⚠️ +1.36 kB

@ijjk
Copy link
Member

ijjk commented Apr 29, 2020

Failing test suites

test/integration/getserversideprops/test/index.test.js

  • getServerSideProps > production mode > should output routes-manifest correctly
  • getServerSideProps > serverless mode > should output routes-manifest correctly
Expand output

● getServerSideProps › serverless mode › should output routes-manifest correctly

expect(received).toEqual(expected) // deep equality

- Expected
+ Received

@@ -60,15 +60,15 @@
      "dataRouteRegex": "^\\/_next\\/data\\/RuWkJHLMAa9zucfLD47Tp\\/something.json$",
      "page": "/something",
    },
    Object {
      "dataRouteRegex": "^\\/_next\\/data\\/RuWkJHLMAa9zucfLD47Tp\\/to-json.json$",
-     "namedDataRouteRegex": "^/_next/data/RuWkJHLMAa9zucfLD47Tp/user/(?<user>[^/]+?)/profile\\.json$",
      "page": "/to-json",
    },
    Object {
      "dataRouteRegex": "^\\/_next\\/data\\/RuWkJHLMAa9zucfLD47Tp\\/user\\/([^\\/]+?)\\/profile\\.json$",
+     "namedDataRouteRegex": "^/_next/data/RuWkJHLMAa9zucfLD47Tp/user/(?<user>[^/]+?)/profile\\.json$",
      "page": "/user/[user]/profile",
      "routeKeys": Array [
        "user",
      ],
    },

  504 |       }
  505 | 
> 506 |       expect(dataRoutes).toEqual(expectedManifestRoutes())
      |                          ^
  507 |     })
  508 | 
  509 |     it('should set default caching header', async () => {

  at Object.<anonymous> (integration/getserversideprops/test/index.test.js:506:26)

● getServerSideProps › production mode › should output routes-manifest correctly

expect(received).toEqual(expected) // deep equality

- Expected
+ Received

@@ -60,15 +60,15 @@
      "dataRouteRegex": "^\\/_next\\/data\\/CuqdB4bPdhV6FL7BK8gsE\\/something.json$",
      "page": "/something",
    },
    Object {
      "dataRouteRegex": "^\\/_next\\/data\\/CuqdB4bPdhV6FL7BK8gsE\\/to-json.json$",
-     "namedDataRouteRegex": "^/_next/data/CuqdB4bPdhV6FL7BK8gsE/user/(?<user>[^/]+?)/profile\\.json$",
      "page": "/to-json",
    },
    Object {
      "dataRouteRegex": "^\\/_next\\/data\\/CuqdB4bPdhV6FL7BK8gsE\\/user\\/([^\\/]+?)\\/profile\\.json$",
+     "namedDataRouteRegex": "^/_next/data/CuqdB4bPdhV6FL7BK8gsE/user/(?<user>[^/]+?)/profile\\.json$",
      "page": "/user/[user]/profile",
      "routeKeys": Array [
        "user",
      ],
    },

  504 |       }
  505 | 
> 506 |       expect(dataRoutes).toEqual(expectedManifestRoutes())
      |                          ^
  507 |     })
  508 | 
  509 |     it('should set default caching header', async () => {

  at Object.<anonymous> (integration/getserversideprops/test/index.test.js:506:26)

@ijjk
Copy link
Member

ijjk commented May 19, 2020

Stats from current PR

Default Server Mode (Decrease detected ✓)
General Overall increase ⚠️
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
buildDuration 13.3s 13.5s ⚠️ +168ms
nodeModulesSize 60.4 MB 60.4 MB ⚠️ +273 B
Page Load Tests Overall decrease ⚠️
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
/ failed reqs 0 0
/ total time (seconds) 2.186 2.236 ⚠️ +0.05
/ avg req/sec 1143.58 1118.12 -25.46
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.473 1.498 ⚠️ +0.02
/error-in-render avg req/sec 1696.87 1668.82 -28.05
Client Bundles (main, webpack, commons)
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
main-HASH.js gzip 6.71 kB 6.71 kB
webpack-HASH.js gzip 746 B 746 B
de003c3a9d30..fc14.js gzip 10.5 kB 10.5 kB
framework.HASH.js gzip 39.1 kB 39.1 kB
Overall change 57.1 kB 57.1 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
main-HASH.module.js gzip 5.74 kB 5.74 kB
webpack-HASH..dule.js gzip 746 B 746 B
de003c3a9d30..dule.js gzip 6.88 kB 6.88 kB
framework.HA..dule.js gzip 39.1 kB 39.1 kB
Overall change 52.5 kB 52.5 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
polyfills-HASH.js gzip 26.3 kB 26.3 kB
Overall change 26.3 kB 26.3 kB
Client Pages
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_app.js gzip 1.26 kB 1.26 kB
_error.js gzip 3.28 kB 3.28 kB
hooks.js gzip 881 B 881 B
index.js gzip 222 B 222 B
link.js gzip 2.06 kB 2.06 kB
routerDirect.js gzip 279 B 279 B
withRouter.js gzip 278 B 278 B
Overall change 8.26 kB 8.26 kB
Client Pages Modern
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_app.module.js gzip 604 B 604 B
_error.module.js gzip 2.09 kB 2.09 kB
hooks.module.js gzip 383 B 383 B
index.module.js gzip 223 B 223 B
link.module.js gzip 1.52 kB 1.52 kB
routerDirect..dule.js gzip 281 B 281 B
withRouter.m..dule.js gzip 278 B 278 B
Overall change 5.38 kB 5.38 kB
Client Build Manifests
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Rendered Page Sizes
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
index.html gzip 927 B 927 B
link.html gzip 937 B 937 B
withRouter.html gzip 924 B 924 B
Overall change 2.79 kB 2.79 kB

Serverless Mode (Increase detected ⚠️)
General Overall increase ⚠️
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
buildDuration 14s 14.2s ⚠️ +188ms
nodeModulesSize 60.4 MB 60.4 MB ⚠️ +273 B
Client Bundles (main, webpack, commons)
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
main-HASH.js gzip 6.71 kB 6.71 kB
webpack-HASH.js gzip 746 B 746 B
de003c3a9d30..fc14.js gzip 10.5 kB 10.5 kB
framework.HASH.js gzip 39.1 kB 39.1 kB
Overall change 57.1 kB 57.1 kB
Client Bundles (main, webpack, commons) Modern
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
main-HASH.module.js gzip 5.74 kB 5.74 kB
webpack-HASH..dule.js gzip 746 B 746 B
de003c3a9d30..dule.js gzip 6.88 kB 6.88 kB
framework.HA..dule.js gzip 39.1 kB 39.1 kB
Overall change 52.5 kB 52.5 kB
Legacy Client Bundles (polyfills)
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
polyfills-HASH.js gzip 26.3 kB 26.3 kB
Overall change 26.3 kB 26.3 kB
Client Pages
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_app.js gzip 1.26 kB 1.26 kB
_error.js gzip 3.28 kB 3.28 kB
hooks.js gzip 881 B 881 B
index.js gzip 222 B 222 B
link.js gzip 2.06 kB 2.06 kB
routerDirect.js gzip 279 B 279 B
withRouter.js gzip 278 B 278 B
Overall change 8.26 kB 8.26 kB
Client Pages Modern
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_app.module.js gzip 604 B 604 B
_error.module.js gzip 2.09 kB 2.09 kB
hooks.module.js gzip 383 B 383 B
index.module.js gzip 223 B 223 B
link.module.js gzip 1.52 kB 1.52 kB
routerDirect..dule.js gzip 281 B 281 B
withRouter.m..dule.js gzip 278 B 278 B
Overall change 5.38 kB 5.38 kB
Client Build Manifests
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_buildManifest.js gzip 61 B 61 B
_buildManife..dule.js gzip 61 B 61 B
Overall change 122 B 122 B
Serverless bundles Overall increase ⚠️
zeit/next.js canary ericclemmons/next.js 11993-getServerSideProps-toJSON Change
_error.js 851 kB 851 kB ⚠️ +273 B
404.html 4.18 kB 4.18 kB
hooks.html 3.81 kB 3.81 kB
index.js 851 kB 851 kB ⚠️ +273 B
link.js 888 kB 888 kB ⚠️ +273 B
routerDirect.js 880 kB 881 kB ⚠️ +273 B
withRouter.js 881 kB 881 kB ⚠️ +273 B
Overall change 4.36 MB 4.36 MB ⚠️ +1.36 kB

@ijjk
Copy link
Member

ijjk commented May 19, 2020

Failing test suites

test/integration/getserversideprops/test/index.test.js

  • getServerSideProps > production mode > should output routes-manifest correctly
  • getServerSideProps > serverless mode > should output routes-manifest correctly
Expand output

● getServerSideProps › serverless mode › should output routes-manifest correctly

expect(received).toEqual(expected) // deep equality

- Expected  - 1
+ Received  + 1

@@ -60,15 +60,15 @@
      "dataRouteRegex": "^\\/_next\\/data\\/zmxRcmVRqrtVMlqZlk02i\\/something.json$",
      "page": "/something",
    },
    Object {
      "dataRouteRegex": "^\\/_next\\/data\\/zmxRcmVRqrtVMlqZlk02i\\/to-json.json$",
-     "namedDataRouteRegex": "^/_next/data/zmxRcmVRqrtVMlqZlk02i/user/(?<user>[^/]+?)/profile\\.json$",
      "page": "/to-json",
    },
    Object {
      "dataRouteRegex": "^\\/_next\\/data\\/zmxRcmVRqrtVMlqZlk02i\\/user\\/([^\\/]+?)\\/profile\\.json$",
+     "namedDataRouteRegex": "^/_next/data/zmxRcmVRqrtVMlqZlk02i/user/(?<user>[^/]+?)/profile\\.json$",
      "page": "/user/[user]/profile",
      "routeKeys": Array [
        "user",
      ],
    },

  510 |       }
  511 | 
> 512 |       expect(dataRoutes).toEqual(expectedManifestRoutes())
      |                          ^
  513 |     })
  514 | 
  515 |     it('should set default caching header', async () => {

  at Object.<anonymous> (integration/getserversideprops/test/index.test.js:512:26)

● getServerSideProps › production mode › should output routes-manifest correctly

expect(received).toEqual(expected) // deep equality

- Expected  - 1
+ Received  + 1

@@ -60,15 +60,15 @@
      "dataRouteRegex": "^\\/_next\\/data\\/ghaI2ZsDnWqMZ3YxScvMI\\/something.json$",
      "page": "/something",
    },
    Object {
      "dataRouteRegex": "^\\/_next\\/data\\/ghaI2ZsDnWqMZ3YxScvMI\\/to-json.json$",
-     "namedDataRouteRegex": "^/_next/data/ghaI2ZsDnWqMZ3YxScvMI/user/(?<user>[^/]+?)/profile\\.json$",
      "page": "/to-json",
    },
    Object {
      "dataRouteRegex": "^\\/_next\\/data\\/ghaI2ZsDnWqMZ3YxScvMI\\/user\\/([^\\/]+?)\\/profile\\.json$",
+     "namedDataRouteRegex": "^/_next/data/ghaI2ZsDnWqMZ3YxScvMI/user/(?<user>[^/]+?)/profile\\.json$",
      "page": "/user/[user]/profile",
      "routeKeys": Array [
        "user",
      ],
    },

  510 |       }
  511 | 
> 512 |       expect(dataRoutes).toEqual(expectedManifestRoutes())
      |                          ^
  513 |     })
  514 | 
  515 |     it('should set default caching header', async () => {

  at Object.<anonymous> (integration/getserversideprops/test/index.test.js:512:26)

Copy link
Member

@Timer Timer left a comment

Choose a reason for hiding this comment

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

  1. It's not clear to me why toJSON wouldn't be allowed to return a string. IMO, any valid JSON output here would be accepted.

  2. This isn't called on the server-side, so there's still the possibility of a hydration mismatch. Especially if toJSON selectively plucks fields.

Are we sure something like this is necessary? I think it'd be better handled by doing a .map() across your results array in getServerSideProps.

@ericclemmons
Copy link
Author

@Timer Thanks for getting around to this. Your comments aren't associated with code, so I'll do the best I can to infer:

1. It's not clear to me why `toJSON` wouldn't be allowed to return a `string`. IMO, any valid JSON output here would be accepted.

This restriction can be loosened. The tests already accounted for Date, which is an object that becomes serialized. I opted for strictness because Class-based structures can be traversed with dot-notation. So requiring .toJSON to be an Object allowed for symmetry (e.g. user.attributes.email) on both client & server.

JSON.stringify(new Date())
"\"2020-05-22T22:04:30.915Z\""

See: #11993 (comment),

2. This isn't called on the server-side, so there's still the possibility of a hydration mismatch. Especially if `toJSON` selectively plucks fields.

What part's not called on the server-side?

Are we sure something like this is necessary? I think it'd be better handled by doing a .map() across your results array in getServerSideProps.

When you own the models, yes, .map isn't a big lift. This is primarily for leveraging the existing JSON.stringify behavior of .toJSON at the top-level when serializing so that returning models from a library (e.g. Amplify JS, MobX, MST) "just works".

See: #11993 (comment)

@timneutkens
Copy link
Member

What part's not called on the server-side?

JSON.stringify is only called for serializing the object to send it to the client-side. The returned value is just passed through in the Node.js environment as we don't want to have the overhead of JSON.parse(JSON.stringify(data)).
The reason the checking is strict is that other it leaves users with ways to introduce hydration bugs which are hard to surface and hard to track down (introducing performance issues as React throws away the DOM on a hydration error).

@Timer
Copy link
Member

Timer commented May 23, 2020

Since adding this feature would require we run it server-side, I'm not sure it's worth doing so. For larger objects, this could introduce significant latency in production mode. Users who bump into this should use .map() on those specific objects.

Thank you for the PR.

Could you send a PR updating our documentation explaining this?

@Timer Timer closed this May 23, 2020
@ericclemmons
Copy link
Author

ericclemmons commented May 25, 2020 via email

@timneutkens
Copy link
Member

The check happens in development in order to make sure you don't introduce hydration bugs that you can't track down easily (as explained earlier) however serialization is only ran to create the JSON string included in the __NEXT_DATA__ script tag. Serialization is not ran on the server-side return value before it's passed to the React component

@jacobrask
Copy link

We're currently using a custom toJSON to remove some large data blobs that we only need at first render and don't want to cache in __NEXT_DATA__. Would there be another way to cover this use case if this PR is not accepted?

@ericclemmons
Copy link
Author

Since adding this feature would require we run it server-side, I'm not sure it's worth doing so. For larger objects, this could introduce significant latency in production mode. Users who bump into this should use .map() on those specific objects.

@Timer @timneutkens I don't think this is true for my PR. This PR explicitly only checks for the .toJSON and only then recursively checks if that returned object is serializeable. That means that models would have to opt-in to this before, minimizing any performance regressions.

In fact, this PR even validates that the .toJSON result is a valid nested object (since on the server it is passed by reference without serialization), so that prop.foo.bar works on the server just as it does on the client (when it finally is serialized).

Can you reconsider this PR and what it would take to allow this?

@timneutkens
Copy link
Member

The serialized result will differ in production mode when the serialization check is not called. You can see that happen when you run this:

yarn next build test/integration/getserversideprops
yarn next start test/integration/getserversideprops

And open http://localhost:3000/to-json. The server-side result will differ from the client-side result.

Potentially the overhead of running the serialization could be worth it but you'd have to do a deeper investigation of what the impact of that is on applications with a lot of data. Potentially the result of serializing could be passed to JSON.stringify making the overhead very minimal. The the problem with this type of traversal is that it would become slower the more nested objects are added. Potentially you could do something clever with proxies and only convert the properties that were called during rendering into json

@vercel vercel locked as resolved and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

getServerSideProps cannot be serialized as JSON. Please only return JSON serializable data types
6 participants