Commit graph

196 commits

Author SHA1 Message Date
George Pantazis
56ad5121a1 Use as instead of url to determine URL newness (#4153)
Currently, using `as` will cause the router to think the URL is not changing in the case where you're re-rendering the same page with a different route. This would most likely be an issue for custom servers
which are using shallow routing.

This should be an invisible change for non-custom-server users, since `as` is defaulted to `url` if not set.

This should resolve #3065.
2018-09-03 15:26:34 +02:00
Bertrand Marron
2eeebacb4c Keep chunks filenames in production mode (#5029)
* Keep chunks filenames in production mode

* Add test for new `[name]` behavior

* Rename static/dll to static/development/dll
2018-09-03 01:40:21 +02:00
Tim Neutkens
a0aaa933de
Apply sideEffect at DidMount on the client side (#5068)
Fixes #5038

The problem with `constructor` is that it doesn't have `context` yet when being called. It's also considered unsafe to add a side-effect on constructor except when server-rendering
2018-09-02 19:18:20 +02:00
Tim Neutkens
33067a5862
Fix inconsistency in dynamic tests (#5071) 2018-09-02 17:22:29 +02:00
Kyle Holmberg
b7fe234005 404 routing for static export without exportPathMap (#5036)
Resolves #5035 

Thanks a billion to @timneutkens for holding my hand
2018-08-27 12:28:54 +02:00
Tim Neutkens
dfafad488a
Remove UNSAFE_ lifecycles from tests (#5031)
* Remove UNSAFE_componentWillMount

* Remove UNSAFE_componentWillReceiveProps from lifecycle
2018-08-25 20:09:20 +02:00
Michael Fix
9532cc1256 Remove old UNSAFE_ lifecycle methods (#5020)
~I am not sure if this is a valid fix yet, but I was going to let CI run the tests for me. I'll close and look into it if the build fails.~

Let me know if this will cause issues, but I don't think it should. The React docs recommends moving `componentWillMount` logic into the constructor
2018-08-25 17:26:11 +02:00
HaNdTriX
4c6ec18d89
Remove dublicate className from head (followup) (#5027)
* Add test of default head.

* Remove duplicate next-head (followup #5026)
2018-08-25 10:00:57 +02:00
HaNdTriX
11816537c3 Open editor from error-overlay (minor) (#4979)
This PR adds links to the [react-error-overlay](https://www.npmjs.com/package/react-error-overlay).
This allows a developer to open a stack trace in its own editor.

![codelinking](https://user-images.githubusercontent.com/1265681/44278860-a63e0a80-a24f-11e8-9c69-c5365c026c58.gif)

Closes #4813
2018-08-24 16:30:41 +02:00
Tim Neutkens
0dd2b2aa74
Add warning for broken popstate (#5000)
* Add warning for undefined url and as coming from popstate

* Use consistent url

* Fix err.sh link in test

* Rename `inital` => `initial`
2018-08-24 12:30:27 +02:00
Tim Neutkens
bd5ee26841
Scroll to name when hash is provided (#5019)
Fixes #5008 

Apparently, browser behavior is to scroll to `name="something"` too.
2018-08-23 20:20:45 +02:00
Tim Neutkens
b7e256ba01
Make onClick Link tests more consistent (#4954) 2018-08-15 12:42:56 -07:00
ǝlzlǝoq lǝᴉuɐp ツ
87f5df2454 Factor out NextScript inline source (#4934) (#4939)
This PR factors out the inline script into an own static method; fixes #4934.
2018-08-14 11:05:25 -07:00
HaNdTriX
4d8e9cacdd Improve getDisplayName util (#4944)
- [x] Add unit test
- [x] Allow to get the display name of a native component (e.g.: `div`) without throwing
- [ ] Remove displayName in production mode
2018-08-13 11:03:59 -07:00
Gary Meehan
0f4e9feafa Allow Duplicate Open Graph Image Tags (#4851)
* allow og:image duplicates

* add tests

* update tests

* fix spacing
2018-08-12 12:51:17 -07:00
Olivier Tassinari
b02fff63d0 Fix broken hash scroll logic (#4766)
`<Container>` does not receive any property. There is no way the *scrollToHash* logic can work right now. I believe it's a regression. It was working fine at some point. I'm sorry, I'm too lazy to add a test.

This fix was tested on Material-UI 👌.

This bug reproduction is the following:
As soon as you want to transition to a new page with a hash. The scroll doesn't change.
- start on pageA
- you scrollTop to 100
- you move to pageB#hash
- you stay at scrollTop 100, but #hash is at scrollTop 400.
2018-08-11 13:04:16 -07:00
HaNdTriX
d1b67623f6 Throw error if getInitialProps is defined as as instance method (#4922)
* Throw error if getInitialProps is defined as as instance method

Omitting the static keyword happens pretty often. Therefore we should trigger a warning in devmode.

Closes: #4782

* Document getInitialProps error

* Add unit tests for loadGetInitialProps
2018-08-09 10:13:44 -07:00
Tim Neutkens
f3f939dde4
Run method sorting codemod (#4909)
react-codemod recommended way of having methods defined
2018-08-06 20:53:06 -07:00
Tim Neutkens
b20b80adf0
Run rename-unsafe-lifecycles as preparation for React 17 (#4907)
https://github.com/reactjs/react-codemod#rename-unsafe-lifecycles
2018-08-06 20:23:28 -07:00
Tim Neutkens
4c602ff395
Run manual-bind-to-arrow codemod (#4906)
https://github.com/reactjs/react-codemod#manual-bind-to-arrow
2018-08-06 20:20:01 -07:00
Jacob Page
b492e6703d Make EventEmitter more Node-like (#4865)
Add behaviors to make `EventEmitter` a bit more like its NodeJS counterpart. This should make using it a bit less surprising.
2018-08-01 14:43:25 +02:00
Tim Neutkens
9240cf7855
Make .events work even when router is not initialized (#4874)
Followup of https://github.com/zeit/next.js/issues/4863#issuecomment-408920755
2018-07-31 21:04:14 +02:00
Tim Neutkens
183866a96d
Add support for rendering .css chunks (#4861)
Depends on https://github.com/zeit/next-plugins/pull/228

Failing tests are expected as `@zeit/next-css` has to be updated/released first.

This implements rendering of `.css` chunks. Effectively removing the custom document requirement when adding next-css/sass/less/stylus.
2018-07-30 15:48:02 +02:00
Tim Neutkens
6a087c6a5d
Rename commons directory to runtime (#4853) 2018-07-27 19:29:25 +02:00
Tim Neutkens
8e2c199ea7
Fix dynamic import page navigation (#4842)
Fixes #3775
2018-07-26 12:38:45 +02:00
Tim Neutkens
475b426ed1
Compile pages to .next/static directory (#4828)
* Compile pages to .next/static/<buildid>/pages/<page>

* Fix test

* Export class instead of using exports

* Use constant for static directory

* Add comment about what the middleware does
2018-07-25 13:45:42 +02:00
Tim Neutkens
75476a9136
[WIP] Webpack 4, react-error-overlay, react-loadable (#4639)
Webpack 4, react-error-overlay, react-loadable (major)
2018-07-24 11:24:40 +02:00
Albin Ekblom
992ea2e875 Allow app component to be wrapped with custom enhancer when rendering (#4762)
* Add support for custom App and Component enhancers

* Add ctx.renderPage test

* Add tests for single enhancer function

* Cleanup renderPage options check

* Cleanup

* Add comment about backwards compatibility for renderPage

* Add more test cases
2018-07-13 11:22:45 +02:00
James Reggio
1a3f950777 Respect target on <a/> tags under Link (#4763)
There are occasions where it is useful to have `target='_blank'` on hyperlinks within your own app. (For example, if your app is being loaded in an iframe and you'd like for the links to break out in to new windows.)

With this PR, the `onClick` logic in Link now checks for an external target on the nested <a/> tag, and will fall back to the default behavior if it's present, similar to the logic for shift-/cmd-clicking the link.
2018-07-12 00:03:25 +02:00
James Reggio
4cc691c0b8 Fix #4574: getInitialProps is not called on _error page for client-side errors (#4764)
## What's wrong

This problem is specific to errors that happen on the client _after_ the initial mounting of the component. (The router has special logic to handle exceptions thrown in `getInitialProps` during a client-side navigation, and I've confirmed this logic is correct.)

Specifically, if the page is mounted, and you raise an exception on the page, the exception will cause  the error page to be mounted without ever invoking `getInitialProps` on the new App/Error page pairing.

This has been illustrated with multiple repros in #4574.

## Why is it broken

This regression was introduced two months ago in #4156, where the invocation of `getInitialProps` was removed from the app's top-level error handler. Specifically, [this line](https://github.com/zeit/next.js/pull/4156/files#diff-895656aeaccff5d7c0f56a113ede9662L147) was removed and [replaced by a comment](https://github.com/zeit/next.js/pull/4156/files#diff-895656aeaccff5d7c0f56a113ede9662R167) that says that "`App` will handle the calling of `getInitialProps`".

I believe the sentiment about "`App` will handle calling `getInitialProps`" is mistaken. In fact, it really doesn't make sense on its face, since it would require an instance lifecycle method of `App` (which is mounted immediately after the comment) to invoke the `static getInitialProps` method on the error page.

## How I fixed it

I've fixed this in a fork by restoring Lines 146 – 148 that were removed in #4156. I think this is the right fix, but Next.js's handling of `getInitialProps` could certainly be improved. (The code in [this conditional](86d01706a6/client/index.js (L173)) speaks to the unnecessary complexity around this.)
2018-07-11 23:58:42 +02:00
Jacob Page
498f37e33f Support events emitter for router (#4726)
Fixes #4679 
* Document usage of `events` router property
* Expose `events` in the `router` context object
2018-07-05 14:41:18 +02:00
Tim Neutkens
57d8af857a
Make sure hashchanges get triggered (#4676)
When clicking a next/link with a hash (#something) multiple times, it wouldn't keep the scrolling behavior browsers have. This makes sure we correctly trigger it.
2018-06-28 20:56:18 +02:00
Thomas Hermann
1c817d2bbf Use nonce attribute for all scripts and preloads if provided (#4539)
When implementing a strict CSP with nonces and `strict-dynamic`, every script and preload requires a nonce.

https://csp.withgoogle.com/docs/strict-csp.html
2018-06-28 20:16:30 +02:00
Tim Neutkens
17e410a1d0
Fix Typescript HMR (#4689)
Fixes #4686

Adds tests for @zeit/next-typescript so that we don't regress on this again.

I've fixed an issue in the `next` CLI too which caused lingering processes when the process gets force killed, which is what we do in the test suite, so it kept running if there was no manual quit.
2018-06-28 20:07:41 +02:00
Luc
e98a877ee4 Merge url query with exportPathMap (#4678)
This PR fixes #4615

From the issue :
> One thing we might consider is merging and showing a warning for keys not defined in exportPathMap

The behaviour after this PR is the following :

```js
// next.config.js
module.exports = {
  exportPathMap: () => ({
    '/': { page: '/', query: { a: 'blue' } }
  })
}
```

| url called | `ctx.query` | warning ? |
|-|-|-|
| `/` | `{ a: 'blue' }` | |
| `/?a=red` | `{ a: 'blue' }` | |
| `/?b=green` | `{ a: 'blue', b: 'green' }` | `... parameter 'b' missing in exportPathMap` |

Is that the expected behaviour ? If not, I'll update the PR to shape the expected behavior.
2018-06-28 08:37:57 +02:00
Tim Neutkens
85769c3d32
Pass through buildId to webpack config in development (#4665)
Fixes #4664
2018-06-25 23:06:46 +02:00
Alexander
bf882eb60c Failing test for #4620 (#4625)
Failing test for #4620
2018-06-18 23:22:40 +02:00
Tim Neutkens
f2c2519159
Move build directory outside of server folder (#4565)
The prepares for next-server.

I also took this as an opportunity to get all build directory paths from a single location, as they were previously scattered across webpack/babel plugins and loaders.
2018-06-14 19:30:14 +02:00
Rafał Ruciński
7333dd622c Process available chunk names properly in dev mode (#4604)
Fixes #4603.

Tests explain it the best:

```js
    describe('development mode (no chunkhash)', () => {
      it('should strip the extension from the filename', () => {
        const filename = 'foo_bar_0123456789abcdef.js'
        expect(getChunkNameFromFilename(filename, true)).toBe('foo_bar_0123456789abcdef')
      })

      it('should only strip the extension even if there\'s a hyphen in the name', () => {
        const filename = 'foo-bar-0123456789abcdef.js'
        expect(getChunkNameFromFilename(filename, true)).toBe('foo-bar-0123456789abcdef')
      })
    })

    describe('production mode (with chunkhash)', () => {
      it('should strip the hash from the filename', () => {
        const filename = 'foo_bar_0123456789abcdef-0123456789abcdef.js'
        expect(getChunkNameFromFilename(filename, false)).toBe('foo_bar_0123456789abcdef')
      })

      it('should only strip the part after the last hyphen in the filename', () => {
        const filename = 'foo-bar-0123456789abcdef-0123456789abcdef.js'
        expect(getChunkNameFromFilename(filename, false)).toBe('foo-bar-0123456789abcdef')
      })
    })
```
2018-06-14 11:04:03 +02:00
Rafał Ruciński
c74ad93e14 Fix a mistake in chunk name generation (#4573)
This fixes a missed bug introduced in #4510.

Because the regexp was `/-[^-]*/` and not `/-[^-]*$/`, a wrong part of the filename was being removed:

```
bad:
'foo-bar-0123456789abcdef-0123456789abcdef.js' -> 'foo-0123456789abcdef-0123456789abcdef.js'

good:
'foo-bar-0123456789abcdef-0123456789abcdef.js' -> 'foo-bar-0123456789abcdef'
```

By a stroke of luck this didn't affect the existing dynamically generated chunks. To prevent regression I've added unit tests for the function that generates the name.

Btw. in the original issue (#4433) I used the right regexp, I just used the wrong regexp in #4510.

cc @timneutkens
2018-06-09 13:46:27 +02:00
Tim Neutkens
a7bb9175eb
Clean up references to this.dir and this.dist everywhere (#4535)
This was spread around the server. Now it's set in one place and passed around.
2018-06-04 15:45:39 +02:00
Tim Neutkens
fbaeba49b6
Add CONFIG_FILE constant, add types for server/config.js (#4529)
This was pulled from #4518, it can already be merged so it's easier to get it in.
2018-06-04 11:38:46 +02:00
Davor Santic
e153bcbb9a next/head allow duplicates if it has uniq keys (#4121)
resolves #4115

For now, I just added `'article:tag'` so it could be duplicated if we need more we have to extend:
```javascript
const ALLOWED_DUPLICATES = ['article:tag']
```
2018-06-01 13:12:33 +02:00
Tim Neutkens
098f3fd7e9
Rename dist to server to be more consistent (#4506)
Previously we called this directory holding the pages/chunks for server rendering `.next/dist` instead of `.next/server` which is confusing both when looking at it and in the codebase, since there's also `distDir` as a configuration option.

Also made this a constant in `next/constants` so functionality using this can be easily found.
2018-05-31 20:56:04 +02:00
Michał Miszczyszyn
669225263d Allow onClick on next/link component's child (#4474)
Allow `onClick` on `next/link` child. This should not be a breaking change, but it's a very useful feature. Real-life use cases include: analytics or closing menu on navigation, and other.

- [x] allow optional `onClick` on `next/link` component's child
- [x] call original `child.props.onClick(e)` before `this.linkClicked(e)`
- [x] add integration tests
- [x] cancel the navigation if `e.defaultPrevented === true`

Fixes #1490
2018-05-27 20:47:02 +02:00
Logan Smyth
2495316235 Use custom Babel loader to avoid using separate Babel copies for loader and loader options (#4417)
This resolves the

> .value is not a valid Plugin property

error showing up for people in https://github.com/zeit/next.js/issues/4227

cc @timneutkens
2018-05-23 20:26:57 +02:00
Tim Neutkens
f620b8f455
Don’t use chunkhash in development (#4436)
* Don’t use chunkhash in development

* Add test for dynamic imports styling

* Remove pre-load of dynamic page

* Make sure the browser gets closed only once
2018-05-23 14:37:02 +02:00
Sampson Oliver
35d32b48cc Create with-firebase-hosting-and-typescript example (#4443)
Adds an example based off of @jthegedus work on firebase hosting, compatible with next v6 and using typescript in both the firebase functions and the next app.
2018-05-21 10:25:45 +02:00
Jon Espen Kvisler
f2261050a0 Set cache-control public (again) (#4322)
* set cache-control public

* test for Cache-Control header

* set Cache-Control header for commons/main.js
2018-05-19 21:43:18 +02:00
Tim Neutkens
449f38daa7
Make sure props.url is immutable (#4352)
* Make sure props.url is immutable

* Add test for immutable url

* Match object instead of string
2018-05-12 20:10:17 +02:00