Commit graph

1509 commits

Author SHA1 Message Date
Jens Meindertsma
a3c47721a1
Include all files in Prettier (#17050)
This uses the "Expand directories" feature introduces in Prettier 2.0 to automatically format all supported file types.

Also, I fixed some badly formatted files.
2020-09-14 02:53:19 +00:00
Joe Haddad
9b22dc4660
Improve custom document error message (#17048) 2020-09-12 18:57:07 +00:00
Markus Lautenbach
76e86e0fba
Remove false positive in circular structure detection (#16380)
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-09-12 02:36:29 -04:00
JJ Kasper
8ecc359b6d
Update to check for overlay in client nav tests (#17002)
Closes: https://github.com/vercel/next.js/issues/14433
2020-09-11 08:37:19 +00:00
JJ Kasper
47d983f71f
Add error when href interpolation fails (#16946)
This adds an error when interpolation fails to make sure invalid `href`s aren't accidentally used and an invalid URL is built. 

Closes: https://github.com/vercel/next.js/issues/16944
2020-09-10 20:05:02 +00:00
Joe Haddad
1ea6745106
Importing CSS from Third Party React Components (#16993) 2020-09-10 13:45:30 -04:00
Jan Potoms
5aed1d2e35
Correct query behavior for falsey values to pre 9.5.1 behavior (#16608)
Fixes https://github.com/vercel/next.js/issues/16147
2020-09-10 15:12:37 +00:00
JJ Kasper
dcdcf49a87
Fix resolving href with a rewrite (#16975)
This makes sure we properly resolve a rewrite when only the `href` value is used. This was causing a full-reload and was missed in the existing test since we weren't making sure a full navigation didn't occur which has been added in this PR. 

Fixes: https://github.com/vercel/next.js/issues/16974
2020-09-10 00:55:22 +00:00
Joe Haddad
25cdaab297
Add Support for CSS Module Value Imports (#16973)
Fixes #10142
Fixes #11629
2020-09-09 23:29:37 +00:00
Gerald Monaco
039eb817e1
Remove next-head-count (#16758)
Removes `next-head-count`, improving support for 3rd party libraries that insert or append new elements to `<head>`.

---

This is more or less what a solution with a `data-` attribute would look like, except that instead of directly searching for elements with that attribute, we serialize the elements expected in `<head>` and then find them/assume ownership of them during initialization (in a manner similar to React's reconciliation) based on their properties.

There are two main assumptions here:
1. Content is served with compression, so duplicate serialization of e.g. inline script or style tags doesn't have a meaningful impact. Storing a hash would be a potential optimization.
2. 3rd party libraries primarily only insert new, unique elements to head. Libraries trying to actively manage elements that overlap with those that Next.js claims ownership of will still be unsupported.

The reason for this roundabout approach is that I'd really like to avoid `data-` if possible, for maximum compatibility. Implicitly adding an attribute could be a breaking change for some class of tools or crawlers and makes it otherwise impossible to insert raw HTML into `<head>`. Adding an unexpected attribute is why the original `class="next-head"` approach was problematic in the first place!

That said, while I don't expect this to be more problematic than `next-head-count` (anything that would break in this new model also should have broken in the old model), if that does end up being the case, it might make sense to just bite the bullet.

Fixes #11012
Closes #16707

---

cc @Timer @timneutkens
2020-09-09 01:41:04 +00:00
JJ Kasper
f46ddc6933
Correct page path for GS(S)P data refreshing (#16939)
This makes sure to the page path is the expected version to trigger refreshing on the client and adds additional tests to make sure it is working properly with these page variants. 

Closes: https://github.com/vercel/next.js/issues/16938
2020-09-08 16:00:05 +00:00
JJ Kasper
bc80fb4fb2
Add handling for redirects from getStaticProps/getServerSideProps (#16642)
Co-authored-by: Tim Neutkens <timneutkens@me.com>
2020-09-08 09:23:21 +02:00
JJ Kasper
f942d9e892
Include additional query values when interpolating href (#16878)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-09-07 13:09:02 +02:00
JJ Kasper
489cad36bc
Fix href resolving with trailing slash enabled (#16873)
This makes sure to strip the trailing slash before attempting to resolve the `href` against pages/dynamic routes and adds tests ensuring the correct pages are resolved with `trailingSlash: true` enabled.

Fixes: https://github.com/vercel/next.js/issues/16872
2020-09-06 02:36:57 +00:00
JJ Kasper
6233ef7ed8
Correct client rewrite resolving with query (#16860)
This makes sure we only pass the as value's `pathname` instead of the full value so that we don't accidentally include `query` values while resolving the rewrites. This also adds tests to ensure the rewrites are resolved with the correct query values when only providing `href` and when manually mapping them with `href` and `as`

Fixes: https://github.com/vercel/next.js/issues/16825
2020-09-04 19:19:17 +00:00
JJ Kasper
d97237a292
Fix invalid config export errors (#16834)
This corrects detecting of invalid page config exports and adds additional test cases for non-invalid config import/exports

Closes: https://github.com/vercel/next.js/issues/16775
2020-09-04 13:19:12 +00:00
Zack Tanner
08859275ae
Add tests for searchParams dev warning (#16798)
Fixes a warning being logged to the console when using `href` with a dynamic path. Fixes #16794
2020-09-03 18:47:45 +00:00
JJ Kasper
8426f13713
Update to show build indicator while re-fetching GS(S)P data in dev (#16789)
This is a follow-up to https://github.com/vercel/next.js/pull/16744 which shows the build/activity indicator while the data is being re-fetched to let the user know the re-fetching is occurring 

Closes: https://github.com/vercel/next.js/issues/16790
2020-09-03 12:27:08 +00:00
JJ Kasper
4685332353
Add automatic reloading when editing GS(S)P methods (#16744)
This adds initial support for reloading the page when `getStaticProps`, `getStaticPaths`, or `getServerSideProps` were changed for a page by triggering a reload when the server output for a page has changed but the client output has not since these methods aren't included in the client output. 

Closes: https://github.com/vercel/next.js/issues/13949
2020-09-02 16:57:21 +00:00
JJ Kasper
f8d92a67f0
Ensure interpolating dynamic href values works correctly (#16774)
This corrects/makes sure interpolating dynamic route values for `href` works correctly. This provides an alternative approach to building the `href` value with `next/link` so that you don't need to worry about encoding the params manually. 

Closes: https://github.com/vercel/next.js/issues/13473
Closes: https://github.com/vercel/next.js/issues/14959
Closes: https://github.com/vercel/next.js/issues/16771
2020-09-02 16:23:26 +00:00
Alex Castle
6874adbbb9
Make the image post-processor ignore SVG images (#16732)
This is a small change to the image post-processor logic. When it's looking for images to preload, it will now ignore SVGs, as these are rarely the relevant images for LCP.
2020-09-02 02:42:20 +00:00
Joe Haddad
1c45f70952
[test] Update hydration marker for React 17 (#16756) 2020-09-01 17:43:44 +00:00
Joe Haddad
f921b4f476
Auto enable React's new JSX transform on 17.x (#16603) 2020-09-01 11:29:25 -04:00
Jan Potoms
20a4928b16
remove unneeded error (#16636)
This is not needed anymore since absolute urls are supported.
Also added an extra test for `mailto:` urls
2020-08-28 02:49:40 +00:00
Joe Haddad
6895f9b0f4
Replace <link rel=stylesheet> client-side transitions with <style> tags (#16581)
This pull request replaces our client-side style transitions with `<style>` tags over async `<link rel=stylesheet>` tags. This should fix some edge cases users see with Chrome accidentally causing a FOUC.

This also removes the need to perform an async operation before starting the render, which should remove any perceivable navigation delay.

---

Fixes #16289
2020-08-26 16:34:53 +00:00
JJ Kasper
990c1792d2
Add tests for preview mode caching (#16579)
This adds tests to ensure preview mode pages aren't cached and made publicly available or written to the disk. 

Closes: https://github.com/vercel/next.js/issues/16020
2020-08-26 11:07:32 +00:00
Joe Haddad
52efe3364f
Reuse existing <link rel=stylesheet> on nav (#16537)
This pull request reuses existing `<link rel=stylesheet>` tags if their `href` matches instead of recreating it. This is in effort to fix an edge case where the browser will FOUC on the tag swap.

This behavior should be sufficiently covered by all the existing CSS cases, as misbehavior would result in the resulting CSS styles being incorrect.
2020-08-25 15:03:14 +00:00
Joe Haddad
34f737c47b
Increase font test timeout for Windows (#16527) 2020-08-25 10:41:34 -04:00
khades
1a7f3e5199
Store css file dependencies info for dynamic imports and apply it at SSR (#12843)
To prevent FOUC, discussed in #10557 i need to store information about css file dependencies for chunk. Right now current implementation just throws away everything but js.

Can there be more than one css file in chunk? If no - code will be simplified.

closes #10557
2020-08-24 05:20:11 +00:00
JJ Kasper
a7550bf1d7
Add error when document component isn't rendered (#16459)
If a custom `_document` is added but not all of the expected document components are rendered it can cause unintended errors as noticed in https://github.com/vercel/next.js/issues/10219 so this adds detecting when one of the expected document components isn't rendered and shows an error. 

Closes: https://github.com/vercel/next.js/issues/10219
2020-08-24 02:42:51 +00:00
JJ Kasper
4e0b40145d
Correct initial fallback route param values (#16485)
This fixes invalid initial route params in development mode and serverless production mode. It also adds tests to ensure these values are correct in development, production, and serverless mode.

x-ref: https://github.com/vercel/next.js/pull/16084
Fixes: https://github.com/vercel/next.js/issues/16481
Fixes: https://github.com/vercel/next.js/issues/16482
2020-08-23 12:35:30 +00:00
JJ Kasper
32ee65efa1
Correct shallow routing behavior through history (#16477)
When navigating from a non-shallow page to a page that was navigated to shallowly in history it causes incorrect page data to be shown since an incorrect shallow navigation is done. We can only maintain shallow routing when the current page was navigated to shallowly and the page being navigated to in history was also navigated to shallowly. Additional tests to ensure this behavior is working has also been added. 

Closes: https://github.com/vercel/next.js/issues/7395
Closes: https://github.com/vercel/next.js/issues/14928
Fixes: https://github.com/vercel/next.js/issues/16028
2020-08-22 21:51:14 +00:00
Joe Haddad
9acd001e09
Fix render cancel behavior (#16462)
This pull request correctly tracks render cancelation behavior. Prior to this PR, we'd have an unhandled rejection that left the app in a bad state and no routeChangeError event was fired.

---

Closes #16424
Fixes #16445
2020-08-22 11:47:21 +00:00
JJ Kasper
8a1c9937b6
Make sure to break rewrites chain when dynamic route matches (#16455)
This makes sure to also check if a dynamic route matched after resolving a rewrite on the client to match behavior on the server. It also adds tests for this behavior to ensure it is working properly. 

Fixes: https://github.com/vercel/next.js/issues/16454
2020-08-22 05:15:45 +00:00
JJ Kasper
78ef13914a
Fix un-transpiled client file with rewrites (#16453)
This fixes a client-side file not being transpiled correctly when rewrites are used. The cross browser tests have been updated to make sure there are rewrites so the related code is included and not dead-code eliminated'

Closes: https://github.com/vercel/next.js/issues/16440
2020-08-21 19:11:25 +00:00
Joe Haddad
7c7ecaa636
Do not alias Node modules for webpack 4 (#16452)
Fixes #16259
Caused by #16022
Follow up issue: #16450

This PR skips polyfilling Node modules in webpack 4 which are ignored by the `browsers` key.
2020-08-21 18:50:24 +00:00
JJ Kasper
450742274a
Fix optional catch-all /index revalidate params (#16451)
This corrects the case where `/index` is used during revalidation for an optional catch-all route and `index` is passed as a param even though it should be undefined. This also adds test cases to make sure the params are normalized correctly

Fixes: https://github.com/vercel/next.js/issues/16366
2020-08-21 18:13:24 +00:00
Janicklas Ralph
b1ea19a563
Eslint preload (#16199)
Eslint rule checks for missing preloads for stylesheets.

cc: @prateekbh
2020-08-20 19:34:12 +00:00
Prateek Bhatnagar
6c9dd6c3d4
AMP compatibility for Font optimization (#16208)
- Upgrades cssnano to 1.2.0
- Only removes whitespaces from downloaded font declarations
- Disables Font optimization for AMP pages
2020-08-20 15:10:59 -04:00
Joe Haddad
ec7009620a
Ensure unknown static paths 404 for data request (#16401)
We were accidentally allowing data requests to be rendered unconditionally. Instead, we should also check them against the staticPaths result and 404 when appropriate.

---

Fixes #15383
2020-08-20 17:59:03 +00:00
Joe Haddad
fc98c13a2e
Warn on duplicate Sass deps (#16398)
Fixes #13953
2020-08-20 16:05:29 +00:00
JJ Kasper
3dec50001e
Add debug flag for extra build output (#16399)
This adds a `-d` or `--debug` flag which enables outputting additional build output information like the rewrites, redirects, and headers

Fixes #15281
2020-08-20 15:43:38 +00:00
JJ Kasper
e1e6cfa189
Fix page checking failing with trailingSlash (#16362)
This fixes page checking failing due to the trailing slash being present which causes pages to proxied by a rewrite when they shouldn't be. This also adds additional tests to ensure rewriting to an external resource is working correctly with `trailingSlash: true`

Fixes: https://github.com/vercel/next.js/issues/15700
2020-08-20 04:05:38 +00:00
JJ Kasper
681fbbd04d
Fix basePath and public folder check ending routes early (#16356)
This corrects the basePath being required check for filesystem routes to not consider the public folder catch-all route since it always matches even if the public file isn't present and instead moves the basePath check inside of the public-folder catch-all. Tests already exist that catch this by adding a public folder to the existing `basepath` test suite

Fixes: https://github.com/vercel/next.js/issues/16332
Closes: https://github.com/vercel/next.js/pull/16350
2020-08-19 17:30:33 +00:00
matamatanot
0226e7872a
CNA: Add warning about permission (#14889)
close #14744

<img width="851" alt="screen_shot" src="https://user-images.githubusercontent.com/39780486/86603491-06bec800-bfdf-11ea-9928-ee85cbad86a7.png">


I have some concerns.

- `import { isWriteable } from '../next/build/is-writeable'` **not** from `create-next-app ` package.
- The warning sentence is from npm. Not for Next.js. I'm not a native English speaker. I'd like to know the natural expression for this.
2020-08-19 17:09:34 +00:00
JJ Kasper
67482914c6
Normalize request URL/asPath for fallback SSG pages (#16352)
This interpolates the dynamic values and rebuilds the request URL for fallback SSG pages since the proxy uses the output path for non-prerendered pages on Vercel which can cause inconsistent request URL/`asPath` values for SSG pages. This also adds tests to ensure the `asPath` is correctly updated

Fixes: https://github.com/vercel/next.js/issues/16269
2020-08-19 15:23:02 +00:00
Joe Haddad
0a72d14deb
Make loadPage track success of script loading (#16334)
Prior to this PR, `loadPage` would call `loadScript` which would then report if the script failed to load.

This was problematic because `loadScript` notified a failure to load via `pageRegisterEvents`, which would not set the `pageCache` value for future requests.
This means a one-off promise rejection would happen, [in lieu of being] typically consumed within the client-side router, causing a server-side reload.

However, when `loadPage` was used independently (i.e. to preload pages), this promise rejection would be ignored as a preload failure.
When the real routing request comes in, the `loadPage` function skips its attempt to load the `<script>` because it was already in the DOM, and the router would stop functioning.

---

To fix this behavior, I've removed erroneous emits on `pageRegisterEvents` to only happen during the page registration lifecycle (its intended use).

The new behavior is that `loadScript` returns a `Promise` that `loadPage` can track, and if any of the page(s) scripts fail to load, we mark the entire page as errored in `pageCache`. This ensures future requests to `loadPage` will always immediately reject with a `PAGE_LOAD_ERROR`, which causes the server-side redirect at the appropriate point.

---

Fixes #16333
2020-08-19 11:41:01 +00:00
Joe Haddad
9746043354
Fix IE11 CSS Compatibility (#16336) 2020-08-19 02:34:44 -04:00
Alex Castle
7198cbe093
Add at attribute to image preload link (#16328)
Fixes a small error in the image preload post-processor. Adds a needed 'as' attribute to the link.
2020-08-18 21:14:42 +00:00
Joe Haddad
5f9755002d
Force browser to recompute layout on page nav (#16318)
This fixes an edge case where every dozen or so transitions you'll see a flash depending on what's happening on the main thread at the time.

I'm not sure it's possible to test for this case, so we'll just have to do more field testing with this.
2020-08-18 18:15:51 +00:00
Joe Haddad
ff33e07afe
Replace broken prop-types-exact package (#15953)
This PR replaces `prop-types-exact` (only used in this location) with manual property checking.

Right now, malformed properties sent to `<Link>` are silently handled and only emit a warning in the console.
This leads to confusing/unexpected errors because we try to read a value that is undefined.

To fix this, we'll now throw a proper error when `<Link>` is misused. **This still isn't optimal, however, because we don't have a component stack trace we can give the user**.
We're not going to be able to give the user actionable instructions until React 16.14 at a minimum.

---

Fixes #13951
Fixes #16107
Closes #13962
2020-08-18 16:36:40 +00:00
Joe Haddad
1318a8d98a
Fix module not found test 2020-08-18 11:30:37 -04:00
James Mosier
29ae372738
Allow React experimental version without warning (#16140)
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-08-18 01:54:31 -04:00
Joe Haddad
bb8374126f
Test basic css module prefetching without compose (#16134) 2020-08-18 01:12:34 -04:00
Joe Haddad
06d8acdfd0
Update stylesheets on page navigation (#16126)
This pull request adds a test case for the reproduction provided in #12445. This bug is specifically caused when loading the next page before navigation has actually occurred.

---

Fixes #12445
2020-08-17 21:20:05 +00:00
Kevin Mårtensson
aa4b87e357
Handle cases where config is exported after its declaration (#16211)
AMP will still not work correctly when switching between non-AMP and AMP pages in development mode because of https://github.com/vercel/next.js/blob/canary/packages/next/build/babel/plugins/next-page-config.ts#L116-L120.

Fixes #15704.
2020-08-17 17:24:18 +00:00
JJ Kasper
f8534a6e62
Fix data URL with root-catchall and basePath (#16263)
This fixes the incorrect `/_next/data` URL being generated on client transition due to the `as` value passed to `getRouteInfo` having the `basePath` which is used while interpolating the values for dynamic routes, specifically root catch-all routes. A regression test has also been added to ensure this is working

Closes: https://github.com/vercel/next.js/issues/15747
2020-08-17 15:25:36 +00:00
Sergey Rubanov
feeb941dc6
Update to Terser 5 (#16194)
Co-authored-by: Tim Neutkens <timneutkens@me.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-08-16 19:32:37 +02:00
JJ Kasper
1b4d463cc8
Update rewrite params query appending (#16189)
This updates to not automatically append params to the query for rewrites if one or more of the params are already used in the destination's path. No other behavior is being changed and if the user still wants the params in the query after using them in the destination's path they can manually add them like with redirects.

Closes: https://github.com/vercel/next.js/issues/15626
2020-08-14 18:51:58 +00:00
JJ Kasper
39e00a3f2f
Add test case for preloading buildManifest (#16183) 2020-08-13 23:04:27 -05: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
6d71eef518
Do not assign to readonly property in Safari (#16051) 2020-08-10 13:15:37 -04:00
Joe Haddad
e08b633c3a
Do not bundle caniuse-lite (#16048) 2020-08-10 11:27:21 -04: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
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
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
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
Jan Potoms
17716d1499
Add tests for querystring-relative urls (#15911) 2020-08-05 14:23:08 -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
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
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
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
0ef710844f
Test that overlay appears (#15850) 2020-08-04 00:37:51 -04:00
Joe Haddad
48ca2f2cc5
Fix CSS grid-column shorthand syntax (#15848) 2020-08-04 00:08:09 -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
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
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
Jan Potoms
d97d045dfc
Stabilize another test (#15697)
Saw this one fail on azure
2020-07-31 03:22:32 +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
cac35c389a
Fix hot reloader edge case with broken webpack plugins (#15659) 2020-07-29 23:44:25 -04:00
Joe Haddad
8f914a3bcb
Fix error overlay hotlinking (#15658)
This pull request:

1. Relocates tests to correct location
1. Tests more scenarios
1. Fixes a bug with anchors at the start of error message
1. Fixes react key warning error

Fixes #15599
2020-07-30 00:58:36 +00:00
Darsh Patel
c1e5b66cd7
Fix: space issue in error overlay and add tests (#15617) 2020-07-29 19:30: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
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
Jan Potoms
3ffef60280
Fix webdriver error handling (#15491)
errors in script execution will result in timeout instead of failure. This PR makes sure to pass all arguments to `.then` so error handling is correctly set up. (`.then` needs to be able to take a second argument). I also removed `.finally`.

I don't know why, but it looks like the following test does something that prevents the tests after it from opening a new browser window on azure. I'm giving up, I shuffled the tests to put this one last.
```js
    it('shows warning when dynamic route mismatch is used on Link', async () => {
      await showsError(
        '/dynamic-route-mismatch',
        /Mismatching `as` and `href` failed to manually provide the params: post in the `href`'s `query`/,
        true,
        true
      )
    })
```
2020-07-29 10:30:06 +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
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
JJ Kasper
3960783983
Stabilize error-is-clickable test (#15606)
This attempts to stabilize the `error-is-clickable` test since it has been flaking recently

Closes: https://github.com/vercel/next.js/issues/15585
2020-07-29 06:38:13 +00:00
JJ Kasper
059741ea00
Update stats-config for new polyfills location (#15584)
This makes sure to not group the polyfills chunk in with the client bundles group now that it is output under chunks instead of runtime
2020-07-28 15:58:13 +00:00
Darsh Patel
23eb267499
Make Links rendered in the error overlay clickable [ 14017 ] (#14055)
Co-authored-by: TodorTotev <51530311+TodorTotev@users.noreply.github.com>
2020-07-28 13:22:28 +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
Joe Haddad
e837c2253d
Upgrade cssnano-simple dependency (#15488) 2020-07-26 23:56:36 -04:00
Jan Potoms
2f50f1f8c9
Stabilize more tests (#15470)
jest retries seem to be masking test failures, like the `auto-export` one (and maybe others). I turned it off for now. The `auto-export` test fails when retries are turned off.
the output of this test failure was a bit unhelpful so I also improved it.
Many tests have anonymous page functions.
2020-07-26 04:57:06 +00: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
Jan Potoms
e6e2722b11
Tweak test retries for invalid-href suite (#15459)
- Reduce jest retries to 2 for a total of 3 attempts
- Disable retries in `invalid-href` test. I noticed jest retries don't help when this test fails (see log output of https://github.com/vercel/next.js/runs/904147534).
2020-07-24 20:04:53 +00:00
Jan Potoms
fcfbceaa7e
Fix cancellation control flow (#15361) 2020-07-21 13:33:11 -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
a11d99390a
Stabilize Trailing Slash API (#15331)
Closes #15330
2020-07-20 16:16:59 +00: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
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
Jan Potoms
548ca82041
Verify that dataroutes work correctly with assetPrefix (#15309)
Fixes https://github.com/vercel/next.js/issues/12046
Fixes https://github.com/vercel/next.js/issues/11992
Closes https://github.com/vercel/next.js/pull/13456
2020-07-19 20:02:27 +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
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
Prateek Bhatnagar
4422be3276
Only required polyfill.io lint rule (#15277)
- Introduces a lint rule which points towards the unwanted polyfill.io features.
- Aim here is to make the user aware that which of the requested features are actually required vs which are already covered under `next-polyfills`

Next step: If the remaining required polyfills amounts to a only a few KBs then its better to include them in 1P javascript and remove the third party render blocking script tag.
2020-07-18 23:54:38 +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
a33bb5bec5
Fix app-document-import-order test for webpack 5 (#15224) 2020-07-17 10:38:06 +02:00
Jan Potoms
e56a6add8d
Add test for query param bug #15233 (#15238)
Fixes https://github.com/vercel/next.js/issues/15233
2020-07-16 22:47:46 +00:00
Joe Haddad
9d94d70d1f
Use core-js for URL(SearchParams) Polyfill (#15209)
This replaces the `url-polyfill` package with the `core-js` version which handles more edge cases in legacy browsers.

Closes #11702
Fixes #15194
2020-07-16 14:36:48 +00: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
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
Joe Haddad
a131909857
Fix Web Workers with Fast Refresh (#15145) 2020-07-14 12:17:10 -04:00
Jan Potoms
b12389598b
Stabilize azure test (#14999)
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-07-14 00:25:07 -04:00
Darsh Patel
fcd03091b4
Fix: Invalid flag provided to next build results in UnhandledPromiseRejectionWarning (#15049) 2020-07-13 23:07:35 +02: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
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
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
Joe Haddad
03d4d14c99
Check for file name in anon export warning (#15061)
Fixes #14888
2020-07-12 15:33:39 +00: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
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
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
Darsh Patel
61e899f42b
Fix bug in profiling test (#14921) 2020-07-08 13:40:40 +02: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
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
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
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
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
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
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
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
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
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
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
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
ae542b8525
Use entry option instead of custom make hook (#14527)
Simplifies on-demand-entries a bit.
2020-06-26 04:26:09 +00: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
Jan Potoms
1a838f45aa
Fix windows tests: snapshot backslash needs to be escaped (#14559)
Noticed while trying to get https://github.com/vercel/next.js/pull/14442 tests to pass. The backslash needs to be double escaped in snapshots. Forward slashes aren't escaped, maybe that was the assumption when this test was written?
2020-06-25 17:00:48 +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
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
JJ Kasper
2136c46b89
Ensure dev overlay uses basePath for requests (#14475)
This fixes the `basePath` not being used when making requests for the `react-dev-overlay`. We might want to pass down the `basePath` to the overlay instead of relying on the `process.env` injection although may be fine this way, will defer to @Timer for preferred way to pass this value to the dev-overlay

Closes: https://github.com/vercel/next.js/issues/14470
2020-06-23 15:11:12 +00: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
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
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
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
Ty Mick
4e5e3b9072
Fix typo in test names: "treversing" → "traversing" (#14347)
Just a quick typo fix for some test names.
2020-06-19 01:05:09 +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
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
Prateek Bhatnagar
6ff72006c8
bug fixes for css eslint rule (#14202)
- ignores the link tags which do not have literal href
e.g. `<link rel="stylesheet" href={props.href} />`
2020-06-15 23:42:36 +00:00
JJ Kasper
0a02efbfcc
Add test for title and routeChangeComplete (#14132)
This adds a test case for the `document.title` not being updated by the time `routeChangeComplete` is fired. This should have been made consistent with https://github.com/vercel/next.js/pull/13287 so should be able to be closed now

Closes: https://github.com/vercel/next.js/issues/6025
2020-06-12 16:26:10 +00:00
Tim Neutkens
89fffa694d
Remove Head.rewind as it's no longer needed (#14091)
Fixes #9326
2020-06-11 22:09:06 +00:00
Joe Haddad
8ae10601b1
Simplify test checks (#14094)
Fixes #14093
2020-06-11 19:02:53 +00:00
Joe Haddad
ec7c3252c3
tests: fail when cannot replace content (#14087)
Fixes #14085
2020-06-11 18:29:38 +00:00
JJ Kasper
1c057e7792
Add test case for loading 404 on invalid bundle (#14082)
This adds a test case to ensure hard navigating when a client bundle fails to load is occurring correctly

x-ref: https://github.com/vercel/next.js/issues/13516
2020-06-11 16:59:25 +00: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
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
80036fd9dd
Fix Fast Refresh with Page Config (#14041)
Fixes #13978
2020-06-10 19:56:05 +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
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
James Mosier
d51fef5fc9
chore(create-next-app): remove example picker (#13977)
If a user does not specify `--example` when using create-next-app then just spin up the default template and only prompt them for the name of their project.

if a user does specify `--example` (with no string after it) then show them the example picker. 

Closes #13960
2020-06-10 03:14:24 +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
JJ Kasper
b1025995b2
Update to reject when test command fails (#13722)
As noticed in https://github.com/vercel/next.js/pull/13506 when a build or export command fails the tests can just stall. This attempts to address that by rejecting when the command doesn't exit correctly and `stdout` and `stderr` aren't being looked at
2020-06-09 18:28:15 +00:00