* Implement circular JSON err.sh link
* Add test for getInitialProps returning circular json
* Make test warn less
* Fix tests
* Add reference to original tests
original code in `/lib/router/router.js`
```
urlIsNew (pathname, query) {
return this.pathname !== pathname || !shallowEquals(query, this.query)
}
```
the urlIsNew compare `this.pathname` to an argument `pathname`
the invokers:
```
// If asked to change the current URL we should reload the current page
// (not location.reload() but reload getInitialProps and other Next.js stuffs)
// We also need to set the method = replaceState always
// as this should not go into the history (That's how browsers work)
if (!this.urlIsNew(asPathname, asQuery)) {
method = 'replaceState'
}
```
the parameter here is `asPathname` destructured from `asPath`
so here is a problem when we reuse a single page rendered in two asPaths
pages/a.js
```
<>
<Link href='/a'><a>goto a</a></Link>
<Link href='/a' as='/b'><a>goto b</a></Link>
</>
```
If we navigate to page /a, then click 'goto b', actually the history is replaced, not pushed.
It is expected that history could be correctly pushed and popped as long as the browser url is changed.
Resolves#4055
Credit: https://github.com/zeit/next.js/pull/5095
I didn't use the ignore webpack plugin from the original PR and tested bundle size with https://github.com/zeit/next.js/pull/5339 - seems to be safe on that front.
Was able to get tests to pass locally, unsure of what goes wrong in CI 🤷♂️
**Questions**
1) The initial PR didn't include changes to `next-server/lib/router` in `getRouteInfo()`. Should the same changes be made within?
2) Should we add a test for rendering a component created via `forwardRef()`?
`component-with-forwardedRef`:
```javascript
export default React.forwardRef((props, ref) => <span {...props} forwardedRef={ref}>This is a component with a forwarded ref</span>);
```
some test:
```javascript
test('renders from forwardRef', async () => {
const $ = await get$('/component-with-forwardedRef')
const span = $('span')
expect(span.text()).toMatch(/This is a component with a forwarded ref/)
})
```
Fixes#3705Fixes#4656
- No longer automatically dedupe certain tags. Only the ones we know are *never* going to be duplicate like charSet, title etc.
- Fix `key=""` behavior, making sure that if a unique key is provided tags are deduped based on that.
For example:
```jsx
<meta property='fb:pages' content='one'>
<meta property='fb:pages' content='two'>
```
Would currently cause
```jsx
<meta property='fb:pages' content='two'>
```
### After this change:
```jsx
<meta property='fb:pages' content='one'>
<meta property='fb:pages' content='two'>
```
Then if you use next/head multiple times / want to be able to override:
```jsx
<meta property='fb:pages' content='one' key="not-unique-key">
<meta property='fb:pages' content='two' key="not-unique-key">
```
Would cause:
```jsx
<meta property='fb:pages' content='two'>
```
As `key` gets deduped correctly after this PR, similar to how React itself works.
**What's this PR?**
Based on the feedback on [this PR](https://github.com/zeit/next.js/pull/5722) @timneutkens asked me to create a test for `ssr: true`
**What's it do?**
- adds a test for setting `ssr: true` - /basic
- adds a test for setting `ssr: true` - /production
* Add failing tests
* Upgrade wd module
* Pass dynamic import webpack ids to the client side
* Pass through webpack ids to initalializer and only use those
* Compile dynamic(import()) to dynamic(() => import())
* Default dynamicIds
* Use forked hard-source-plugin
* Possibly fix test
* Make tests fail less intermittently
* Temporarily disable hard-source in production
* Make sure dynamic import chunks are unique
* Disable hard-source
* Log html if error is thrown
* Fix test
Since we are now using webpacks `mode` flag we can get rid of:
* `webpack.optimize.ModuleConcatenationPlugin`
* `webpack.DefinePlugin` (`process.env.NODE_ENV`)
https://webpack.js.org/concepts/mode/
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.
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
~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
`<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.
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.
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.
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']
```
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
* 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
* Handle production errors correctly
* Improved source map support
* Make react-hot-loader hold state again
* Remove console.log
* Load modules on demand
* Catch errors in rewriteErrorTrace
* Update comment
* Update comment
* Remove source-map-support
* Load modules in next-dev
* Make sure error logged has sourcemaps too
* Add tests for production runtime errors
* Add tests for development runtime errors. Fix issue with client side errors in development
* Move functionality back to renderError now that error handling is consistent
* Rename to applySourcemaps
* Add specific test cases for Error Recovery.
* Update hmr/about.js
* Add a test case: should recover after a bad return from the render function
* Add test case: should recover from errors in getInitialProps in client
* Add test case: should recover after an error reported via SSR
* Add a test case: should recover from 404 after a page has been added
* Refactor code base.
* Fix SSR error handling.
* Remove unwanted console.logs
* Fix a typo.
* Fix current tests.
* Add a new test case for this case.
* Error should only be logged if it is not a 404
* Add custom-server-typescript example (see #3694)
* Fix linting errors in custom-server-typescript
* Provide proper arguments to ts-node.
* Fix import and fix all linting errors.
* Use import in server as well.
* Update nodemon.json
* Allow next/asset to work properly with dynamic assetPrefix
Now we use webpack's publicPath via client side.
* Add test cases for dynamic assetPrefix and next/asset.
* Add .jsx extension
* examples: add create-next-app (#3377)
* examples: add create-next-app
* fix with-typescript readme
* Upgrading with-flow example to the latest flow-bin ver. 0.59.0 (#3337)
For upgrading I used flow-upgrade module by https://yarnpkg.com/en/package/flow-upgrade
* doc'd fs-routing option & added note on `passHref` (#3384)
2 changes:
`passHref` - just added a cautionary note on the importance of `passHref`. We had a few days of no-href links on our site b/c we used a custom component instead of a raw `<a>` tag, and Google bot wasn't crawling our links (confirmed in Google cache). Hurt our SEO a bit, so I thought it was worth noting.
`useFileSystemPublicRoutes` - this is mentioned in https://github.com/zeit/next.js/pull/914 , but it doesn't appear any doc was actually added. We use `next-routes`, and we were serving all the files in `/pages/` in addition to their route patterns (ie duplicate content), which can be a pain w/ SEO and duplicate content.
* fix typo in readme.md (#3385)
* Upgrade styled-jsx to v2.2.1 (#3358)
* Pulled encoding to top of head (#3214)
* Remove next.d.ts to use @types/next (#3297)
* Add with-mobx-state-tree example (#3179)
* Adapt with-mobx example for with-mobx-state-tree
* Remove unnecessary lastUpdate parameter to show off snapshot
* update readme
* make other.js more closely mimic index.js
* Upgrade styled-jsx to v2.2.1
Includes some bug fixes.
* Fix linting
* Make sure import that doesn’t end in .jsx works
* Move tests
* Show error when .js and .jsx both exist
* Remove .jsx when importing from ‘path.jsx’
* Fixes
* Get .jsx resolver back
* Revert "Get .jsx resolver back"
This reverts commit 6f76712caa400e6f41a6a32ff80189a95b194cce.
* Revert "Revert "Get .jsx resolver back""
This reverts commit 69e592e86e53f28d0e1f78009196b76f2f831866.
* Add remove .jsx to preset
* Remove jsx resolver
* Revert "Remove jsx resolver"
This reverts commit 5e3ef1aca134de47657d91485809cd801e13329f.
* Revert "Revert "Remove jsx resolver""
This reverts commit 8248e5066cff1c7e33dac2e5a88ffe6856e3fc4e.
* Revert "Revert "Revert "Remove jsx resolver"""
This reverts commit 2a6d418a227ea4e59874b0374628ef497e527c52.
* Make 1 component not use .jsx
* Support de-deduping head tags by setting key
* move dedupe logic to `unique` function
* fix head tag deduping logic
* remove console.log
* use `toContain` assertions
* update de-duping head tags section in README
* Add withRoute HOC
Rebased (squashed)
- removed routerToProps
- updated hoist-non-react-statics
- improved propTypes
* Expose the whole Router instead of the route.
* Make the example simple.
* Update examples and the readme.
* Add a test case.