Commit graph

1148 commits

Author SHA1 Message Date
Joe Haddad
a92e976231
Remove remaining granular chunks references (#13672)
This removes remaining references to `granularChunks` in configs, error messages, and comments.

Also removed the `process.env.__NEXT_GRANULAR_CHUNKS` value.

---

Follow up to: https://github.com/vercel/next.js/pull/13663
2020-06-02 14:45:07 +00:00
Joe Haddad
15cdb4f408
Propagate Serverless Errors to Platform (#12841)
In serverless mode, it's best practice to propagate an unhandled error so that the function is disposed instead of recycled. This helps fix the "bad state" problem.
2020-06-01 23:12:45 +00:00
Jan Potoms
8bac412845
make getStaticPaths work with optional catch-all routes (#13559)
Fixes https://github.com/vercel/next.js/issues/13524

To do:
- [x] fix dev mode
- [x] there's a ~route ordering or~ trailing slash issue with top level catch-all (current tests reflect that)
- [x] in this test `/get-static-paths/whatever` should fall back to `/[[...optionalName]].js` since `fallback` is `false` in its `getStaticPaths` method. ~Currently seems to 500~ must have been a glitch
- [x] add tests for `null`, `undefined` ~and `false`~ behavior as well (if decided these are valid)
- [x] ~add tests for string params as well~ this is not allowed for catch-all routes
- [x] test behavior when fallback is enabled and a top level catch-all exists
2020-06-01 17:08:34 +00:00
JJ Kasper
c0368e1b09
Handle encoding for data requests and fix fallback response (#13622)
This addresses some errors for `/_next/data` requests where encoded `/` values in dynamic route param would cause invalid behavior, a headers already sent error would be shown when sending the fallback page in development, and when rendering the `_error` page for a data request the error response would still be treated as a data request. 

This also adds test cases for these errors to prevent regression
2020-06-01 13:25:00 +00:00
Jan Potoms
f69757408e
Update browserslist/caniuse-lite (#13605)
Looks like `caniuse-lite` is out of date and causing test failures. 
- I upgraded both `browserslist` and `caniuse-lite` to latest semver compatible version.
- This seemed to cause changes in ncc compiled files, so recompiled.
- `lint-staged` failed on these files even though they should be ignored. As a fix, I applied the advice from https://github.com/okonet/lint-staged#how-can-i-ignore-files-from-eslintignore-
- Updated some test snapshots. 🤔 not sure this is the way to go
2020-05-31 19:37:01 +00:00
Simon Knott
a32fa4243a
Add ETag Support (#12802)
Closes #12045 

This PR adds support for [etags](https://tools.ietf.org/html/rfc7232#section-3.2) to Next.js' API routes, which will improve user experience and decrease network traffic by enabling usage of etag-based caching.
2020-05-30 19:23:24 +00:00
JJ Kasper
ae3c388039
Add support for rewriting non-fallback SSG pages (#11010)
Since non-fallback pages don't rely on the URL for hydration we can allow them to be rewritten to but pages with fallback still can't be rewritten to because we won't be able to parse the correct `/_next/data` path to request the page's data from. I added a test for this behavior and ensured it works correctly on Now.

Example on with fallback false rewrite on Now:
https://tst-rewrite-cp9vge4bg.now.sh/about
2020-05-29 16:33:09 +00:00
Joe Haddad
92a12a2e20
Replace fork-ts-checker-webpack-plugin with faster alternative (#13529)
This removes `fork-ts-checker-webpack-plugin` and instead directly calls the TypeScript API.

This is approximately 10x faster.

Base build: 7s (no TypeScript features enabled)

- `fork-ts-checker-webpack-plugin@3.1.1`: 90s, computer sounds like an airplane
- `fork-ts-checker-webpack-plugin@4.1.6`: 84s, computer did **not** sound like an airplane
- `fork-ts-checker-webpack-plugin@5.0.0-alpha.14`: 90s, regressed
- `npx tsc -p tsconfig.json --noEmit`: 12s (time: `18.57s user 0.97s system 169% cpu 11.525 total`)
- **This PR**: 22s, expected to get better when we run this as a side-car

All of these tests were run 3 times and repeat-accurate within +/- 0.5s.
2020-05-29 08:16:22 +00:00
Joe Haddad
30fbd9adc9
Speedup tests (#13461)
This PR checks if our tests can be ran faster by disabling source maps unless they're used for the purpose of testing.
2020-05-29 07:57:51 +00:00
Joe Haddad
a7ae54d7cc
refactor(typescript): extract preflight functions (#13510)
This pull request refactors our TypeScript preflight check in preparation for dropping the `fork-ts-checker-webpack-plugin` plugin.

This will make reviewing the subsequent PR much easier.

---

There is no behavior change, so the existing test should cover this adequately.
2020-05-28 23:39:46 +00:00
Joe Haddad
c64cb60a8e
Fail production build quickly (#13496)
By default, webpack will proceed to run loaders and plugins on all files, even after an error has been encountered during the build process.

This means you might need to wait minutes to see a syntax error encountered in one of your source files. This PR fixes that.
2020-05-28 22:51:30 +00:00
Prateek Bhatnagar
ac9194ad2c
[experimental] filtering unwanted jsx type in eslint plugin (#13520) 2020-05-28 18:11:29 -04:00
Joe Haddad
b7e17e09e5
Update references to zeit/next.js (#13463) 2020-05-27 17:51:11 -04:00
Manu Schiller
9f1b4f5694
Add type inference for getStaticProps and getServerSideProps (#11842)
This adds `InferredStaticProps` and `InferredServerSideProps` to the typings.

- [x] add types for type inference 
- [x] add explanation to docs
- [ ] tests - are there any?

![inferred-props](https://user-images.githubusercontent.com/56154253/79068041-24bcab00-7cc4-11ea-8397-ed1b95fbeca7.gif)

### What does it do:

As an alternative to declaring your Types manually with:
```typescript
type Props = {
  posts: Post[]
}

export const getStaticProps: GetStaticProps<Props> = () => ({
  posts: await fetchMyPosts(),
})

export const MyComponent(props: Props) =>(
 // ...
);
```

we can now also infer the prop types with
```typescript
export const getStaticProps = () => ({
  // given fetchMyPosts() returns type Post[]
  posts: await fetchMyPosts(),
})

export const MyComponent(props: InferredStaticProps<typeof getStaticProps>) =>(
 // props.posts will be of type Post[]
);

```

### help / review wanted
- [ ] I am no typescript expert. Although the solution works as intended for me, someone with more knowledge could probably improve the types. Any edge cases I missed?
- [ ] are there any tests I should modify/ add?
2020-05-27 19:02:22 +00:00
Joe Haddad
37f4353f24
Do not throw away tsconfig.json comments (#13458)
This pull request updates our TypeScript verification process to not wipe out potentially vital user comments.

Introducing a prompt process was mostly a side effect of users wanting to keep comments.
There's no reason we really need this prompt, as answering no would refuse to boot the Next.js server anyway.

---

Fixes #8128
Closes #11440
2020-05-27 18:46:18 +00:00
JJ Kasper
e2619359ec
Add warning when reserved pages are nested (#13449)
This adds a warning when a user has nested a reserved page `_error`, `_app`, or `_document` in their pages directory since it causes it to not be picked up and used by Next.js in the expected way

x-ref: https://github.com/zeit/next.js/pull/13425

<details>
<summary>Example of warning</summary>

<img width="927" alt="Screen Shot 2020-05-27 at 10 39 09" src="https://user-images.githubusercontent.com/22380829/83042315-24276c00-a007-11ea-9dc4-cabcc93571d2.png">
</details>
2020-05-27 16:45:53 +00:00
Joe Haddad
c731d59149
Fix AMP Test Flake (#13450)
Observed here: https://github.com/zeit/next.js/pull/13434#issuecomment-634566450
2020-05-27 16:28:43 +00:00
JJ Kasper
ce0a32c39e
Make sure to not duplicate exports with exportTrailingSlash (#11011)
This makes sure we don't duplicate the `/` route or any others while exporting with `exportTrailingSlash` enabled. We do still output `404.html` with `exportTrailingSlash` enabled in case anyone was relying on this file being present.

Fixes: https://github.com/zeit/next.js/issues/11008
2020-05-27 05:48:50 +00:00
JJ Kasper
83bc82e40a
Fix auto export opting out from _error edge case (#13425)
This fixes an edge case where an application can seemingly randomly be opted out of the automatic static optimization from having an `_error` file that isn't directly nested under the `pages` folder e.g. `pages/hello/_error.js`. 

Since in serverless mode we use the `_app` export from the first serverless page, if this `_error.js` file is used to check for custom `getIniitalProps` in `_app` and the `_error.js` page had a custom `getInitialProps` itself it would cause the check to fail opting the application out of the static optimization. 

This fixes it by having the check be explicit instead of relying on the bundle name and it also adds regression tests for this. It might be good to also add a warning when `_error` or `_app` are not directly nested under the pages folder in a follow up PR
2020-05-27 05:31:57 +00:00
Joe Haddad
8b72b9e2de
[Experimental] Do not type check twice (#13419)
The experimental modern mode runs the type checking plugin twice, which **occasionally** suffers from a race condition that hangs the build.

This PR fixes type checking to only be run once.

While this test cannot 100% reproduce/capture the race condition, I don't feel strongly about the test case:

- We're planning on eliminating this type checking plugin ASAP (for a faster alternative)
- Modern mode implementation as-is will probably go away with webpack 5
2020-05-27 02:58:16 +00:00
Christian Stuff
d94e8db531
Add failing paths to export error summary (#10026)
Closes #9990 by collecting all paths with errors during `next export` and reporting them sorted in the error summary at the end.

It will produce an output similar to:

```
    Error: Export encountered errors on following paths:
        /nested/page
        /page
        /page-1
        /page-10
        /page-11
        /page-12
        /page-13
        /page-2
        /page-3
        /page-4
        /page-5
        /page-6
        /page-7
        /page-8
        /page-9
        at _default (/app/next.js/packages/next/dist/export/index.js:19:788)
        at process._tickCallback (internal/process/next_tick.js:68:7)
```

I tested the output with the `handle-export-errors` integration test suite, but I'm not sure how to gracefully test this added output.
I thought of collecting all page source files with [recursiveReaddirSync](2ba352da39/packages/next/next-server/server/lib/recursive-readdir-sync.ts) but it seems I can't import it in js test files:

```
SyntaxError: /app/next.js/packages/next/next-server/server/lib/recursive-readdir-sync.ts: Unexpected token, expected "," (11:5)

       9 |  */
      10 | export function recursiveReadDirSync(
    > 11 |   dir: string,
         |      ^
      12 |   arr: string[] = [],
      13 |   rootDir = dir
      14 | ): string[] {
```

The test itself could look like:
```js
  it('Reports failing paths', async () => {
    const { stderr } = await nextBuild(appDir, [], {
      stdout: true,
      stderr: true,
    })
    const pages = []
    // collect pages to be ['/page', '/page-1', ... etc.]
    pages.forEach(page => {
      expect(stderr).toContain(page)
    })
  })
```
2020-05-26 19:50:25 +00:00
JJ Kasper
fafa16f350
Bundle env configs in serverless mode (#13406)
As discussed this adds bundling of `.env` files in `serverless` mode so that the environment values are also available when deploying with this target

closes: https://github.com/zeit/next.js/issues/13332
2020-05-26 19:01:57 +00:00
Fabio Benedetti
235b3befcc
fix(client-routing): page render (#13305)
Fixes https://github.com/zeit/next.js/issues/12935
2020-05-26 17:50:06 +00:00
Marco Moretti
b3e45fab5e
feat(cli): use default template when GH is offline (#12194)
fix #12136 

I add a prompt if there is an error when trying to download example files.
Maybe could be better to add an error class and in create-app.ts on every "console.error" trow a new Exception and manage it in catch. What you think ? 👯
2020-05-26 16:39:18 +00:00
Jan Potoms
cefbcadf45
Make page path case sensitive in dev (#8848)
URL paths are case sensitive, MacOS file system is case insensitive. This PR makes sure development mode doesn't find pages that don't have the casing as specified in the URL.

Will clean up and write a test when agreed on this approach.

Fixes https://github.com/zeit/next.js/issues/8825
Fixes https://github.com/zeit/next.js/issues/8847
Fixes https://github.com/zeit/next.js/issues/9080
2020-05-26 12:50:28 +00:00
Joe Haddad
2ecb7c6e37
Fix retry for Windows tests (#13296)
Noticed these tests failed for Windows on `canary`, then traced down the cause.
2020-05-24 01:34:06 +00:00
James Mosier
846ec74013
Special case default template in CNA (#12109)
This addresses #11910 in which `-e default` was not working because there was no example with the name `default`. This PR checks if a user inputted `default` as the example argument for `create-next-app` and if so it will use the local `default` template in the create-next-app directory.

Closes #11910
2020-05-23 22:50:31 +00:00
Joe Haddad
3ee0a1f41a
Wait for flush before firing routing event (#13287)
This waits for the render to be committed to DOM before we render the route change complete event (no longer sync in new React).

We have tests that ensure this resolves.

---

Closes #12938
2020-05-23 21:54:11 +00:00
Joe Haddad
d6ad201f80
[Fast Refresh] Upgrade react-refresh (#13285)
Closes #13254
2020-05-23 21:37:56 +00:00
Jairo Tylera
e66bcfa838
Add support for sass-loader prependData option (#12277)
This PR adds support for prepending sass code before the actual entry file.

It's common for developers to import their sass mixins and variables once on their project config so they don't need to import them on every file that requires it. Frameworks like gatsby and nuxt.js already support that handy feature.

The way it works is:

```
/// next.config.js
module.exports = {
  experimental: {
    sassOptions: {
      prependData: `
        /// Scss code that you want to be
        /// prepended to every single scss file.
      `,
    },
  },
}
```

Fixes #11617 and duplicates
2020-05-23 13:37:48 +00:00
Luis Alvarez D
589f44ef94
Ignore nullish user configs (#10250) 2020-05-22 16:46:36 +00:00
Joe Haddad
3d852d895f
Better formatted Sass errors (#13211)
https://twitter.com/timer150/status/1263689549898829829
2020-05-22 05:25:02 +00:00
Prateek Bhatnagar
75b0bfff9c
bug fixes for Lint routing (#13111)
- bug fixes in `@next/eslint-plugin-next`.
- adds rules to `recommended` config.
2020-05-21 23:42:20 +00:00
Joe Haddad
7c7fd3e863
Record presence of reportWebVitals (#13155)
Closes #12897
2020-05-20 18:44:39 +00:00
Joe Haddad
57815c5fe5
Fix Windows LogBox Test (#13147) 2020-05-20 13:33:26 -04:00
Joe Haddad
74d7e3585c
Eliminate array destructuring assignment (#13151)
While we're at it, we should fix this too.

x-ref: #13144
2020-05-20 17:13:31 +00:00
Joe Haddad
92a159d939
Correctly eliminate destructuring assignment (#13144)
This eliminates code referenced via destructuring assignment, as reported by @styfle.
2020-05-20 15:57:18 +00:00
Joe Haddad
ccea1c018b
Enable jest/no-try-expect (#13124) 2020-05-20 13:37:35 +02:00
Janicklas Ralph
a17ace8eba
GranularChunks conformance check (#11710)
Adding a conformance plugin the make sure users don't undo the benefits of the granularChunks config.

The plugin makes sure that minSize, maxInitialRequests values aren't overridden. Also ensures the cacheGroups - vendors, framework, libs, common, shared are maintained.

The warning and error messages do not break the build with this change. They only display a message.

cc - @prateekbh, @atcastle
2020-05-20 06:40:23 +00:00
Joe Haddad
d64e2e1cbe
Use eval-source-map for Server Side Errors (#13123)
This switches to faster source maps in development for the server-side compilation on macOS.

We still need to figure out a story for Windows.
2020-05-20 05:00:50 +00:00
Dave Cardwell
07084d4819
[Experimental] Only consider files within plugins (#12943)
I have a plugin with a src folder structure following jest’s recommended practice of including a `__tests__` folder:

```
$ find src/
src/
src/document-html-props-server.ts
src/__tests__
src/__tests__/document-html-props-server.unit.ts
```

collect-plugins.ts [reads the src directory](960c18da53/packages/next/build/plugins/collect-plugins.ts (L65)) and finds:
```js
[ '__tests__', 'document-html-props-server.ts' ]
```

…which it then [converts to](960c18da53/packages/next/build/plugins/collect-plugins.ts (L76-L80)):
```js
[ '', 'document-html-props-server' ]
```

…and finally [outputs](960c18da53/packages/next/build/plugins/collect-plugins.ts (L90-L96)):
```
Next.js Plugin: {my plugin} listed invalid middleware
```

This pull request makes collect-plugins.ts only consider files, so my __tests__ directory and its contents are ignored.
2020-05-20 04:05:29 +00:00
Joe Haddad
9386ba29f8
Stabilize config tests (#13116) 2020-05-19 18:42:41 -04:00
Joe Haddad
f7bdf29ecb
Fix Lint 2020-05-19 18:00:04 -04:00
Jan Potoms
0d05904552
Fix catch-all route + index.js in dev when accessed with trailing slash (#10502)
Failing test case for https://github.com/zeit/next.js/issues/10488#issuecomment-584500081

This used to give a 500 in dev environment
2020-05-19 18:03:14 +00:00
JJ Kasper
ef422467dc
Add error when exporting pages with fallback: true (#13063) 2020-05-19 09:29:34 -04:00
Slawek Kolodziej
7f604a504b
Fix building server-side generated AMP pages (#13046) 2020-05-19 07:58:50 -04:00
Prateek Bhatnagar
dc826e3d37
adding no html-link lint rule to eslint-plugin (#12969)
* addinng no html-link lint rule

* fixing lint tests

* adding the utils file

* fixing lock file

* prettier fix
2020-05-19 10:54:32 +02:00
Joe Haddad
86160a5190
Upgrade to Prettier 2 (#13061) 2020-05-18 15:24:37 -04:00
Joe Haddad
f9b7247360
Fix lint 2020-05-18 14:01:45 -04:00
Jan Potoms
714747957a
Add eslint-plugin-jest (#13003) 2020-05-18 13:16:07 -04:00