Skip to content

Commit

Permalink
nion fetches on contruction of a component, which causes requets to h…
Browse files Browse the repository at this point in the history
…appen during SSR
  • Loading branch information
jbyttow committed Feb 23, 2019
1 parent 250894f commit 5d58f56
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 46 deletions.
78 changes: 39 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions src/decorator/index.js
Expand Up @@ -371,7 +371,7 @@ const nion = (declarations = {}, ...rest) => WrappedComponent => {
this.initializeDataKeys(nextProps)
}

initializeDataKeys(props) {
fetchOnMount(props) {
const { nion } = props // eslint-disable-line no-shadow

// We want to trigger a fetch when the props change and lead to the creation of a new
Expand Down Expand Up @@ -411,8 +411,8 @@ const nion = (declarations = {}, ...rest) => WrappedComponent => {
})
}

componentDidMount() {
const { nion } = this.props // eslint-disable-line no-shadow
initializeDataKeys(props) {
const { nion } = props // eslint-disable-line no-shadow

// Iterate over the declarations provided to the component, deciding how to manage the
// load state of each one
Expand All @@ -435,6 +435,10 @@ const nion = (declarations = {}, ...rest) => WrappedComponent => {
})
}

componentDidMount() {
this.fetchOnMount(this.props)
}

render() {
// Filter out internally used props to not expose them in the wrapped component
const nextProps = {
Expand Down
4 changes: 0 additions & 4 deletions test/integration.test.js
Expand Up @@ -170,10 +170,6 @@ describe('nion : integration tests', () => {
.find('Container')
.props().nion.test

let test = getProp()
expect(test.request.status).toEqual('pending')
expect(test.request.isLoading).toEqual(true)

await P.delay(15) // Wait 15ms for the request reducer to update

test = getProp()
Expand Down

0 comments on commit 5d58f56

Please sign in to comment.