-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UI demo type components: workspace view and itemscontainer (#32)
* Adding PageView to test the changes in client * Refactoring more of the components with using pageviews * 1.2.0 * Updating docs and react dependencies. Still need to update package.json to have the dev dependency of react-router and when running the storybook, we need to run in dev mode * 1.2.1 * Adding more configuration to the webpack config * 1.2.2 * Fixing the dundling and removing the react dom stuff * 1.2.3 * Changing the behaviour of List * 1.2.4 * New workspace view * Adding page view tabular vs split workspace * change labelling of stories for demo components
- Loading branch information
Showing
27 changed files
with
2,745 additions
and
1,173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
docs/guides/error-invariant-multiple-react-router-dom-09-28.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Error: Invariant failed | ||
|
||
## Context and Problem Statement | ||
|
||
Turns out that this error "Error: Invariant failed" is because how [React Router v4](https://www.sitepoint.com/react-router-v4-complete-guide/) and [React Router v5]() is different. With the new v5 there can only be one Router, because it's using the new React Context API to do some routing. See here for another [explanation](https://gist.github.com/StringEpsilon/88c7b049c891425232aaf88e7c882e05#explanation) | ||
|
||
Why we need two Routers is that Breadcrumb component has LinkContainer, which depends on React-Router-Dom. So, when the component is published, it then also bundles the React-Router dependency. When we import the Breadcrumb, since we already have a React-Router in the main DPE-client repository, it creates two Contexts in React. The routes created using a different Context cannot be found by React, and so it throws the `Invariant failed: You should not use <Route> outside a <Router>`. | ||
|
||
## Suggestions | ||
|
||
### Use the Router + Route | ||
|
||
From [this](https://github.com/marmelab/react-admin/issues/3078) this is how it was recommended, but since the Breadcrumb was nested it's not a straightforward fix. | ||
|
||
```jsx | ||
<BrowserRouter> | ||
<div> | ||
<Route path="/" component={} /> | ||
</div> | ||
</BrowserRouter> | ||
``` | ||
|
||
### Use Webpack to remove dupes in Client | ||
|
||
Was also advised to do [this](https://gist.github.com/StringEpsilon/88c7b049c891425232aaf88e7c882e05) but since our setup is CRA in DPE-client, it's quite a few hurdles to jump. If you have webpack, from the [webpack](https://webpack.js.org/guides/code-splitting/#prevent-duplication) is useful to understand to prevent dupes. | ||
|
||
### peerDependencies | ||
|
||
[Yarn](https://yarnpkg.com/lang/en/docs/dependency-types/) website says: | ||
> Peer dependencies are a special type of dependency that would only ever come up if you were publishing your own package. | ||
> Having a peer dependency means that your package needs a dependency that is the same exact dependency as the person installing your package. This is useful for packages like react that need to have a single copy of react-dom that is also used by the person installing it. | ||
This also wouldn't work due to us actively developing storybook. It doesn't prevent webpack from packaging in the react-routers. | ||
|
||
### Solution: Update Storybook webpack to remove react, react-router and react-router-dom | ||
|
||
You can prevent Webpack to bundle things that should not be duped. | ||
See package.json: | ||
|
||
```js | ||
resolve: { | ||
alias: { | ||
'react': path.resolve(__dirname, './node_modules/react'), | ||
'react-dom': path.resolve(__dirname, './node_modules/react-dom'), | ||
'react-router': path.resolve(__dirname, './node_modules/react-router'), | ||
'react-router-dom': path.resolve(__dirname, './node_modules/react-router-dom') | ||
} | ||
}, | ||
externals: { | ||
// Don't bundle react or react-dom or react-router | ||
react: { | ||
commonjs: 'react', | ||
commonjs2: 'react', | ||
amd: 'React', | ||
root: 'React' | ||
}, | ||
'react-dom': { | ||
commonjs: 'react-dom', | ||
commonjs2: 'react-dom', | ||
amd: 'ReactDOM', | ||
root: 'ReactDOM' | ||
}, | ||
'react-router': { | ||
commonjs: 'react-router', | ||
commonjs2: 'react-router', | ||
amd: 'ReactRouter', | ||
root: 'ReactRouter' | ||
}, | ||
'react-router-dom': { | ||
commonjs: 'react-router-dom', | ||
commonjs2: 'react-router-dom', | ||
amd: 'ReactRouterDOM', | ||
root: 'ReactRouterDOM' | ||
} | ||
} | ||
``` |
Oops, something went wrong.