Commit graph

2711 commits

Author SHA1 Message Date
Joe Haddad
4e813ae0c6
v9.5.3-canary.1 2020-08-13 18:49:35 -04:00
Joe Haddad
cb786ebd81
Share NEXT_DATA type instead of recreating it (#16174) 2020-08-13 22:19:06 +00:00
Joe Haddad
33176806f3
Remove unused dependency (#16168) 2020-08-13 13:40:08 -04:00
Joe Haddad
0e48ea3938
Convert next/client to TypeScript (#16167)
Fixes #16166
2020-08-13 13:39:33 -04:00
Joe Haddad
09afc376cd
Convert performance relayer to TypeScript (#16161)
Really basic one! Needed for `next/client`.
2020-08-13 15:20:29 +00:00
Joe Haddad
5b81531676
Reduce router code (#16159)
This reduces the code as suggested: https://github.com/vercel/next.js/pull/15231#discussion_r469691649.

Removes these bloated Babel helpers:

```diff
@@ -678,80 +678,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
 
       var _createClass = __webpack_require__("W8MJ");
 
-      function _createForOfIteratorHelper(o, allowArrayLike) {
-        var it;
-        if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
-          if (
-            Array.isArray(o) ||
-            (it = _unsupportedIterableToArray(o)) ||
-            (allowArrayLike && o && typeof o.length === "number")
-          ) {
-            if (it) o = it;
-            var i = 0;
-            var F = function F() {};
-            return {
-              s: F,
-              n: function n() {
-                if (i >= o.length) return { done: true };
-                return { done: false, value: o[i++] };
-              },
-              e: function e(_e) {
-                throw _e;
-              },
-              f: F
-            };
-          }
-          throw new TypeError(
-            "Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."
-          );
-        }
-        var normalCompletion = true,
-          didErr = false,
-          err;
-        return {
-          s: function s() {
-            it = o[Symbol.iterator]();
-          },
-          n: function n() {
-            var step = it.next();
-            normalCompletion = step.done;
-            return step;
-          },
-          e: function e(_e2) {
-            didErr = true;
-            err = _e2;
-          },
-          f: function f() {
-            try {
-              if (!normalCompletion && it["return"] != null) it["return"]();
-            } finally {
-              if (didErr) throw err;
-            }
-          }
-        };
-      }
-
-      function _unsupportedIterableToArray(o, minLen) {
-        if (!o) return;
-        if (typeof o === "string") return _arrayLikeToArray(o, minLen);
-        var n = Object.prototype.toString.call(o).slice(8, -1);
-        if (n === "Object" && o.constructor) n = o.constructor.name;
-        if (n === "Map" || n === "Set") return Array.from(o);
-        if (
-          n === "Arguments" ||
-          /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)
-        )
-          return _arrayLikeToArray(o, minLen);
-      }
-
-      function _arrayLikeToArray(arr, len) {
-        if (len == null || len > arr.length) len = arr.length;
-        for (var i = 0, arr2 = new Array(len); i < len; i++) {
-          arr2[i] = arr[i];
-        }
-        return arr2;
-      }
-
       exports.__esModule = true;
       exports.hasBasePath = hasBasePath;
       exports.addBasePath = addBasePath;
@@ -1864,28 +1790,16 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
               } // handle resolving href for dynamic routes
 
               if (!pages.includes(cleanPathname)) {
-                var _iterator = _createForOfIteratorHelper(pages),
-                  _step;
-
-                try {
-                  for (_iterator.s(); !(_step = _iterator.n()).done; ) {
-                    var page = _step.value;
-
-                    if (
-                      (0, _isDynamic.isDynamicRoute)(page) &&
-                      (0, _routeRegex.getRouteRegex)(page).re.test(
-                        cleanPathname
-                      )
-                    ) {
-                      parsedHref.pathname = addBasePath(page);
-                      break;
-                    }
+                // eslint-disable-next-line array-callback-return
+                pages.some(function(page) {
+                  if (
+                    (0, _isDynamic.isDynamicRoute)(page) &&
+                    (0, _routeRegex.getRouteRegex)(page).re.test(cleanPathname)
+                  ) {
+                    parsedHref.pathname = addBasePath(page);
+                    return true;
                   }
-                } catch (err) {
-                  _iterator.e(err);
-                } finally {
-                  _iterator.f();
-                }
+                });
               }
 
               return parsedHref;
@@ -2069,10 +1983,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
                 }
 
                 if (cancelled) {
-                  var _err = new Error("Loading initial props cancelled");
-
-                  _err.cancelled = true;
-                  throw _err;
+                  var err = new Error("Loading initial props cancelled");
+                  err.cancelled = true;
+                  throw err;
                 }
 
                 return data;
```
2020-08-13 14:50:01 +00:00
Tim Neutkens
7b13205e7e v9.5.3-canary.0 2020-08-13 14:41:25 +02:00
JJ Kasper
8a489e24bc
Add initial handling for dynamic route href resolving and rewrites on the client (#15231)
Co-authored-by: Tim Neutkens <timneutkens@me.com>
2020-08-13 14:39:36 +02:00
Joe Haddad
ff0571ae14
Remove unused router method (#16149)
This PR removes a legacy router method that was used for old-style HMR, now replaced by Fast Refresh.

This method was not public:
```tsx
export type NextRouter = BaseRouter &
  Pick<
    Router,
    | 'push'
    | 'replace'
    | 'reload'
    | 'back'
    | 'prefetch'
    | 'beforePopState'
    | 'events'
    | 'isFallback'
  >
```

Even if someone found this method, it's highly unlikely they could use it successfully—it required the full module object.
2020-08-13 05:43:13 +00:00
Joe Haddad
c7acd1187b
Dedupe ComponentRes type (#16148)
This PR dedupes the `ComponentRes` type to now align with the `loadPage` return type.
2020-08-13 05:24:57 +00:00
Joe Haddad
94a85cff12
Improve page loader types (#16145) 2020-08-13 00:01:15 -04:00
Joe Haddad
16e4f9e79e
Strongly type Head Manager (#16144) 2020-08-12 23:54:48 -04:00
Joe Haddad
9e65c6a958
Strongly type PageLoader (#16132)
Fixes #16131
2020-08-12 20:42:05 +00:00
Tim Neutkens
e72ac76422
Remove tslint disables (#16116)
We no longer use tslint so these comments don't do anything.
2020-08-12 14:39:07 +00:00
Joe Haddad
07df897dad
v9.5.2 2020-08-10 19:17:42 -04:00
Joe Haddad
1bc63a379d
v9.5.2-canary.18 2020-08-10 18:45:23 -04:00
Joe Haddad
782d27e576
v9.5.2-canary.17 2020-08-10 16:49:03 -04:00
Yuhei Yasuda
052a9d2353
Don’t prevent the browser’s default behavior for Alt key (#16003)
In most browsers, clicking links with the Alt key has a special behavior, for example, Chrome downloads the target resource. As with other modifier keys, the router should stop the original navigation to avoid preventing the browser’s default behavior.

When users click a link while holding the Alt key together, the browsers behave as follows.

Windows 10:

| Browser    | Behavior                                    |
|:-----------|:--------------------------------------------|
| Chrome 84  | Download the target resource                |
| Firefox 79 | Prevent navigation and therefore do nothing |
| Edge 84    | Download the target resource                |
| IE 11      | No impact                                   |

macOS Catalina:

| Browser    | Behavior                                    |
|:-----------|:--------------------------------------------|
| Chrome 84  | Download the target resource                |
| Firefox 79 | Prevent navigation and therefore do nothing |
| Safari 13  | Download the target resource                |
2020-08-10 20:32:47 +00:00
Joe Haddad
378f092aaf
v9.5.2-canary.16 2020-08-10 15:46:43 -04:00
Prateek Bhatnagar
2ddfd84411
Improvements - Font optimizations (#16031)
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-08-10 14:06:38 -04:00
Joe Haddad
bd70354394
v9.5.2-canary.15 2020-08-10 13:55:06 -04:00
Joe Haddad
6d71eef518
Do not assign to readonly property in Safari (#16051) 2020-08-10 13:15:37 -04:00
Joe Haddad
4a04212d6b
v9.5.2-canary.14 2020-08-10 12:28:49 -04:00
Sebastian Benz
d6ad0d0843
upgrade @ampproject/toolbox-optimizer to 2.6.0 (#16043)
See [release notes](https://github.com/ampproject/amp-toolbox/releases/tag/v2.6.0).

**Highlight:** [hero images can now be server-side rendered](https://github.com/ampproject/amp-toolbox/tree/main/packages/optimizer#preloadheroimage) by annotating then with `data-hero`. This will greatly improves LCP when using large images in the first viewport.

```
<amp-img data-hero src="/hero.jpg" layout="responsive" width="640" height="480"></amp-img>
```

Also fixes #15979
2020-08-10 16:06:00 +00:00
Joe Haddad
e08b633c3a
Do not bundle caniuse-lite (#16048) 2020-08-10 11:27:21 -04:00
Tim Neutkens
1398aebf7b v9.5.2-canary.13 2020-08-10 16:29:13 +02:00
Tim Neutkens
e8e59a175e v9.5.2-canary.12 2020-08-10 14:35:25 +02:00
Tim Neutkens
281318d50e v9.5.2-canary.11 2020-08-10 11:49:45 +02:00
Tim Neutkens
37d2d15b6e
Resolve aliases modules (#16033)
Co-authored-by: Kristoffer K. <merceyz@users.noreply.github.com>
2020-08-10 11:45:10 +02:00
Tim Neutkens
62031ff24f
Move next-codemod to Next.js monorepo (#15536) 2020-08-10 11:14:53 +02:00
Tim Neutkens
f4433ceaa2 v9.5.2-canary.10 2020-08-10 09:50:15 +02:00
Tim Neutkens
843d58425b
Add browser polyfils for Node.js modules (webpack 5 backwards compat) (#16022)
This adds the following Node.js core polyfills only when the import is used:

- `path`
- `stream`
- `vm`
- `crypto`
- `buffer`

Fixes #15948

We'll have a separate issue about adding warnings for the usage of these modules in the browser, some polyfills like crypto are quite heavy and generally not needed for most applications (included accidentally through node_modules).
2020-08-10 01:26:21 +00:00
Amirali Esmaeili
4b6e9a45a3
Fix amphtml link rel not respecting basePath (#15949)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-08-08 15:15:00 +02:00
Prateek Bhatnagar
d8edb2eaa5
Bug fix: Font optimization (#15984)
Bug fix
- Do not remove spaces as it might mangle font names
2020-08-08 13:14:03 +00:00
Tim Neutkens
7fc92a6c78 v9.5.2-canary.9 2020-08-07 09:39:18 +02:00
JJ Kasper
b1ef76df31
Fix asPath normalizing for non-dynamic pages (#15960) 2020-08-07 09:01:34 +02:00
Markoz Peña
6375026a41
Added Friendly error for res.redirect 🐝 (#15844)
## Which solves this PR

 Displaying a friendly error, when the user is only passing `statusOrUrl`(type number) and the second argument `url` is ignored.

**Example**

`res.redirect(307);` // Show friendly error

Closes: https://github.com/vercel/next.js/issues/15594
x-ref: https://github.com/vercel/next.js/pull/15603
2020-08-06 22:53:09 +00:00
Tom Dohnal
eb4be226fd
notify component when route hash changes (#13894)
This resolves https://github.com/vercel/next.js/issues/13659
2020-08-06 22:04:47 +00:00
Evil Rabbit
8fed0c3ab5
Improve Vercel's badge (#15946) 2020-08-06 12:35:36 -04:00
Jan Potoms
cbfb8cbcc7
Remove querystring from the client (#15378) 2020-08-06 12:32:58 -04:00
Joe Haddad
882288b532
Warn when Fast Refresh is disabled (React <16.10) (#15931) 2020-08-06 10:41:11 -04:00
Joe Haddad
2d42b8e076
Delay server start message until it's listening (#15929)
Fixes #15928

---

This would cause us to print the message too early and open the browser to a server that wasn't started yet. This waits until we're listening, but before the app is ready fully.
2020-08-06 06:47:01 +00:00
Joe Haddad
0923ee6db4
v9.5.2-canary.8 2020-08-05 16:46:28 -04:00
Joris
0fd1958ae4
Disallow re-export all exports from Next.js pages (#14325)
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-08-05 16:21:40 -04:00
JJ Kasper
7d7a8fc300
Normalize serverless asPath value (#15914)
Since we now use query parameters to pass dynamic route params while routing on Vercel, this makes sure we normalize the request URL before populating the `asPath`

Fixes: https://github.com/vercel/next.js/issues/15879
2020-08-05 19:29:38 +00:00
Tim Neutkens
405e42e41e
Enhance module not found error (#15860)
Adds handling for module not found errors exposed by webpack. This ensures you see the actual stack line and code instead of a short message where you don't know where to go.

### Previous

<img width="794" alt="Screen Shot 2020-08-05 at 18 02 06" src="https://user-images.githubusercontent.com/6324199/89435935-d5542c00-d745-11ea-9ca7-c67f553364f9.png">


### New

<img width="769" alt="Screen Shot 2020-08-05 at 14 20 23" src="https://user-images.githubusercontent.com/6324199/89412212-f6595480-d726-11ea-81a3-398ab7036338.png">


Fixes #14711
2020-08-05 19:11:35 +00:00
Joe Haddad
46488fbcc6
v9.5.2-canary.7 2020-08-05 14:25:00 -04:00
Jan Potoms
5dbe0d0215
Allow absolute urls in router and Link (#15792)
Fixes https://github.com/vercel/next.js/issues/15639
Fixes https://github.com/vercel/next.js/issues/15820

To Do:
- [x] Doesn't work with `basePath` yet
2020-08-05 18:12:17 +00:00
Alex Castle
b6060fa4a5
Add experimental image post-processing (#15875)
This PR adds a second experimental post-processing step for the framework introduced by @prateekbh in #14746. The image post-processing step scans the rendered document for the first few images and uses a simple heuristic to determine if the images should be automatically preloaded.

Analysis of quite a few production Next apps has shown that a lot of sites are taking a substantial hit to their [LCP](https://web.dev/lcp/) score because an image that's part of the "hero" element on the page is not preloaded and is getting downloaded with lower priority than the JavaScript bundles. This post-processor should automatically fix that for a lot of sites, without causing any real performance effects in cases where it fails to identify the hero image.

This feature is behind an experimental flag, and will be subject to quite a bit of experimentation and tweaking before it's ready to be made a default setting.
2020-08-05 17:49:44 +00:00
Joe Haddad
fce1830d35
v9.5.2-canary.6 2020-08-04 22:28:36 -04:00
Joe Haddad
754ec6642a
Run Fast Refresh Loader in Babel Loader (#15851)
Next.js plugins like `@next/mdx` inject additional webpack loaders to compile files, but they omit the necessary loader for Fast Refresh to work.

Instead of making these files deopt out of Fast Refresh, we can automatically detect and inject the loader in these cases.

Fixes #13574
2020-08-04 21:24:56 +00:00
Joe Haddad
1968f7f552
v9.5.2-canary.5 2020-08-04 13:52:26 -04:00
Jan Potoms
92304404a4
Disallow basePath: false for internal routes (#15837) 2020-08-04 17:50:09 +00:00
jiangtao
35e4a370d9
fixed issue with runtime-config returning undefined when building or in a development environment (#15777)
fix https://github.com/vercel/next.js/issues/7713#issuecomment-643632270
2020-08-04 16:47:37 +00:00
Joe Haddad
e818389999
Add support for fallback: 'blocking' (#15672)
By popular request, this pull request adds support for returning `fallback: 'blocking'` from `getStaticPaths`.

This new mode will cause unknown paths to be rendered on-demand ("SSR") without the static (placeholder) fallback.

This feature is **currently experimental and should not be used in production yet**. It's currently flagged behind `unstable_`:

```
fallback: 'unstable_blocking'
```

TODO:

- [x] Next.js tests
- [ ] Add Vercel support
- [ ] Vercel tests

---

Fixes #15637
2020-08-04 15:10:31 +00:00
Tim Neutkens
668cc6a6f1 v9.5.2-canary.4 2020-08-04 12:35:24 +02:00
Darsh Patel
96a66c4bd3
incremental static generation and regeneration support in build manifest (#14365)
The icon is just something I thought might look good, can certainly be changed.
I've currently added incremental static generation support

Edit: Updated screenshot after 8037981
![Screenshot 2020-08-04 at 1 51 14 PM](https://user-images.githubusercontent.com/11258286/89270960-afe9f400-d659-11ea-8f18-197dc53b8beb.png)





Fixes: #14204
2020-08-04 08:42:18 +00:00
Jonathan G
6c59cbb46a
[Feature] Progress bar for static build (#15297)
Co-authored-by: Tim Neutkens <timneutkens@me.com>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2020-08-04 09:58:23 +02:00
Prateek Bhatnagar
1ea8bdcdc7
Bug fix: Font optimization (#15644)
- Fixes the serverless build for font optimizations
2020-08-04 07:54:08 +00:00
Kristóf Poduszló
aef6726eb8
Add missing nomodule polyfills and suggest using features only up to ES2019 for browser compatibility (#15772)
These changes aim to resolve most of the concerns raised in #15756. It adds missing polyfills for legacy browsers up until ES2019:

- Number.{parseFloat,parseInt}
- ~Math.{acosh,asinh,atanh,cbrt,clz32,cosh,expm1,fround,hypot,imul,log10p,log1p,log2,sign,sinh,tanh,trunc}~ _[Removed as these are [not widely used](https://github.com/vercel/next.js/pull/15772#discussion_r463957931)]_
  - While these may seem to weigh a lot, they barely add 1 kB to the resulting bundle:
    <img width="492" alt="gzip: 32 kB vs. 30.9 kB, Brotli: 28.8 kB vs. 27.8 kB" src="https://user-images.githubusercontent.com/14854048/89100961-1376e600-d3fc-11ea-90fd-3e6632b70220.png">
- ~Object.fromEntries~ _[Removed as [it's rarely used in user code](https://github.com/vercel/next.js/pull/15772#discussion_r463984612)]_

Also, the following features are now supported with build-time transforms:

- ~`globalThis` (gets transformed into `window` in browser environments)~ _[Removed as it [could break existing applications](https://github.com/vercel/next.js/pull/15772#discussion_r463956269)]_
- `export * as ns from 'module'`

The suggested TypeScript library version has been set to ES2018, so the features below become unavailable in type-checked files (they're not evenly supported by module-compatible browsers, either):

- Object.fromEntries
- String.prototype.matchAll
- String.prototype.replaceAll
- Promise.any + AggregateError
- WeakRef

As for the `import.meta` support, [webpack v5 seems to fix that](https://github.com/webpack/webpack/pull/11075), so it should eventually become an issue of the past.

---

Fixes #15756
2020-08-04 06:03:52 +00:00
Joe Haddad
8285df5ed2
v9.5.2-canary.3 2020-08-04 00:08:28 -04:00
Joe Haddad
48ca2f2cc5
Fix CSS grid-column shorthand syntax (#15848) 2020-08-04 00:08:09 -04:00
Tim Neutkens
e8c3190255
Support persisting the dev cache buster (#15827)
Same as #15483 but couldn't push to it

---

Closes #15483
Fixes #15828
2020-08-03 14:22:55 +00:00
Jan Potoms
b87e4989e2
Rename exportTrailingSlash to existing trailingSlash property (#15768)
In terms of url rewriting, `trailingSlash` supports everything `exportTrailingSlash` does. We can just share all other code paths and deprecate `exportTrailingSlash`.

This PR shows a deprecation warning when `exportTrailingSlash` is used.

Also fixes https://github.com/vercel/next.js/issues/15774

We can update the tests now or later. (I kept them the same to prove it's non-breaking)

To do:
- [x] Do we want to keep this? => nope 841d4efc51/packages/next/next-server/lib/router/router.ts (L329)
- [x] I kept `exportTrailingSlash` here. Do we want to rename that as well? => nope 2d9d649d49/packages/next/build/index.ts (L959)
2020-08-03 14:03:11 +00:00
Tim Neutkens
60f1d58c83
Fix some webpack 5 deprecation warnings (#15797)
- Use latest terser version (still 1 warning in the stable version which is an open PR)
- Add emitOnErrors instead of noEmitOnErrors
- Added trace-deprecations for Next.js core development
2020-08-03 12:57:17 +00:00
Tim Neutkens
210a6980d2
Solve large portion of webpack 5 deprecation warnings (#15806)
- Using `namedChunks` where possible, this will also allow for faster access to the chunks as we no longer have to look them up like we did before using `find`
- Using the new asset hooks introduced in the latest webpack beta
- Using the new externals function signature
2020-08-03 12:26:23 +00:00
Joe Haddad
ed0a47b110
v9.5.2-canary.2 2020-08-03 01:47:42 -04:00
JJ Kasper
9dd974dfca
Fix dotenv loading with cascading values (#15799)
Adds additional test cases for cascading env values and corrects behavior

Fixes: https://github.com/vercel/next.js/issues/15744
2020-08-02 20:15:11 +00:00
Jan Potoms
841d4efc51
Improve router types (#15775) 2020-08-01 18:13:03 +00:00
Jan Potoms
1b033423dc
Fix asPath of rewrite without basePath (#15760)
Fixes https://github.com/vercel/next.js/issues/15755
2020-08-01 11:51:47 +00:00
Joe Haddad
6366727550
v9.5.2-canary.1 2020-07-31 13:31:49 -04:00
Jan Potoms
ad5c736798
Remove unused error (#15748)
Irrelevant since https://github.com/vercel/next.js/pull/15379
2020-07-31 17:29:09 +00:00
Rafau
bcd1ba622e
[webpack5] Complile for ES5 (#15708)
I think this is necessary for IE11.

via [Webpack docs](https://webpack.js.org/migrate/5/#turn-off-es2015-syntax-in-runtime-code-if-necessary)


> By default, webpack's runtime code uses ES2015 syntax to build smaller bundles. If your build targets environments that don't support this syntax (like IE11), you'll need to set output.ecmaVersion: 5 to revert to ES5 syntax.


Thank you
2020-07-31 08:50:54 +00:00
Jan Potoms
c9e379c3bf
Fix wrong asPath on 404 (#15728)
Caught this while reviewing router code for https://github.com/vercel/next.js/pull/15710
2020-07-31 06:38:39 +00:00
JJ Kasper
ce56b60166
Add additional pageProps check (#15667)
`pageProps` should always be defined to ensure everything is working as expected although to prevent a breaking change this adds an additional check before attempting to access `pageProps` before hydration. It also adds tests to prevent regressing on this

Closes: https://github.com/vercel/next.js/issues/15647
2020-07-30 04:47:20 +00:00
Joe Haddad
6a48e3de60
v9.5.2-canary.0 2020-07-29 23:53:24 -04:00
Joe Haddad
cac35c389a
Fix hot reloader edge case with broken webpack plugins (#15659) 2020-07-29 23:44:25 -04:00
Joe Haddad
6b0c4948f0
v9.5.1 2020-07-29 23:11:48 -04:00
Joe Haddad
662d84b95b
v9.5.1-canary.3 2020-07-29 22:36:18 -04:00
Joe Haddad
3d98171dab
Test webpack 5 beta (#15645) 2020-07-29 19:19:32 -04:00
Joe Haddad
b748b5a443
v9.5.1-canary.2 2020-07-29 13:18:18 -04:00
Jan Potoms
80998a05f7
Don't use assetprefix on getServerSideProps and getStaticProps (#15634)
Strictly use `basePath` and not `assetPrefix` on `getStaticProps` and `getServerSideProps`

Fixes https://github.com/vercel/next.js/issues/15563
2020-07-29 16:51:51 +00:00
JJ Kasper
1a0cdbeacb
v9.5.1-canary.1 2020-07-29 09:58:32 -05:00
JJ Kasper
dd6a08980a
Normalize missing optional value on Vercel (#15593)
This updates collecting dynamic route params on Vercel to make sure that missing optional dynamic routes are undefined. Additional tests for this mode have also been added to ensure the params are being collected properly

Closes: https://github.com/vercel/next.js/issues/15579
2020-07-29 14:19:25 +00:00
JJ Kasper
fc2167311e
Update header replacing to be more relaxed (#15592)
Instead of trying to parse header values as URLs and then replace path segments in them this switches to escaping characters that can break `path-to-regexp` compiling

Fixes: https://github.com/vercel/next.js/issues/15580
x-ref: https://github.com/vercel/vercel/pull/4942
2020-07-29 08:47:23 +00:00
Robert van Steen
6eea915456
Add better typing for redirect (#15603) 2020-07-29 09:01:21 +02:00
JJ Kasper
86ba29f654
Make sure link can render without router (#15604)
This ensures rendering `next/link` doesn't fail without being nested under the router context.

Closes: https://github.com/vercel/next.js/issues/15543
2020-07-29 06:56:33 +00:00
Tim Neutkens
4730a1061d v9.5.1-canary.0 2020-07-28 14:08:23 +02:00
Arsalan Khattak
edbb32cac9
Next.js prefetching should use requestIdleCallback (#14580) 2020-07-28 13:13:44 +02:00
Prateek Bhatnagar
fb81ecb2bd
Font optimizations (#14746)
Co-authored-by: atcastle <atcastle@gmail.com>
2020-07-28 12:19:28 +02:00
Darsh Patel
27c207da7b
Fix: UnhandledPromiseRejectionWarning when unknown flag provided for cli commands (#15422) 2020-07-28 12:12:57 +02:00
Jan Potoms
91242ca6d7
Ignore history state not created by next.js (#15379)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-07-28 12:02:00 +02:00
Jean Helou
17420c785c
improves baseUrl resolution in typescript monorepos (#13542) 2020-07-28 12:00:27 +02:00
Tim Neutkens
fdfc508a61
Add polyfill for process and Buffer in webpack 5 (#15499) 2020-07-28 11:33:21 +02:00
Gerald Monaco
71bc0db92a
Combine sendPayload and sendHTML (#15475) 2020-07-27 16:19:30 -04:00
Sebastian Benz
5636748708
upgrade @ampproject/toolbox-optimizer to 2.5.14 (#15463) 2020-07-27 18:12:33 +00:00
Tim Neutkens
d33dbea8dc v9.5.0 2020-07-27 16:55:16 +02:00
Joe Haddad
1ee151640e
v9.4.5-canary.45 2020-07-27 01:59:19 -04:00
Joe Haddad
3accce37a7
v9.4.5-canary.44 2020-07-27 00:23:23 -04:00
Joe Haddad
e837c2253d
Upgrade cssnano-simple dependency (#15488) 2020-07-26 23:56:36 -04:00
Jan Potoms
574fe0b582
Make dynamic routes case-sensitive (#15444)
Fixes https://github.com/vercel/next.js/issues/15377
Closes https://github.com/vercel/next.js/pull/15394
2020-07-25 05:11:42 +00:00
James Mosier
f22f88fd73
Always resolve after router.prefetch() (#15448)
In development or with an invalid href, `await router.prefetch()` would not resolve the promise. This PR ensures that `await router.prefetch()` always resolves, no matter if it succeeds or not.

Fixes: https://github.com/vercel/next.js/issues/15436
Relevant discussion: https://github.com/vercel/next.js/discussions/15431#discussioncomment-41264
2020-07-25 04:36:43 +00:00
Tim Neutkens
c5f29b76ea
Update webpack to land chokidar patch for all Next.js users (#15460)
Forces all Next.js users to have this patch installed: https://twitter.com/timneutkens/status/1282129714627448832

Huge thanks to @paulmillr and @sokra 🙏
2020-07-24 19:23:23 +00:00
Mehedi Hassan
00ebce5553
More helpful README (#14830)
* More helpful README

Updated to include more details about Next.js, link to the interactive tutorial, showcase, etc. Content mostly based on the official Next.js site.

* create-next-app readme

An updated readme with more details on options, benefits, etc.

* Apply edits from code review

Co-authored-by: Luis Alvarez D. <luis@vercel.com>

* Remove redundant intro

* Update packages/create-next-app/README.md

* Remove introduction and list in showcase

* Apply suggestions from code review

* Update packages/next/README.md

Co-authored-by: Luis Alvarez D. <luis@vercel.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-07-23 20:56:32 -05:00
Joe Haddad
53a3ffea25
v9.4.5-canary.43 2020-07-22 02:20:02 -04:00
Jan Potoms
fcfbceaa7e
Fix cancellation control flow (#15361) 2020-07-21 13:33:11 -04:00
Joe Haddad
0866ce3f5c
v9.4.5-canary.42 2020-07-20 16:19:48 -04:00
Jan Potoms
7dd61b47a2
Fix basepath router events (#14848)
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-07-20 16:03:49 -04:00
Joe Haddad
d5c1addd64
Simplify trailing slash regex (#15335) 2020-07-20 14:24:43 -04:00
Tim Neutkens
c40f407d82
Stabilize revalidate (#15338) 2020-07-20 14:23:51 -04:00
Joe Haddad
a45def87a2
v9.4.5-canary.41 2020-07-20 13:00:54 -04:00
Joe Haddad
a11d99390a
Stabilize Trailing Slash API (#15331)
Closes #15330
2020-07-20 16:16:59 +00:00
Tim Neutkens
047b73b824 v9.4.5-canary.40 2020-07-20 17:39:41 +02:00
Tim Neutkens
e57b2091aa
Bring over fixes from #15185 (#15326)
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-07-20 11:14:02 -04:00
Bogdan Chadkin
a26c69d11d
Upgrade browserslist (#15324)
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-07-20 10:01:34 -04:00
Joe Haddad
42014a49af
v9.4.5-canary.39 2020-07-19 22:20:41 -04:00
Tim Neutkens
aa62fa7f42
Add test for main.js in webpack.config.js (#15311)
This particular variable was not being read correctly. Added a test for the behavior.

Fixes #15261
2020-07-20 02:16:50 +00:00
Joe Haddad
13a971c8b5
Do not duplicate compilation errors (#15299)
* Do not duplicate compilation errors

* Add tests

* Attempt to fix test

* Fix test
2020-07-19 14:09:41 -04:00
Joe Haddad
b1cfa51b47
v9.4.5-canary.38 2020-07-19 01:53:53 -04:00
Necmettin Karakaya
c2f38f2af0
[Fix] common misspelling errors (#15288)
For reference: https://en.wikipedia.org/wiki/Wikipedia:Lists_of_common_misspellings/For_machines
2020-07-19 04:38:20 +00:00
Jan Potoms
381e44f324
Fix static data fetching when using absolute assetprefix (#15287)
Fixes https://github.com/vercel/next.js/issues/15188

`parseRelativeUrl` was used on urls that weren't always relative. It was used to generate a cache key, but we actually don't need these cache keys to be relative if the urls aren't relative.

Also took a look at the overall static data fetching logic and found a few things:

- [x] cache key is unnecessarily transformed through `prepareRoute`, we can just cache by resolved `dataHref` and remove that function. Pretty sure that `prepareRoute` was also introducing edge cases with `assetPath` and `delBasePath`
- [x] there is [a bug in the caching logic](ebdfa2e7a3/packages/next/next-server/lib/router/router.ts (L898)) that made it fail on the second visit: it should be `Promise.resolve(this.sdc[pathname])` instead of `Promise.resolve(this.sdc[dataHref])`. Also added a test for this
- [x] ~converted to async await to improve stacktraces and readability.~ I assumed this was fine since I saw some async/awaits in that file already but it seems to just blow up the size of the non-modern bundle.
- [x] extracted nested `getResponse` function and define it top level. this should improve runtime performance
- [x] convert `_getStaticData` and `_getServerData` to class methods instead of properties. Not sure why they were defined as properties but I think they belong on the prototype instead.
- [x] remove `cb` property from `fetchNextData`, it's unnecessary and makes the async flow hard to understand.  The exact same logic can go in the `.then` instead.
- [ ] data fetching logic [retries on 5xx errors](ebdfa2e7a3/packages/next/next-server/lib/router/router.ts (L157)), but not on network level errors. It should also retry on those. It should also not retry on every 5xx, probably only makes sense on 502, 503 and 504. (e.g. 500 is a server error that I wouldn't expect to succeed on a retry)

The overall result also is a few bytes smaller in size
2020-07-19 04:02:01 +00:00
Joe Haddad
f5b186cb69
Drop module: esnext requirement in tsconfig.json (#15276)
Next.js forcibly setting `module: 'esnext'` in `tsconfig.json` is necessary to prevent TypeScript from erroring on the following code:

```tsx
import dynamic from 'next/dynamic';

const A = dynamic(() => import('../A'));
```

```
ERROR in /Users/joe/Desktop/scratch/test-cjs/pages/index.tsx(5,25):
5:25 Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
  > 5 | const A = dynamic(() => import("../test"));
```

However, users may want to use one of the many other targets for better interoperability with projects that co-exist with their Next.js project (like `commonjs`).

When cross referenced with:
```
Option '--resolveJsonModule' can only be specified when module code generation is 'commonjs', 'amd', 'es2015' or 'esNext'.ts
```

That means we can permit any of these values:

```json5
      parsedValues: [
        ts.ModuleKind.ES2020,
        ts.ModuleKind.ESNext,
        ts.ModuleKind.CommonJS,
        ts.ModuleKind.AMD,
      ],
```

This PR updates Next.js to allow those!

---

Fixes #15275
2020-07-18 19:37:13 +00:00
Tim Neutkens
4d944a2bfb
Fix no-anon-default-export for webpack 5 (#15293)
Fixes one of the cases of https://github.com/vercel/next.js/pull/15185#issuecomment-660128647
2020-07-18 18:34:05 +00:00
Tim Neutkens
569a289c84 v9.4.5-canary.37 2020-07-17 11:08:33 +02:00
Wayne Warner
7834766907
Fix DevServer#close doesn't close all resources (#15247) 2020-07-17 09:07:48 +00:00
Tim Neutkens
a33bb5bec5
Fix app-document-import-order test for webpack 5 (#15224) 2020-07-17 10:38:06 +02:00
Jan Potoms
dad3299852
Improve query conversion logic (#15236)
`URLSearchParams` has a `forEach` method. this should simplify and shorten the logic. Perhaps it will even phix https://github.com/vercel/next.js/issues/15232
2020-07-16 20:44:45 +00:00
Joe Haddad
2ffe46605d
v9.4.5-canary.36 2020-07-16 10:50:28 -04:00
Joe Haddad
b9f4bdfde3
v9.4.5-canary.35 2020-07-15 21:41:55 -04:00
Jan Potoms
54d991e642
fix basepath trailing slash (#15200)
Fixes the link rewriting part of https://github.com/vercel/next.js/issues/15194
2020-07-15 23:53:31 +00:00
Tim Neutkens
1fe612e882
Make sure the correct chunk names are used in webpack 5 (#15204) 2020-07-15 19:33:41 -04:00
Tim Neutkens
14babe5b3f
Make type checking compatible with webpack 5 (#15158)
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-07-15 13:56:27 -04:00
Joe Haddad
ac7bee1589
v9.4.5-canary.34 2020-07-15 01:29:42 -04:00
Luis Alvarez D
6639b8f2af
Find pages/_document.js chunk in development (#15172)
Chunks already have a normalized path.

Not sure if there are other chunks that require this change, I did a global search and didn't find similar cases.
2020-07-15 05:28:47 +00:00
Joe Haddad
29dfaf9c7b
v9.4.5-canary.33 2020-07-14 14:59:19 -04:00
Joe Haddad
8222d571e7
Correctly fetch data for root route (#15149)
This PR corrects the data fetching behavior for optional root routes.

---

Fixes #14923
2020-07-14 18:58:02 +00:00
Darsh Patel
fcd03091b4
Fix: Invalid flag provided to next build results in UnhandledPromiseRejectionWarning (#15049) 2020-07-13 23:07:35 +02:00
Joe Haddad
a8b2a8e617
v9.4.5-canary.32 2020-07-13 15:40:57 -04:00
Jan Potoms
cd79c829b1
Make sure bad links in router methods resolve in production (#15135)
edge-case I introduced in https://github.com/vercel/next.js/pull/14827
2020-07-13 19:28:32 +00:00
Joe Haddad
dfee55221c
Update Fast Refresh full reload warning (#15062)
We've added a Babel warning for unnamed default exports, and this PR addresses the remaining points in #13024.

Fixes #13024
2020-07-13 18:01:11 +00:00
Jan Potoms
3369d67bd1
Replace node.js url module with WHATWG URL (#14827)
Replace `url.parse` and `url.resolve` logic with whatwg `URL`, Bring in a customized `format` function to handle the node url objects that can be passed to router methods. This eliminates the need for `url` (and thus `native-url`) in core. Looks like it shaves off about 2.5Kb, according to the `size-limits` integration tests.
2020-07-13 16:08:12 +00:00
Jan Potoms
d2699be6e8
Trailing slash basepath (#14781)
Fixes https://github.com/vercel/next.js/issues/14757

Since https://github.com/vercel/next.js/pull/15041 has been sorted out, this can now be fully fixed
There was also a bug in the dev server that causes redirect loops
2020-07-13 14:59:40 +00:00
Jan Potoms
c9492a8cc9
Relax encoding on dynamic prerendered routes (#14717)
It should be enough to encode the characters that `path-to-regexp` uses as path delimiters (`/#?`).

Fixes https://github.com/vercel/next.js/issues/14691
2020-07-13 14:42:27 +00:00
Jason Miller
272080c9c0
Avoid aggressive state loop (#15068)
/cc @cristianbote
2020-07-13 13:12:18 +00:00
JJ Kasper
2d9d649d49
Add handling for custom-routes with basePath (#15041)
This adds handling for custom-routes with `basePath` to automatically add the `basePath` for custom-routes `source` and `destination` unless `basePath: false` is set for the route. 

Closes: https://github.com/vercel/next.js/issues/14782
2020-07-12 19:03:49 +00:00
Tim Neutkens
8a8ef641d8
Update ignored patterns for webpack 4 (#15096)
Found while working on figuring out this bug: https://twitter.com/timneutkens/status/1282129714627448832

 I noticed that the node_modules got passed by the ignore still because when chokidar identifies a ignore pattern is a glob it treats the glob as-is instead of appending `/**` to the glob
2020-07-12 14:03:17 +02:00
JJ Kasper
fed7e093f5
Make sure additional query values aren't added for auto-export (#15037)
This makes sure we don't add an undefined query value for auto-export pages for auto-export pages unnecessarily 

Fixes #15023
2020-07-10 03:16:02 +00:00
Tim Neutkens
525fc360ae
Exclude node_modules in watchOptions (#15020) 2020-07-09 19:58:39 +02:00
Tim Neutkens
096c9a33d2 v9.4.5-canary.31 2020-07-09 16:32:24 +02:00
Tim Neutkens
ab4a90b0d9
Add filename to error in webpack 5 (#14977)
Co-authored-by: Tobias Koppers <sokra@users.noreply.github.com>
2020-07-09 14:31:06 +02:00
Tim Neutkens
10408241f7
Make serverless-plugin compatible with webpack 5 (#15010)
Co-authored-by: Zack Jackson <zackary.l.jackson@gmail.com>
2020-07-09 14:30:40 +02:00
Darsh Patel
6d7cf2a934
Convert profiling mode from configuration option to CLI switch (#14920)
Removed Option to enable `ReactProductionProfiling` from configuration and added a CLI switch for the same.
Users can now do `next build --profile`  to enable react production profiling. 
Also added a warning to notify users about the performance impact

Fixes: #14688
2020-07-09 11:39:12 +00:00
Jan Potoms
33ebda1b7d
Fix root route optional catch-all prerendering (#14986)
Fixes https://github.com/vercel/next.js/issues/14964
2020-07-09 04:21:49 +00:00
JJ Kasper
62902545df
v9.4.5-canary.30 2020-07-08 14:51:37 -05:00
JJ Kasper
16590f7606
Make sure routeKeys are PCRE compliant (#14987)
This adds additional checks against the routeKeys used to build the named regexes for dynamic routes to ensure they follow PCRE rules for named capture groups

x-ref: https://github.com/vercel/vercel/pull/4813
2020-07-08 18:45:53 +00:00
Joe Haddad
85057e5417
v9.4.5-canary.29 2020-07-07 02:11:43 -04:00
Ty Mick
1f5bbb3a8c
Add warning when viewport meta tag is added to _document.js (#13452)
Co-authored-by: Joe Haddad <timer150@gmail.com>
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-07-07 01:43:16 -04:00
Jan Potoms
3623d444c1
Fix basepath browser back/forward issue (#14861)
Discovered while working on https://github.com/vercel/next.js/pull/14848

when asPath is the same but href is different it should use `replaceState` instead of `pushState`, so that browser back/forward behavior is preserved. Currently it's comparing a path that includes basepath with one that excludes  it, so `pushState` is always used. This makes sure the behavior is the same as when running next.js without a basepath
2020-07-07 05:24:38 +00:00
Ben Botvinick
d19c34353d
Add res.redirect response helper (#14705)
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2020-07-07 01:06:16 -04:00
Jan Potoms
2f78d8858f
basePath: Resolve links against router pathname instead of window.location (#14804)
Currently following links are broken when using `basePath`:
```jsx
// pages/hello.js
    <Link href="#hashlink">
      <a id="hashlink">Hash Link</a>
    </Link>
```
with `basePath: '/docs'`, this will navigate to `/docs/docs/hello#hashlink` instead of `/docs/hello#hashlink`

I have a further optimization that builds on this branch that removes `url.parse` and `url.resolve` in favor for `new URL()` in router and link. Will PR when this gets merged.
2020-07-07 04:52:26 +00:00
Asher Foster
33234ca1f1
Attach previewData to API Route request (#13373)
Co-authored-by: Joe Haddad <timer150@gmail.com>
Co-authored-by: Tim Neutkens <timneutkens@me.com>
2020-07-06 23:41:16 -04:00
JJ Kasper
38bd1a024c
Re-enable scroll restoration behind flag (#14046)
This updates the scroll position saving to occur as the scroll position changes instead of trying to do it when the navigation is changing since the `popState` event doesn't allow us to update the leaving history state once the `popState` has occurred. 

The order of events that was previously attempted to save scroll position on a `popState` event (back/forward navigation)

1. history.state is already updated with state from `popState`
2. we replace state with the currently rendered page adding scroll info
3. we replace state again with the `popState` event state overriding scroll info

Using this approach the above event order is no longer in conflict since we don't attempt to populate the state with scroll position while it's leaving the state and instead do it while it is still the active state in history

This approach resembles existing solutions:
https://www.npmjs.com/package/scroll-behavior
https://twitter.com/ryanflorence/status/1029121580855488512

Fixes: https://github.com/vercel/next.js/issues/13990
Fixes: #12530
x-ref: https://github.com/vercel/next.js/pull/14075
2020-07-06 14:27:45 +00:00
matamatanot
62ef872989
Change authors member and links (#14367) 2020-07-05 11:36:50 +02:00
Tim Neutkens
eecc73702b v9.4.5-canary.28 2020-07-03 13:31:38 +02:00
Darsh Patel
e84537f88e
add NextWebVitalsMetric type for reportWebVitals (#14675)
Fixes: #13512
Defined and exported type for `metric`  used in [reportWebVitals](https://nextjs.org/docs/advanced-features/measuring-performance)

```
export function reportWebVitals(metric) {
  if (metric.label === 'custom') {
    console.log(metric) // The metric object ({ id, name, startTime, value, label }) is logged to the console
  }
}
```

One can now do 
```
import { NextWebVitalsMetric } from 'next/app'
export function reportWebVitals(metric: NextWebVitalsMetric ) {
  if (metric.label === 'custom') {
    console.log(metric) // The metric object ({ id, name, startTime, value, label }) is logged to the console
  }
}
```
2020-07-03 03:36:13 +00:00
JJ Kasper
a0c683208a
Fix URL being updated with basePath for 404 page (#14740)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-07-02 11:11:57 +02:00
Jan Potoms
dd97c984b2
Convert link to function component (#14633)
Convert `Link` to a function component. Prefetch logic and memoized url formatting now meshes nicely with React hooks. Class methods were hoisted to module scope to preserve performance characteristics.
2020-07-02 04:53:17 +00:00
JJ Kasper
dc49cd33eb
Update warning for rewriting to auto-export dynamic pages (#14751)
Since the no-op rewrite is a valid rewrite used to check pages/assets before adding a 404-rewrite this makes sure we don't show the rewriting to auto-export dynamic pages warning from it

Closes: https://github.com/vercel/next.js/issues/14736
2020-07-02 04:12:41 +00:00
Jan Potoms
066a18ffc8
Fix basepath root handling (#14756)
Fixes https://github.com/vercel/next.js/issues/14734
2020-07-02 03:48:10 +00:00
Tim Neutkens
9e83ba8cf6 v9.4.5-canary.27 2020-07-01 20:49:52 +02:00
Tim Neutkens
c5cc6072d0
Use single webpack runtimeChunk for Node.js compilation (#14722)
Webpack 5 supports a single runtimechunk for the Node.js compilation, this solves sharing modules between entrypoints.
2020-07-01 15:34:00 +00:00
Tim Neutkens
260707de68
Add etag support for getServerSideProps/getStaticProps pages (#14760)
Fixes #11711

Also cleaned up some extra code.

This was already supported on the Vercel edge network.
2020-07-01 14:59:18 +00:00
JJ Kasper
4a107b6994
v9.4.5-canary.26 2020-06-30 17:21:24 -05:00
JJ Kasper
dd644945ea
Fix encoding for env files in serverless mode (#14750)
This makes sure to base64 encode the `.env*` file contents before passing them in the URL for the serverless-loader since `!` is a special character in this case which can cause webpack to fail to build

Closes: https://github.com/vercel/next.js/issues/14749
2020-06-30 21:33:37 +00:00
Joe Haddad
cbb1c5c755
v9.4.5-canary.25 2020-06-30 11:54:20 -04:00
Joe Haddad
ea1f45a388
Add no-anon-default-export Babel lint rule (#14519)
Fixes #12291 

![image](https://user-images.githubusercontent.com/616428/85499698-176b4900-b5b0-11ea-8a5d-a7f0b4c20307.png)
2020-06-30 13:05:29 +00:00
Yang Sun
a8d2c1ee95
modify global css import error message (#14639)
Fixes #14464
2020-06-30 05:25:02 +00:00
Jan Potoms
ab7010711f
Avoid pulling extra code in the bundles for trailingSlash logic (#14696)
* avoid pulling code in the bundle for `trailingSlash` logic when it's not enabled
* avoid cloning the url an extra time if normalizing the path doesn't change it
2020-06-30 04:06:39 +00:00
Jan Potoms
6ff3a63a2e
Fix link to file url behavior with trailingSlash (#14681)
Avoid trailing slashes on urls that look like files. The redirect for `trailingSlash: true` will now look like:

```
Redirects

┌ source: /:path*/:file.:ext/
├ destination: /:path*/:file.:ext
└ permanent: true

┌ source: /:path*/:notfile([^/.]+)
├ destination: /:path*/:notfile/
└ permanent: true
```

The default still looks like:

```
Redirects

┌ source: /:path+/
├ destination: /:path+
└ permanent: true
```
After this gets merged, I have a few optimizations planned on the normalization code that should reduce the client bundle a little and that consolidates the `trailingSlash` and `exportTrailingSlash` options
2020-06-30 02:25:12 +00:00
Joe Haddad
af901f4366
v9.4.5-canary.24 2020-06-29 17:31:30 -04:00
Joe Haddad
923afd68d4
Upgrade CSSNano Version (#14638)
Fixes #14632
Fixes #14690
2020-06-29 21:29:53 +00:00
Joe Haddad
ac5b2acd12
Fix dynamic route encoding for NextLinks (#14281) 2020-06-29 16:44:43 -04:00
Joe Haddad
1d0e7a8a9a
Enable Optional Catch-All by Default (#14687)
Closes #14682
2020-06-29 18:50:32 +00:00
JJ Kasper
f12a9f92f8
v9.4.5-canary.23 2020-06-29 10:45:40 -05:00
JJ Kasper
89ca0d10d4
Update to use getDataHref in fetchNextData (#14667)
This updates `fetchNextData` to re-use the `getDataHref` function from `page-loader` which has more verbose handling to ensure the correct `/_next/data` URL is built. Re-using this logic ensures the `/_next/data` URL can still be built even when a mismatching `href` and `as` value is provided to `next/link`.

This also fixes a case in `getDataHref` where optional values that weren't provided would fail to build the data href since the check requiring the param be present while interpolating the route values hasn't been updated to allow missing params for optional values.

An additional test case has been added to the prerender suite to ensure the `/_next/data` URL is built correctly when mismatching `href` and `as` values are provided

x-ref: https://github.com/vercel/next.js/discussions/14536
x-ref: https://github.com/vercel/next.js/discussions/9081#discussioncomment-31160
Closes: https://github.com/vercel/next.js/issues/14668
2020-06-29 15:14:45 +00:00
Jan Potoms
b8a30bab55
Handle trailing slashes, even when query parameters (#14650)
Add tests and fix for when the url contains query parameters.
`router` now uses the same method for formatting url+as pair as `Link`, will be able to share code after https://github.com/vercel/next.js/pull/14633 is merged
2020-06-29 14:50:45 +00:00
Tim Neutkens
327f6eed41
Clean up plugins (#14676)
Preparation for a larger rewrite
2020-06-29 14:26:49 +00:00
Tim Neutkens
83de34239c
Convert incremental generation cache to a class (#14660)
We've been meaning to change this code for a while 👍

- Changed the name from spr to incremental
- Changed the code to be a class instead of using module scope variables
2020-06-28 20:58:43 +00:00
Todor Totev
1aed9eaac1
Introduce react profiling production flag (#13873)
Closes [13709](https://github.com/vercel/next.js/issues/13709).

The solution works, **(tested and confirmed with true and false flags with the latest next version)** though I am quite sure this is not the most elegant and proper way to implement it. I have spent the good part of yesterday and today's morning in order to make it more generic but since it's my first time working with anything related to webpack I have struggled miserably. Last, but not least I'm unsure if this is the most proper naming for the flag.

Please, let me know what you want me to change and I'll get it done asap.
2020-06-28 11:23:29 +00:00
Tim Neutkens
479c38d3b7 v9.4.5-canary.22 2020-06-27 20:39:52 +02:00
Tim Neutkens
b4b68c0b85
Use assetEmitted hook instead of afterEmit (#14626)
Makes sure this works correctly with webpack 5.
2020-06-27 17:16:55 +00:00
Jan Potoms
bd24b70d60
Fix trailing slash handling in exporting pages with getStaticPaths (#14620)
Fixes https://github.com/vercel/next.js/issues/14573
2020-06-27 11:59:27 +00:00
Tim Neutkens
3909c76cef v9.4.5-canary.21 2020-06-27 13:11:08 +02:00
JJ Kasper
61b68730f8
De-experimentalize custom-routes (#14602)
This moves the custom-routes configs outside of the experimental section to prepare them for being made stable

Fixes: https://github.com/vercel/next.js/issues/14184
2020-06-27 09:18:18 +00:00
Tim Neutkens
8393869912 v9.4.5-canary.20 2020-06-26 12:05:38 +02:00
Tim Neutkens
ae542b8525
Use entry option instead of custom make hook (#14527)
Simplifies on-demand-entries a bit.
2020-06-26 04:26:09 +00:00
JJ Kasper
3b12dbf488
v9.4.5-canary.19 2020-06-25 15:13:12 -05:00
Jan Potoms
fdcc24be6d
Fix native-url path parsing bug (#14442)
Test case for https://github.com/GoogleChromeLabs/native-url/pull/28

Fix https://github.com/vercel/next.js/issues/14419
2020-06-25 17:19:12 +00:00
Anthony Short
61c4cdb501
Avoid adding basePath when it's not needed (#14535)
* Avoid adding basePath when it's not needed

When using the `basePath` setting, on pages with params it will fire a router change. This will pass the url pathname in the `as` param using the `getUrl()` function. This means the `as` path will be sent through already including the `basePath`, leading to `/basePath/basePath/path` which will cause the router to throw an error.

* lint

* Add test case and ensure removal

* Make sure to re-add before changeState

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2020-06-24 21:36:22 -05:00
James Mosier
435bf65784
Warn/revert custom devtool in development mode (#14285)
Warn users and revert their `devtool` when they manually change the `devtool` in development mode. For this addition, I check to ensure the `devtool` is custom (i.e. different than what is set by Next) and has a value (`false` is fine as a custom `devtool`!).

As described in [this issue (13963)](https://github.com/vercel/next.js/issues/13963), changing the `devtool` in development mode can cause issues with performance.

Fixes #13963
2020-06-24 04:15:57 +00:00
JJ Kasper
15367829de
v9.4.5-canary.18 2020-06-23 16:04:34 -05:00
JJ Kasper
5bb081f13f
Handle rendering next/head outside of Next.js (#14511)
This ensures `next/head` doesn't fail to render when being rendered during tests or outside of Next.js' tree

Closes: https://github.com/vercel/next.js/issues/14425
2020-06-23 20:46:40 +00:00
Jan Potoms
574e9d285a
Remove deprecated plugin in favor of the option (#14503)
Not sure if it's still there for a reason, but from  the types for `NoEmitOnErrorsPlugin`
```js
/* @deprecated use config.optimization.noEmitOnErrors */
```
2020-06-23 17:44:51 +00:00
Tim Neutkens
be2a63238a
Webpack 5 build compat (#14498)
Initial PR to make `next build` work with webpack 5, still needs more work to make sure runtimeChunk and such are shared between pages.

- No longer needs the custom ChunkNamesPlugin as the default behavior was changed
- Dropping AMP First client page bundles is now compatible
2020-06-23 15:47:50 +00:00
Tim Neutkens
23db226ea5 v9.4.5-canary.17 2020-06-23 13:39:18 +02:00
Jan Potoms
2142b76e6b
Normalize trailing slashes (#13333)
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
Co-authored-by: Tim Neutkens <timneutkens@me.com>
2020-06-23 13:38:49 +02:00
Jan Potoms
bc2cb2210f
Fix prerendered nested index handling (#14383)
Noticed this while reviewing https://github.com/vercel/next.js/pull/14376. After having done https://github.com/vercel/next.js/pull/13699, this code didn't feel right to me:
```js
function prepareRoute(path: string) {
  path = delBasePath(path || '')
  // this /index rewrite is problematic, it makes pages/index.js 
  // and pages/index/index.js point to the same thing:
  return toRoute(!path || path === '/' ? '/index' : path)
}
```
Added a nested index page to the prerender tests and found it was rendering the `/` route on navigation. This uncovered 2 more places around the dataroute where the index path was not translated correctly.

**edit:**

Just to note that there was nothing wrong with https://github.com/vercel/next.js/pull/14376, the issue was already there, I just noticed it while reading that PR
2020-06-23 05:49:48 +00:00
JJ Kasper
fca768d3d2
Update to rely on dynamic param values from proxy (#12608)
This updates to rely on query values from the proxy when capable to ensure the correct values are provided. This does not remove the `x-now-route-matches` as this is still needed until the values are provided in the query instead for iSSG

x-ref: https://github.com/zeit/now/pull/4196
x-ref: https://github.com/zeit/next.js/pull/12250
x-ref:

Tested against the following updated fixtures from https://github.com/vercel/vercel/pull/4682 with https://github.com/ijjk/next-update-loader

- 08-custom-routes-catchall
- 10-export-cache-headers
- 16-base-path
- 22-ssg-v2
- 23-custom-routes-verbose
2020-06-23 05:31:32 +00:00
Tim Neutkens
1f125f8a7e v9.4.5-canary.16 2020-06-22 23:20:11 +02:00
Tim Neutkens
6c2ce70608
Remove buildId from server-side files (#14413)
Gets rid of the custom function for naming files by removing buildId from the file paths.
2020-06-22 21:12:36 +00:00
Jan Potoms
a7af013350
Update route regex for optional catch-all parameters in named regexes (#14456)
Noticed while working on https://github.com/vercel/next.js/pull/14400 that the optional catch-all handling was missing in `namedRegex`.

This whole file also seemed quite regex heavy so I took a look at the overall logic and changed a few things. It worked by regex escaping the whole route then unescape the dynamic parts. I changed it to only regex escape the static parts, this eliminates unnecessary back and forth escaping. It also makes the dynamic parts handling more readable. The whole logic is less reliant on regexes and just uses simple string manipulation to translate the route into a regex, I didn't measure anything but as an effect this should make it more performant.
2020-06-22 18:16:21 +00:00
Jan Potoms
7078318543
Shave a few bytes off the bootstrap code (#14457)
Saw in the client bootstrap script that the error message was printed alongside the stacktrace. This is unnecessary since the stacktrace already includes the error message. In fact, it seems like browsers already do a good job of printing an error with its stacktrace when you just print them using `console.error`. It's a bit minor, but this should shave off a few bytes of the bundle.
2020-06-22 17:50:17 +00:00
Joe Haddad
6ab0724916
v9.4.5-canary.15 2020-06-22 10:14:07 -04:00
Joe Haddad
67ff62507d
Do not remove no-FOUC styles too early (#14448)
We previously used to remove our FOUC helper inside of the style injection to ensure content was shown as fast as possible.

This behavior, however, was problematic for a few reasons:

1. Large JavaScript chunks would take longer than an animation frame to parse, causing FOUC
1. Rendering would sometimes complete before an animation frame, causing improper effects

To fix the latter, we started removing the no FOUC helper **before** rendering, however, we never fixed the former by removing the dead code.

There's not a great way to test this because the FOUC is so fast and flaky, however, this code really shouldn't exist and isn't likely to be re-added (regress).

Also, we already have FOUC tests that occasionally flake, probably due to this.


Fixes #12448
Fixes #13058
Fixes #11195
Fixes #10404
2020-06-22 14:10:19 +00:00
Jan Potoms
eead55cbaf
Fix prefetch and some other issues with optional catch all (#14400)
Fix https://github.com/vercel/next.js/issues/14290 and a couple other issues around optional catch-all that popped up after writing these tests

Closes https://github.com/vercel/next.js/pull/14344
2020-06-22 03:00:30 +00:00
Tim Neutkens
ee1cf6f8c4 v9.4.5-canary.14 2020-06-21 11:20:23 +02:00
Tim Neutkens
bef9b56109
Update filename generation for client-side compilation (#14279)
Updates the way filenames are generated for browser compilation.
Notably:
- All entry bundles now have hashes in production, this includes pages (previously pages used a buildId in the path)
- The AmpFiles no longer depends on hardcoded bundle names, it uses the buildManifest instead (internals)
- All cases where we match the page name from the chunk/entrypoint name now use the same function `getRouteFromEntrypoint` (internals)
- In development we no longer include the "faked" `buildId` set to `development` for page files, instead we just use the `/_next/static/pages` path (was `/_next/static/development/pages`). This was changed as it caused unneeded complexity and makes generating the bundles easier (internals)
- Updated tons of tests to be more resilient to these changes by relying on the buildManifest instead of hardcoded paths (internals)

Follow up of these PRs:
https://github.com/vercel/next.js/pull/13759
https://github.com/vercel/next.js/pull/13870
https://github.com/vercel/next.js/pull/13937
https://github.com/vercel/next.js/pull/14130
https://github.com/vercel/next.js/pull/14176
https://github.com/vercel/next.js/pull/14268


Fixes #6303
Fixes #12087 
Fixes #1948
Fixes #4368
Fixes #4255
Fixes #2548
2020-06-20 19:59:47 +00:00
JJ Kasper
546c6512bd
Correct /_next/data link for GS(S)P with basePath (#14376)
This corrects the `/_next/data` path generated when using `basePath` with `getStaticProps` in a `pages/index.js` file which was previously stripping the `basePath` without checking if `/index` needed to be appended after stripping. This also adds additional checks to the `basePath` test suite to prevent regressing   

x-ref: https://github.com/vercel/next.js/pull/9872#issuecomment-646841260
2020-06-19 21:53:15 +00:00
JJ Kasper
f92571d502
De-experimentalize basePath config (#14283)
This moves the experimental `basePath` config out of the `experimental` section to prepare it for being stable
2020-06-18 10:10:20 +00:00
stefanprobst
279ae19c7e
docs: update links to docs site (#14305)
this updates some links to the docs site to their new location
2020-06-18 09:54:07 +00:00
Tim Neutkens
1fc0aae589
Prepare for webpack 5 upgrade (#14268)
Tweaked the config that can already be updated a bit.
2020-06-17 15:00:29 +00:00
Joe Haddad
11753dd27f
v9.4.5-canary.13 2020-06-17 09:37:56 -04:00
Joe Haddad
7ce000b328
WSL should be considered Windows for HMR option (#14254)
This toggles the separate Windows `devtool` setting for WSL. We cannot test this as we do not have access to WSL in our current test setup suite, however, this is a temporary patch that should be fixed with the webpack 5 upgrade, so I do not feel strongly about testing it.

---

Fixes #14253
2020-06-17 12:59:00 +00:00
Joe Haddad
5ed89d3021
Render a helpful message for null GS(S)P return (#14252)
This makes Next.js render a better error message when `undefined` (or null) is returned from `getStaticProps` or `getServerSideProps`.

---

Fixes #11139
2020-06-17 09:25:27 +00:00
JJ Kasper
a9a7319ee3
Refactor moveExportedPages to use getPagePath (#14247)
Updates to not build the path from scratch here and relies on `getPagePath` instead

Closes: https://github.com/vercel/next.js/issues/14223
2020-06-17 03:40:07 +00:00
JJ Kasper
08d7755e68
Update routeKeys to handle non-word characters (#12801)
This updates the named regexes output in the `routes-manifest` and the associated `routeKeys` to not use any non-word characters as this breaks the named regexes e.g. `"Invalid regular expression: "^/(?<data\-provider\-id>[^/]+?)(?:/)?$"`

x-ref: https://github.com/zeit/now/pull/4355
2020-06-16 13:49:13 +00:00
Tim Neutkens
ea6b8dac40
use requirePage for /_document and /_app (#14176) 2020-06-15 10:41:17 -04:00
stefanprobst
66778c7ab0
chore: add retry method to loadable types (#14152) 2020-06-15 14:21:03 +02:00
Sebastian Benz
eef40c5948
update AMP Optimizer to v2.5.3 (#14173) 2020-06-15 14:17:59 +02:00
Tim Neutkens
27f653bb3d
Clean up AMP bundle removal (#14130)
Drops the entrypoint instead of removing the underlying file.
2020-06-14 12:49:46 +00:00
Tim Neutkens
60d1ed2ee5 v9.4.5-canary.12 2020-06-12 11:11:17 +02:00
Tim Neutkens
89fffa694d
Remove Head.rewind as it's no longer needed (#14091)
Fixes #9326
2020-06-11 22:09:06 +00:00
Sebastian Benz
ec90cc83ff
Update AMP Optimizer to v2.5.2 (#14095)
This addresses the problem of the optimizer postinstall hook causing
delayed installs if run behind a proxy. See https://github.com/ampproject/amp-toolbox/issues/832

Fixes #14070
2020-06-11 19:28:56 +00:00
Joe Haddad
c2c0e6d677
v9.4.5-canary.11 2020-06-11 10:41:38 -04:00
Joe Haddad
c8b51b5c3a
Revert "Add scroll restoration handling after render is done" (#14075) 2020-06-11 10:40:08 -04:00
JJ Kasper
3d6d033a5b
Normalize asPath between SSR and CSR with basePath (#14040)
To make `asPath` consistent with `basePath` handling this makes sure it is always stripped including on the client under the `asPath` value and from `req.url` in the `serverless-loader`. Additional tests have been added for this behavior to ensure we don't regress on this

Closes: https://github.com/vercel/next.js/issues/14037
Closes: https://github.com/vercel/next.js/issues/14039
2020-06-11 14:06:06 +00:00
Tim Neutkens
90638c7001 v9.4.5-canary.10 2020-06-11 10:57:59 +02:00
Tim Neutkens
76fddcd7ef
Use chunkhash instead of buildId for pages (#13937)
Co-authored-by: JJ Kasper <jj@jjsweb.site>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-06-11 10:57:24 +02:00
Joe Haddad
91664d1d02
Eliminate public folder enumeration (#14042)
This builds off of @timneutkens's PR instead of updating it because it's his `canary` branch.

Updated to still `stat`, as it's the only way to test the difference between a file and directory. 

---

Closes #13506
Fixes #12235
2020-06-10 20:35:34 +00:00
JJ Kasper
d5493ff24d
Fix dynamic route match and basePath (#14036)
This correctly strips the `basePath` before generating the `route-matcher` for dynamic routes and adds regression tests to ensure these work correctly with the `basePath` feature

Closes: https://github.com/vercel/next.js/issues/13966
2020-06-10 18:26:57 +00:00
JJ Kasper
ad2c1a8a16
Make sure to watch all next-server files (#14023)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-06-10 11:27:37 -05:00
Ben Spinks
a9891095ec
Invert colors of compiling indicator (#13995)
Hi,

This PR inverts the colors for the compiling indicator, closes #13952.

The second commit makes the styling consistent with the prerender indicator (height and border)

From:
![before](https://user-images.githubusercontent.com/32001471/84236653-df640080-aaef-11ea-8532-a5d65cab5cc3.gif)

To:
![after](https://user-images.githubusercontent.com/32001471/84247287-c6fbe200-aaff-11ea-9eff-a16c42a7b625.gif)
2020-06-10 13:15:35 +00:00
Joe Haddad
54ac432390
v9.4.5-canary.9 2020-06-10 00:51:04 -04:00
Joe Haddad
d874329d11
Prioritize webpack bootstrapping first (#13987)
Webpack will randomly execute script order if its runtime is not prioritized before chunks execute.

This seems to be somehow triggered in #13870 because of slightly different script ordering.

This had actually broke CSS, which is why our tests are failing 50% of the time:

Without this PR:
![image](https://user-images.githubusercontent.com/616428/84221491-57f0a000-aaa3-11ea-9dff-c27c87d29ac5.png)

However, it's still problematic to use `async` in development since we rely on script execution order. So, this PR disables `async` in development.

We're exploring `defer` in the future anyway (over `async`), which will be ordered, so I don't mind diverging between dev and prod in this way.

---

Fixes #13911
2020-06-10 04:41:59 +00:00
JJ Kasper
06ac0adcf8
Add scroll restoration handling after render is complete (#13914)
This adds scroll restoration handling to make sure the correct scroll position is restored after navigating back/forward to a page and the rendering hasn't completed by the time the default browser scroll restoration has taken place. 

An initial failing test case was added which is working with the changes in this PR, if there are any other cases that should be added let me know and I can make sure we have them to ensure we don't regress on this behavior

---

Fixes #12530
2020-06-09 20:53:44 +00:00
Jan Potoms
9da99bcb66
Prepare custom routes loading for adding additional routes (#13857)
Extracted from https://github.com/vercel/next.js/pull/13333, the same exact code lives in that PR as well, but we can merge this separately if it makes reviewing https://github.com/vercel/next.js/pull/13333 easier

This PR does 3 things 
- deduplicate code from build and next-dev-server that loads custom routes from next.config.js  (`loadCustomRoutes`)
- in `loadCustomRoutes`, load these rewrites, headers and redirects configs concurrently instead of sequentially.
- in next-server, make `this.customRoutes` always defined, this allows us to remove the big `if` around its initialization code in `generateRoutes`, which in turn makes it possible to reuse this code for other routing than user defined routes, which is how https://github.com/vercel/next.js/pull/13333 adds its redirects.
2020-06-09 20:16:23 +00:00
Joe Haddad
7d648dace1
Change text from "Attention" to "Warning" (#13973)
Fixes #13972
2020-06-09 19:43:15 +00:00
Sebastian Benz
adf1a24ccb
Update AMP Optimizer to 2.5.1 (#13925)
Most notable new feature: automated hero image preloading.

Release notes: https://github.com/ampproject/amp-toolbox/releases/tag/v2.5.1
2020-06-09 09:08:29 +00:00
Tim Neutkens
2920af7cd3
Combine taskr next-server tasks into one (#13842)
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-06-08 21:32:09 -04:00
Joe Haddad
72ddfeb6a1
v9.4.5-canary.8 2020-06-08 14:12:17 -04:00
Tim Neutkens
2169c0ce97
Use buildManifest to load page JS (#13870)
Initial work to use chunkhashes instead of buildid for the page files in production. This does not change the calculation of the filename itself initially.
2020-06-08 18:11:00 +00:00
JJ Kasper
8dd3d2a8e2
Update handling for basePath to only automatically add (#13817)
As discussed, this streamlines the handling for `basePath` to not automatically strip and add the `basePath` when provided to `next/link` or `router.push/replace` and only automatically adds the `basePath` and when it is manually provided it will cause a 404 which ensures `href` still matches to the pages directory 1-to-1.

This also adds additional test cases that we discussed to ensure this behavior is working as intended

---

Fixes #13902
2020-06-08 15:59:50 +00:00
Todor Totev
1c91a46c3c
Fix message on getStaticPaths conflict with getServerSideProps (#13874)
* initial

* Update tests

Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-06-08 10:25:37 -04:00
Jan Potoms
08b2e9b3ba
Remove some leftovers after index page updates (#13876) 2020-06-08 16:17:03 +02:00
Jan Potoms
989b6ad145
Preserve url better in exportTrailingSlash (#13840)
Discovered while doing https://github.com/vercel/next.js/pull/13333. `#` or `?` used to be stripped if there wasn't a value behind
2020-06-07 17:15:06 +00:00
Tim Neutkens
e125d905a0
Clean up render.tsx options (#13759)
Went through and removed a bunch of internal options which are just pass-through values of buildManifest

Closes #13851
2020-06-06 23:00:03 +00:00
matamatanot
38519c626e
refactor: Use native fs instead of fs-extra and promisify (#13841)
**add-comment.js**
`writeFile` is not unique to `fs-extra`. 

**lib/find-page-file.ts**
ref: #12026
2020-06-06 15:40:06 +00:00
Ty Mick
c33757f1ad
Fix base path handling with URL queries in dev server (#13560)
So I can't *entirely* explain why, but I believe this fixes #13132. 🙈 I basically ended up looking around at other `_next` URLs (are those asset URLs?) around the project and seeing that they tended to use `delBasePath()` to remove the base path from the current page's path whenever it was used.

When testing locally with the [repo submitted with the issue](https://github.com/robertovg/next-base-path-example), I no longer experience the constant page-reloading in dev mode when adding a query string to the URL.
2020-06-05 17:47:16 +00:00
JJ Kasper
4e6eb5b3a7
Update rewrite dynamic SSG error (#13724)
This error isn't specific to just fallback SSG pages since any dynamic SSG page that is rewritten to can cause the `/_next/data` request to fail also since it currently derived from the the URL. 

This can also fail for `getServerSideProps` since it derives the `/_next/data` URL the same way so might need to be updated to show in that case also
2020-06-04 17:49:53 +00:00
Jan Potoms
1b36f0c029
Fix pages/index.js and pages/index/index.js behavior (#13699)
Disambiguate between pages/index.js and pages/index/index.js so that they resolve differently.
It all started with a bug in pagesmanifest that propagated throughout the codebase. After fixing pagesmanifest I was able to remove a few hacks here and there and more logic is shared now. especially the logic that resolves an entrypoint back into a route path. To sum up what happened:

- `getRouteFromEntrypoint` is the inverse operation of `getPageFile` that's under `pages/_document.tsx`
- `denormalizePagePath` is the inverse operation of `normalizePagePath`.

Everything is refactored in terms of these operations, that makes their behavior uniform and easier to update/patch in a central place. Before there were subtle differences between those that made `index/index.js` hard to handle.

Some potential follow up on this PR:
- [`hot-reloader`](https://github.com/vercel/next.js/pull/13699/files#diff-6161346d2c5f4b7abc87059d8768c44bR207) still has one place that does very similar behavior to `getRouteFromEntrypoint`. It can probably be rewritten in terms of `getRouteFromEntrypoint`.
- There are a few places where `denormalizePagePath(normalizePagePath(...))` is happening. This is a sign that `normalizePagePath` is doing some validation that is independent of its rewriting logic. That should probably be factored out in its own function. after that I should probably investigate whether `normalizePagePath` is even still needed at all.
- a lot of code is doing `.replace(/\\/g, '')`. If wanted, that could be replaced with `normalizePathSep`.
- It looks to me like some logic that's spread across the project can be centralized in 4 functions 
  - `getRouteFromEntrypoint` (part of this PR)
  - its inverse `getEntrypointFromRoute` (already exists in `_document.tsx` as `getPageFile`)
  - `getRouteFromPageFile` 
  - its inverse `getPageFileFromRoute` (already exists as `findPageFile ` in `server/lib/find-page-file.ts`)

  It could be beneficial to structure the code to keep these fuctionalities close together and name them similarly.
 - revise `index.amp` handling in pagesmanifest. I left it alone in this PR to keep it scoped, but it may be broken wrt nested index files as well. It might even make sense to reshape the pagesmanifest altogether to handle html/json/amp/... better
2020-06-04 17:32:45 +00:00
Tim Neutkens
0fc344e6a3
Remove unused variable (#13716)
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-06-03 11:58:58 -04:00
Todor Totev
bad376127e
Detailed error and warnings upon next() call (#13539)
**First, apologies for a second PR on the same issue but I was working on this already so I thought I'd push it and let you decide which you want to merge.**

The PR is related to [13466](https://github.com/vercel/next.js/issues/13466).

Based on my research, the error happens if the options are empty, null, or undefined. That's why I have decided that the most proper check would be using the! post-fix expression operator may assert that its operand is non-null and non-undefined. ``if (options == null)``

(Optional)
I have also added a warning, which warns the user if the passed "dev" variable is not a boolean.

It's my first PR on the "packages" part of the repo so I'd be glad to receive all kinds of critics. If you want me to change or remove anything, I'm open to suggestions.

---

Fixes #13466
2020-06-03 03:19:29 +00:00
Joe Haddad
ca4de3e7e8
v9.4.5-canary.7 2020-06-02 22:06:20 -04:00
Tim Neutkens
08e7fa16db
Get rid of autodll (#13669)
Prepares for the upgrade to webpack 5
2020-06-02 19:20:37 +00:00
Joe Haddad
4dd5616af2
v9.4.5-canary.6 2020-06-02 13:36:40 -04:00
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
Tim Neutkens
0769a82acc
Remove granularChunks experimental option as it was launched (#13663)
The option was released a few months ago so we can get rid of this option.
2020-06-02 14:13:11 +00:00
Tim Neutkens
31b3e46b8f
Use inclusive naming for variables / examples (#13657)
https://twitter.com/vercel/status/1267650234236252161

The variables for the launchEditor feature were kept consistent with Create React App so it's probably a good idea for them to change them too: https://github.com/facebook/create-react-app/search?q=WINDOWS_FILE_NAME_WHITELIST

Prior discussions on this topic:
- https://github.com/hashicorp/consul/issues/7901
- https://github.com/styled-system/styled-system/issues/391
- https://github.com/go-sql-driver/mysql/pull/1116
- https://github.com/lagom/lagom/issues/2532
- https://github.com/grafana/grafana/issues/18841
2020-06-02 13:52:41 +00:00
Joe Haddad
9ce4655fee
v9.4.5-canary.5 2020-06-01 19:20:19 -04: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
Tim Neutkens
b124ed2e14
Added no-shadow rule to eslint (#13645)
Was going through _document and noticed some variable shadowing going on. Added a rule for it to our eslint configuration and went through all warnings with @Timer.
2020-06-01 21:00:22 +00:00
Tim Neutkens
6f8ef70cb0
Remove middleware function that is never called (#13642)
Follow-up to #12218, missed this bit of code.
2020-06-01 20:12:58 +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
Joe Haddad
9dede1011a
v9.4.5-canary.4 2020-06-01 10:08:35 -04: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
Tim Neutkens
3dc24bbd79
Update waitUntilValid parameters (#13612)
Since the reload function was removed this parameter is no longer needed 💯
2020-05-31 21:28:23 +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
Tim Neutkens
6a993d5972 v9.4.5-canary.3 2020-05-29 17:58:45 +02:00
Tim Neutkens
4199de6376
Remove old reloading code (#13554)
This code existed mostly to work around webpack 2 (yes 2.x) limitations where it crashed in certain cases where files didn't exist anymore. We have tests for that behavior and latest webpack has fixed these. Hence why this can be removed 👍
2020-05-29 15:55:36 +00:00
Tim Neutkens
fef3b8c2ce
Update babel config found log to new logging output (#13550)
Updates the message to be in line with .env loading.
2020-05-29 15:08:28 +00:00
Kristoffer K
0199d00671
fix: update ampproject/toolbox-optimizer (#13547) 2020-05-29 15:33:16 +02:00
Tim Neutkens
619493a9be v9.4.5-canary.2 2020-05-29 10:20:37 +02: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
a62aadddab
v9.4.5-canary.1 2020-05-29 00:47:33 -04: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
Tim Neutkens
ad145d347f v9.4.5-canary.0 2020-05-28 13:56:34 +02:00
Joe Haddad
aab1fff861
Better NODE_ENV explanation (#13476)
After #12361, I've seen a few users ask "but why".

This PR updates the err.sh link to better explain the restriction.

It also provides an alternative!
2020-05-28 09:10:22 +00:00
Joe Haddad
bee8c31b87
Lint for invalid imports (#13482)
This adds a lint rule to ensure we don't import dev dependencies by accident.
2020-05-28 08:23:10 +00:00
Joe Haddad
e6eb32f676
v9.4.4 2020-05-28 00:07:27 -04:00
Joe Haddad
b37d2f1267
v9.4.4-canary.0 2020-05-27 23:44:36 -04:00
Joe Haddad
096d50386e
Do not import from fs-extra (#13481) 2020-05-27 23:43:48 -04:00
Joe Haddad
96c3b08701
v9.4.3 2020-05-27 22:17:56 -04:00
Joe Haddad
e7922873ba
v9.4.3-canary.3 2020-05-27 21:25:18 -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