-
Notifications
You must be signed in to change notification settings - Fork 27.4k
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
Style improvements on MongoDB example #20515
Style improvements on MongoDB example #20515
Conversation
Stats from current PRDefault Server Mode (Decrease detected ✓)General
Page Load Tests Overall decrease
|
vercel/next.js canary | LauraBeatris/next.js improve-mongo-example-code-style | Change | |
---|---|---|---|
/ failed reqs | 0 | 0 | ✓ |
/ total time (seconds) | 2.052 | 2.071 | |
/ avg req/sec | 1218.24 | 1207.02 | |
/error-in-render failed reqs | 0 | 0 | ✓ |
/error-in-render total time (seconds) | 1.232 | 1.318 | |
/error-in-render avg req/sec | 2029.92 | 1896.72 |
Client Bundles (main, webpack, commons)
vercel/next.js canary | LauraBeatris/next.js improve-mongo-example-code-style | Change | |
---|---|---|---|
677f882d2ed8..5e70.js gzip | 12.8 kB | 12.8 kB | ✓ |
framework.HASH.js gzip | 39 kB | 39 kB | ✓ |
main-e0d2962..b163.js gzip | 6.56 kB | 6.56 kB | ✓ |
webpack-95c2..e870.js gzip | 751 B | 751 B | ✓ |
Overall change | 59 kB | 59 kB | ✓ |
Legacy Client Bundles (polyfills)
vercel/next.js canary | LauraBeatris/next.js improve-mongo-example-code-style | Change | |
---|---|---|---|
polyfills-d3..23f6.js gzip | 31 kB | 31 kB | ✓ |
Overall change | 31 kB | 31 kB | ✓ |
Client Pages
vercel/next.js canary | LauraBeatris/next.js improve-mongo-example-code-style | Change | |
---|---|---|---|
_app-0d19cb6..5497.js gzip | 1.28 kB | 1.28 kB | ✓ |
_error-85785..a9f3.js gzip | 3.44 kB | 3.44 kB | ✓ |
hooks-42456f..0c06.js gzip | 887 B | 887 B | ✓ |
index-8081ce..e44f.js gzip | 227 B | 227 B | ✓ |
link-0ab9f83..fa00.js gzip | 1.61 kB | 1.61 kB | ✓ |
routerDirect..c3d8.js gzip | 303 B | 303 B | ✓ |
withRouter-0..a68e.js gzip | 302 B | 302 B | ✓ |
Overall change | 8.05 kB | 8.05 kB | ✓ |
Client Build Manifests
vercel/next.js canary | LauraBeatris/next.js improve-mongo-example-code-style | Change | |
---|---|---|---|
_buildManifest.js gzip | 323 B | 323 B | ✓ |
Overall change | 323 B | 323 B | ✓ |
Rendered Page Sizes
vercel/next.js canary | LauraBeatris/next.js improve-mongo-example-code-style | Change | |
---|---|---|---|
index.html gzip | 612 B | 612 B | ✓ |
link.html gzip | 620 B | 620 B | ✓ |
withRouter.html gzip | 607 B | 607 B | ✓ |
Overall change | 1.84 kB | 1.84 kB | ✓ |
Serverless Mode
General
vercel/next.js canary | LauraBeatris/next.js improve-mongo-example-code-style | Change | |
---|---|---|---|
buildDuration | 12.3s | 12.3s | |
nodeModulesSize | 82.6 MB | 82.6 MB | ✓ |
Client Bundles (main, webpack, commons)
vercel/next.js canary | LauraBeatris/next.js improve-mongo-example-code-style | Change | |
---|---|---|---|
677f882d2ed8..5e70.js gzip | 12.8 kB | 12.8 kB | ✓ |
framework.HASH.js gzip | 39 kB | 39 kB | ✓ |
main-e0d2962..b163.js gzip | 6.56 kB | 6.56 kB | ✓ |
webpack-95c2..e870.js gzip | 751 B | 751 B | ✓ |
Overall change | 59 kB | 59 kB | ✓ |
Legacy Client Bundles (polyfills)
vercel/next.js canary | LauraBeatris/next.js improve-mongo-example-code-style | Change | |
---|---|---|---|
polyfills-d3..23f6.js gzip | 31 kB | 31 kB | ✓ |
Overall change | 31 kB | 31 kB | ✓ |
Client Pages
vercel/next.js canary | LauraBeatris/next.js improve-mongo-example-code-style | Change | |
---|---|---|---|
_app-0d19cb6..5497.js gzip | 1.28 kB | 1.28 kB | ✓ |
_error-85785..a9f3.js gzip | 3.44 kB | 3.44 kB | ✓ |
hooks-42456f..0c06.js gzip | 887 B | 887 B | ✓ |
index-8081ce..e44f.js gzip | 227 B | 227 B | ✓ |
link-0ab9f83..fa00.js gzip | 1.61 kB | 1.61 kB | ✓ |
routerDirect..c3d8.js gzip | 303 B | 303 B | ✓ |
withRouter-0..a68e.js gzip | 302 B | 302 B | ✓ |
Overall change | 8.05 kB | 8.05 kB | ✓ |
Client Build Manifests
vercel/next.js canary | LauraBeatris/next.js improve-mongo-example-code-style | Change | |
---|---|---|---|
_buildManifest.js gzip | 323 B | 323 B | ✓ |
Overall change | 323 B | 323 B | ✓ |
Serverless bundles
vercel/next.js canary | LauraBeatris/next.js improve-mongo-example-code-style | Change | |
---|---|---|---|
_error.js | 1 MB | 1 MB | ✓ |
404.html | 2.67 kB | 2.67 kB | ✓ |
hooks.html | 1.92 kB | 1.92 kB | ✓ |
index.js | 1 MB | 1 MB | ✓ |
link.js | 1.06 MB | 1.06 MB | ✓ |
routerDirect.js | 1.05 MB | 1.05 MB | ✓ |
withRouter.js | 1.05 MB | 1.05 MB | ✓ |
Overall change | 5.16 MB | 5.16 MB | ✓ |
Stats from current PRDefault Server Mode (Decrease detected ✓)General
Page Load Tests Overall decrease
|
vercel/next.js canary | LauraBeatris/next.js improve-mongo-example-code-style | Change | |
---|---|---|---|
/ failed reqs | 0 | 0 | ✓ |
/ total time (seconds) | 1.739 | 1.729 | -0.01 |
/ avg req/sec | 1437.93 | 1445.89 | +7.96 |
/error-in-render failed reqs | 0 | 0 | ✓ |
/error-in-render total time (seconds) | 1.085 | 1.111 | |
/error-in-render avg req/sec | 2304.39 | 2250.44 |
Client Bundles (main, webpack, commons)
vercel/next.js canary | LauraBeatris/next.js improve-mongo-example-code-style | Change | |
---|---|---|---|
677f882d2ed8..5e70.js gzip | 12.8 kB | 12.8 kB | ✓ |
framework.HASH.js gzip | 39 kB | 39 kB | ✓ |
main-e0d2962..b163.js gzip | 6.56 kB | 6.56 kB | ✓ |
webpack-95c2..e870.js gzip | 751 B | 751 B | ✓ |
Overall change | 59 kB | 59 kB | ✓ |
Legacy Client Bundles (polyfills)
vercel/next.js canary | LauraBeatris/next.js improve-mongo-example-code-style | Change | |
---|---|---|---|
polyfills-d3..23f6.js gzip | 31 kB | 31 kB | ✓ |
Overall change | 31 kB | 31 kB | ✓ |
Client Pages
vercel/next.js canary | LauraBeatris/next.js improve-mongo-example-code-style | Change | |
---|---|---|---|
_app-0d19cb6..5497.js gzip | 1.28 kB | 1.28 kB | ✓ |
_error-85785..a9f3.js gzip | 3.44 kB | 3.44 kB | ✓ |
hooks-42456f..0c06.js gzip | 887 B | 887 B | ✓ |
index-8081ce..e44f.js gzip | 227 B | 227 B | ✓ |
link-0ab9f83..fa00.js gzip | 1.61 kB | 1.61 kB | ✓ |
routerDirect..c3d8.js gzip | 303 B | 303 B | ✓ |
withRouter-0..a68e.js gzip | 302 B | 302 B | ✓ |
Overall change | 8.05 kB | 8.05 kB | ✓ |
Client Build Manifests
vercel/next.js canary | LauraBeatris/next.js improve-mongo-example-code-style | Change | |
---|---|---|---|
_buildManifest.js gzip | 323 B | 323 B | ✓ |
Overall change | 323 B | 323 B | ✓ |
Rendered Page Sizes
vercel/next.js canary | LauraBeatris/next.js improve-mongo-example-code-style | Change | |
---|---|---|---|
index.html gzip | 612 B | 612 B | ✓ |
link.html gzip | 620 B | 620 B | ✓ |
withRouter.html gzip | 607 B | 607 B | ✓ |
Overall change | 1.84 kB | 1.84 kB | ✓ |
Serverless Mode
General
vercel/next.js canary | LauraBeatris/next.js improve-mongo-example-code-style | Change | |
---|---|---|---|
buildDuration | 10.1s | 10.1s | -33ms |
nodeModulesSize | 82.6 MB | 82.6 MB | ✓ |
Client Bundles (main, webpack, commons)
vercel/next.js canary | LauraBeatris/next.js improve-mongo-example-code-style | Change | |
---|---|---|---|
677f882d2ed8..5e70.js gzip | 12.8 kB | 12.8 kB | ✓ |
framework.HASH.js gzip | 39 kB | 39 kB | ✓ |
main-e0d2962..b163.js gzip | 6.56 kB | 6.56 kB | ✓ |
webpack-95c2..e870.js gzip | 751 B | 751 B | ✓ |
Overall change | 59 kB | 59 kB | ✓ |
Legacy Client Bundles (polyfills)
vercel/next.js canary | LauraBeatris/next.js improve-mongo-example-code-style | Change | |
---|---|---|---|
polyfills-d3..23f6.js gzip | 31 kB | 31 kB | ✓ |
Overall change | 31 kB | 31 kB | ✓ |
Client Pages
vercel/next.js canary | LauraBeatris/next.js improve-mongo-example-code-style | Change | |
---|---|---|---|
_app-0d19cb6..5497.js gzip | 1.28 kB | 1.28 kB | ✓ |
_error-85785..a9f3.js gzip | 3.44 kB | 3.44 kB | ✓ |
hooks-42456f..0c06.js gzip | 887 B | 887 B | ✓ |
index-8081ce..e44f.js gzip | 227 B | 227 B | ✓ |
link-0ab9f83..fa00.js gzip | 1.61 kB | 1.61 kB | ✓ |
routerDirect..c3d8.js gzip | 303 B | 303 B | ✓ |
withRouter-0..a68e.js gzip | 302 B | 302 B | ✓ |
Overall change | 8.05 kB | 8.05 kB | ✓ |
Client Build Manifests
vercel/next.js canary | LauraBeatris/next.js improve-mongo-example-code-style | Change | |
---|---|---|---|
_buildManifest.js gzip | 323 B | 323 B | ✓ |
Overall change | 323 B | 323 B | ✓ |
Serverless bundles
vercel/next.js canary | LauraBeatris/next.js improve-mongo-example-code-style | Change | |
---|---|---|---|
_error.js | 1 MB | 1 MB | ✓ |
404.html | 2.67 kB | 2.67 kB | ✓ |
hooks.html | 1.92 kB | 1.92 kB | ✓ |
index.js | 1 MB | 1 MB | ✓ |
link.js | 1.06 MB | 1.06 MB | ✓ |
routerDirect.js | 1.05 MB | 1.05 MB | ✓ |
withRouter.js | 1.05 MB | 1.05 MB | ✓ |
Overall change | 5.16 MB | 5.16 MB | ✓ |
|
||
if (!cached) { | ||
cached = global.mongo = {} | ||
} | ||
|
||
export async function connectToDatabase() { | ||
if (cached.conn) return cached.conn | ||
if (cached.conn) { | ||
return cached.conn | ||
} | ||
|
||
if (!cached.promise) { | ||
const conn = {} | ||
|
||
const opts = { | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
} | ||
|
||
cached.promise = MongoClient.connect(MONGODB_URI, opts) | ||
.then((client) => { | ||
conn.client = client | ||
|
||
return client.db(MONGODB_DB) | ||
}) | ||
.then((db) => { | ||
conn.db = db | ||
|
||
cached.conn = conn | ||
}) | ||
} | ||
|
||
await cached.promise | ||
|
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.
@LauraBeatris We only worry about changes requested by eslint and prettier. Code style changes like this aren't required and it's never going to be perfect for everybody (I for example don't like that much spacing), so don't worry too much about this in the future.
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.
Got it!
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.
@LauraBeatris LGTM. Thank you!
I've looked at the example code and saw some consistent issues related to code style. The changes applied to this PR fixes the following points:
There were line breaks between statements on
pages/index.js
And this wasn't being applied to the MongoDB utility:
And also, as shown in the snippet above, there are different styles of if statements being used.
With that being said, the reason I made this PR is because I think that this kind of inconsistent arises questions when a contributor looks to the codebase, even if this is a simple example.