Commit graph

7010 commits

Author SHA1 Message Date
Jens Meindertsma
c021662d1e
Fix with-msw example (#17695)
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**
```
Page                                                           Size     First Load JS
┌ λ /                                                          479 B          58.9 kB
├   /_app                                                      0 B            58.4 kB
└ ○ /404                                                       3.44 kB        61.9 kB
+ First Load JS shared by all                                  58.4 kB
  ├ chunks/f6078781a05fe1bcb0902d23dbbb2662c8d200b3.b1b405.js  10.3 kB
  ├ chunks/framework.cb05d5.js                                 39.9 kB
  ├ chunks/main.a140d5.js                                      7.28 kB
  ├ chunks/pages/_app.b90a57.js                                277 B
  └ chunks/webpack.e06743.js                                   751 B

λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
○  (Static)  automatically rendered as static HTML (uses no initial props)
●  (SSG)     automatically generated as static HTML + JSON (uses getStaticProps)
   (ISR)     incremental static regeneration (uses revalidate in getStaticProps)
```
**Build size after implementing MSW according to the `with-msw` example**
```
Page                                                           Size     First Load JS
┌ λ /                                                          479 B          71.6 kB
├   /_app                                                      0 B            71.1 kB
└ ○ /404                                                       3.44 kB        74.6 kB
+ First Load JS shared by all                                  71.1 kB
  ├ chunks/f6078781a05fe1bcb0902d23dbbb2662c8d200b3.b1b405.js  10.3 kB
  ├ chunks/framework.cb05d5.js                                 39.9 kB
  ├ chunks/main.a140d5.js                                      7.28 kB
  ├ chunks/pages/_app.c58a6f.js                                13 kB
  └ chunks/webpack.e06743.js                                   751 B

λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
○  (Static)  automatically rendered as static HTML (uses no initial props)
●  (SSG)     automatically generated as static HTML + JSON (uses getStaticProps)
   (ISR)     incremental static regeneration (uses revalidate in getStaticProps)
```

There 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: 
```js
if (process.env.NEXT_PUBLIC_API_MOCKING === 'enabled') {
  require('../mocks')
}
```
Removing this reduces the `_app` First Load JS to what it was previously. The `NEXT_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:
```js
if (process.env.NODE_ENV !== 'production') {
  require('../mocks')
}
```
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:
```js
if (true) {
  require('../mocks')
}
```

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.
2020-10-08 18:19:29 +00:00
JJ Kasper
bbc1a21c74
Update to have default locale matched on root (#17669)
Follow-up PR to https://github.com/vercel/next.js/pull/17370 when the path is not prefixed with a locale and the default locale is the detected locale it doesn't redirect to locale prefixed variant. If the default locale path is visited and the default locale is visited this also redirects to the root removing the un-necessary locale in the URL. 

This also exposes the `defaultLocale` on the router since the RFC mentions `Setting a defaultLocale is required in every i18n library so it'd be useful for Next.js to provide it to the application.` although doesn't explicitly spec where we want to expose it. If we want to expose it differently this can be updated.
2020-10-08 11:12:17 +00:00
Henrik Wenz
a79bcfb73a
Fix with-apollo example (#17686)
# Issue

The cache updates are performed in a wrong way, resulting in a duplicate collection:

**Error:**

```log
webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:88 Warning: Encountered two children with the same key, `6f3f7265-0d97-4708-a3ea-7dee76dc0a0a`. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.
```

**Video:**

![broken](https://user-images.githubusercontent.com/1265681/95336501-0c170180-08b1-11eb-9273-6ac9e37ceb41.gif)

# Fix

**Video:**

![fixed](https://user-images.githubusercontent.com/1265681/95336538-15a06980-08b1-11eb-8d5e-6acc07e16138.gif)
2020-10-08 03:45:28 +00:00
JJ Kasper
b2d1d87e7f
Add initial changes for i18n support (#17370)
This adds the initial changes outlined in the [i18n routing RFC](https://github.com/vercel/next.js/discussions/17078). This currently treats the locale prefix on routes similar to how the basePath is treated in that the config doesn't require any changes to your pages directory and is automatically stripped/added based on the detected locale that should be used. 

Currently redirecting occurs on the `/` route if a locale is detected regardless of if an optional catch-all route would match the `/` route or not we may want to investigate whether we want to disable this redirection automatically if an `/index.js` file isn't present at root of the pages directory. 

TODO: 

- [x] ensure locale detection/populating works in serverless mode correctly
- [x] add tests for locale handling in different modes, fallback/getStaticProps/getServerSideProps

To be continued in fall-up PRs

- [ ] add tests for revalidate, auto-export, basePath + i18n
- [ ] add mapping of domains with locales
- [ ] investigate detecting locale against non-index routes and populating the locale in a cookie

x-ref: https://github.com/vercel/next.js/issues/17110
2020-10-07 21:11:01 +00:00
JJ Kasper
6588108150
v9.5.4 2020-10-07 13:56:56 -05:00
JJ Kasper
7108567b06
v9.5.4-canary.25 2020-10-07 12:29:46 -05:00
JJ Kasper
5d79a8c0c4
Update workflow step to restore cache (#17656) 2020-10-07 09:55:09 -05:00
Tantan Fu
4c38e3ed8e
fix typo (#17653) 2020-10-06 15:31:40 +00:00
Joe Haddad
241f38eaa8
v9.5.4-canary.24 2020-10-06 09:48:39 -04:00
Jashn Maloo
7dec91175c
change anonymous functions to named in docs examples (#17510)
Fixes #17200
2020-10-05 21:16:47 +00:00
Lee Robinson
1659e4da61
Update migrating from Gatsby docs. (#17636)
Addresses remaining comments from https://github.com/vercel/next.js/pull/17491.
2020-10-05 20:20:26 +00:00
Lee Robinson
06a8b1ad67
Add docs on how to migrate from Gatsby. (#17491)
Addresses https://github.com/vercel/next.js/issues/17453.
2020-10-05 17:39:00 +00:00
JJ Kasper
04234cc312
Update to use hasNextSupport for custom-routes in next export check (#17630)
Follow-up to https://github.com/vercel/next.js/pull/17538 per https://github.com/vercel/next.js/pull/17538#discussion_r499647323 this updates the check to use the existing `hasNextSupport` export instead of checking the environment variable directly
2020-10-05 15:26:11 +00:00
James George
742f5d9a46
test(create-next-app): increase coverage (#17507)
Added a test case to make sure that creating a new project within the current directory works as expected.
2020-10-05 13:04:25 +00:00
JJ Kasper
100a1d3acc
Update release stats workflow (#17580)
Follow-up to https://github.com/vercel/next.js/pull/17533 this makes sure the file used to signal release stats should be skipped for a non-release merge is created in a location that is accessible by the stats action and also updates the release action info detection for the new workflow
2020-10-05 09:32:12 +00:00
JJ Kasper
b42be17593
Normalize optional catch-all fallback: true page params (#17551)
This makes sure to normalize the params for optional catch-all routes on Vercel since for `fallback: true` pages the `[[...paramName]]` value will be provided for the undefined/root param which needs to be normalized. 

Tests have been added in https://github.com/vercel/vercel/pull/5247 and were manually tested with the changes in this PR with https://github.com/ijjk/next-update-loader

Fixes: https://github.com/vercel/next.js/issues/17220
x-ref: https://github.com/vercel/vercel/pull/5247
2020-10-05 07:34:50 +00:00
JJ Kasper
782b7e48ec
Add warning when exporting with custom routes (#17538)
This adds a warning when `next export` and custom routes are defined  outside of a platform that supports them since they won't be applied anymore.
2020-10-05 07:11:06 +00:00
Rafael Zerbini
d32b195539
Fixes #16431 (#17610)
Fixes #16431
* Added `.babelrc` with `next/babel` to remove the need of the React import on the `with-storybook` example.
2020-10-05 06:27:43 +00:00
JJ Kasper
91b5390617
Remove left-over api-utils method (#17595)
Noticed this method was left-over from previous query handling logic in `api-utils` while working on https://github.com/vercel/next.js/pull/17370 so this removes the extra code which should be safe since `api-utils` is an internal file that shouldn't be relied on externally.
2020-10-04 19:16:30 +00:00
Joris W
f8aeaa479e
Add missing introductory exportPathMap purpose description (#17444)
The page describing exportPathMap goes straight into an example without explaining what the config is for.
2020-10-03 14:50:37 +00:00
JJ Kasper
f27e1f85ac
Update release stats workflow (#17533)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-10-02 21:12:12 -05:00
Riccardo Di Maio
10f7b8f941
Improve formatting in examples (#17571) 2020-10-02 21:25:29 +00:00
Yann Pringault
75a0ef9cc2
[docs] Fix typo Next.js -> TypeScript (#17561) 2020-10-02 10:27:38 -05:00
JJ Kasper
05fb9df06d
Add note about priority to rewrites docs (#17535)
This adds a note about public files and pages taking higher priority over rewrites causing them to not be able to be rewritten unless the files are renamed first since this has been asked a few times. 

x-ref: https://github.com/vercel/next.js/discussions/17513
x-ref: https://github.com/vercel/next.js/discussions/9081#discussioncomment-22077
x-ref: https://github.com/vercel/next.js/discussions/9081#discussioncomment-21995
2020-10-02 07:37:46 +00:00
Dylan Jhaveri
2a047a8f17
update README for vercel.app, stream.new (#17539) 2020-10-01 22:46:17 -04:00
Lee Robinson
fa244ef833
Mention favicon.ico in static file serving docs. (#17540) 2020-10-01 21:14:14 +00:00
Luis Alvarez D
816798569a
Mention required version for global CSS imports in node_modules (#17506)
Fixes https://github.com/vercel/next.js/issues/17505
2020-10-01 08:58:22 +00:00
Philihp Busby
f06c589115
with-google-analytics-amp needs <Head /> in Document component (#17462)
If this component is missing, an error will be printed to the console

```
Expected Document Component Head was not rendered. Make sure you render them in your custom `_document`
See more info here https://err.sh/next.js/missing-document-component
```

Additionally, any components which use CSS modules will fail with an error.

This is documented in https://nextjs.org/docs/advanced-features/custom-document
2020-09-30 08:41:05 +00:00
Amandeep Singh
02d7504670
Fixed minor typo (#17456) 2020-09-29 19:31:43 +00:00
Joe Haddad
c731c63631
v9.5.4-canary.23 2020-09-28 17:41:15 -07:00
JJ Kasper
f7f376f91e
Ensure optional-chaining/nullish coalescing is included (#17429) 2020-09-28 16:47:05 -07:00
JJ Kasper
489b13d00e
Fix empty title in head (#17430)
This handles the case where the children on a head element are undefined and not a string or an array of strings. This doesn't currently handle sub-children on head elements so additional handling will be needed if this is a feature we would like to support although can be discussed/investigated separately from this fix. 

Fixes: https://github.com/vercel/next.js/issues/17364  
Fixes: https://github.com/vercel/next.js/issues/6388
Closes: https://github.com/vercel/next.js/pull/16751
2020-09-28 23:12:07 +00:00
Tim Feeley
b009ebbec6
Fix a small typo in index.css (#17399) 2020-09-27 22:17:03 +00:00
JJ Kasper
8eccecb35e
v9.5.4-canary.22 2020-09-25 13:16:35 -05:00
JJ Kasper
ad22e77309
Expose dotenv loading under separate package (#17152)
* Expose dotenv loading under separate package

* Update pre-compiled

* Rename package to @next/env

* Update lint ignores

* Update package.json

Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-09-25 13:14:28 -05:00
JJ Kasper
a3b9d8670a
Remove extra check in config loading (#17336)
Noticed while adding config checks for a new config that the `basePath` checks were wrapped in a `result.experimental` check and even though this should always be true from the default experimental value being an object the `basePath` checks shouldn't be wrapped in this check since it isn't experimental anymore.
2020-09-25 02:29:13 +00:00
Rishi Raj Jain
92fc260e4c
Update README.md (#17347)
As clear from [#14233](https://github.com/vercel/next.js/pull/14233#issuecomment-645997757) that the 'with-algolia example is not SSR', I've updated the documentation to clear the confusion caused, as visible in #17229 

Fixes #17229
2020-09-25 01:55:11 +00:00
Antonio Pitasi
c388048f3e
fix(examples/with-redux-wrapper): wrong initial state (close #17299) (#17335)
Wrong variable was being checked for the hydrate action on redux. This was causing the count to be reset to 0 instead of being 1 when initially loading index.js page.

Fixes #17299
2020-09-24 19:35:46 +00:00
Sam Robbins
c45497e1c3
Remove reference to now env example (#17341)
The example has been emptied as it is no longer the recommended way to do it so it shouldn't be linked to
2020-09-24 18:30:39 +00:00
Sam Poder
c5b20d06fa
Remove Random Blank Line in create-next-app (#17328)
There was a blank line, this PR removes it :D
2020-09-24 08:57:48 +00:00
Joe Haddad
47b7e0b318
v9.5.4-canary.21 2020-09-24 02:17:53 -04:00
Joe Haddad
c351f6154b
Improve server performance by skipping decode/re-encode (#17323)
Prior to this pull request, Next.js would immediately decode all URLs sent to its server (via `path-match`).

This was rarely needed, and Next.js would typically re-encode the incoming request right away (see all the `encodeURIComponent`s removed in PR diff). This adds unnecessary performance overhead.

Long term, this will also help prevent weird encoding edge-cases like #10004, #10022, #11371, et al.

---

No new tests are necessary for this change because we've extensively tested these edge cases with existing tests.
One test was updated to reflect that we skip decoding in a 404 scenario.

Let's see if all the existing tests pass!
2020-09-24 06:05:40 +00:00
Stig Kleppe-Jørgensen
a4be780781
Remove duplicate should in test name (#17303) 2020-09-23 17:36:46 +00:00
Gergo Tolnai
8fdb93d76f
Docs(api-middlewares): use typings for serialize options from @types/cookie (#17285) 2020-09-22 18:52:29 +00:00
Luis Alvarez D
beeeba099b
Rename exportTrailingSlash to trailingSlash in docs (#17268) 2020-09-22 12:10:10 +02:00
Joe Haddad
c6ff918777
Update no-document-viewport-meta.md 2020-09-21 21:31:51 -04:00
Sébastien Vanvelthem
f3eadac467
Example: with-next-auth updated to v3 (#17266)
Update [`next-auth`](https://github.com/iaincollins/next-auth) from `^2.1.0` to `^3.1.0` and minor sqlite bump to `^5.0.0`.
2020-09-21 19:51:52 +00:00
Kazuma Furuhashi
31ab12aaf7
Add project name to examples/with-three-js create command (#17256)
This is a change to add the project name as in the other examples.
When we run with the current create command, we are asked for the project name.
As follows:

```
$ npx create-next-app --example with-three-js
? What is your project named? › my-app
```
2020-09-21 17:02:25 +00:00
paulogdm
3400052cbb
Delete vercel.json from "yarn workspaces" example (#17263)
This PR removes "vercel.json" from the Yarn workspaces example. Since the release of [monorepos](https://vercel.com/blog/monorepos) support, there is no need to use the "builds" property or "vercel.json".
2020-09-21 16:39:51 +00:00
Yuji Sugiura
4adf48b6cc
Fix export-cli progress label default value (#17106)
This PR fixes `info  - undefined (N/N)` log for `export` cli.

![image](https://user-images.githubusercontent.com/6259812/93186247-5d801500-f779-11ea-89ec-e20939d7b7c1.png)

Default parameter `label` for `createProgress()` was always ignored by `${Log.prefixes.info} undefined` 😅 .
2020-09-21 16:09:14 +00:00