-
Notifications
You must be signed in to change notification settings - Fork 61
duplicate call all component under container, at twice access view usin react-route in client #51
Comments
I'll explain better. |
Hi @kasselTrankos could you create a minimal repo/gist to reproduce the bug? |
yes i got one |
hi @RickWong , could you see what im say?.tks |
👍 I'm not sure if it's the intended behavior, all transmit containers that have promise fragments are executed twice. Once on componentWillMount and again on componentDidMount. For example if I'm switching between two URI paths that have separate react component (transmit container) handlers. If each of those component have fragments that will fetch for data, they will be fetching twice each time they're rendered. Some of the fetch queries could be heavy and it's being called twice each time the component is mounted. Perhaps I'm not using react-transmit as intended? |
@broveloper that is, the fetch is called twice. I dont understand why?, as you told me if the fetch is heavy?. |
Is it because of React Router perhaps? I cannot reproduce the behavior using the example in this repository. |
Hi @RickWong, it behind src/lib/createContainer.js you call twice, and that is good from server. but in client do twice.
say false in both methods, |
The results are not related to react-router. In the example below, the component will getAllFragments twice. Example: import React from 'react';
import ReactDOM from 'react-dom';
import Transmit from 'react-transmit';
class Item extends React.Component {}
const TransmitItem = Transmit.createContainer(Item, {
fragments: {
item (variables) {
return () => Promise.resolve(variables);
}
}
});
class App extends React.Component {
render () {
return <div/>;
}
}
const TransmitApp = Transmit.createContainer(App, {
initialVariables: {},
fragments: {
items () {
console.log('I am called twice.');
return Promise.all([
TransmitItem.getFragment('item', {item: 1}),
TransmitItem.getFragment('item', {item: 2}),
TransmitItem.getFragment('item', {item: 3}),
]);
},
}
});
ReactDOM.render(<TransmitApp />, document.getElementById('body')); |
yes, i tell the cause to call twice is because the router, but that not implies that is provocated by router, in the base code there is only one page access, so there is no way to saw the call twice. |
Thanks for providing the reconstructed example. I identified the problem. If the promises resolve too quickly, then this happens. I'm coding a solution now. |
hey at last, yes that's. React work more quicly than the promises. So this is running twice. |
@RickWong You rock bro! 👍 💯 |
Hi,
Im using react router, and call all twice when access to page twice or more
call render, fetch all twice.
The text was updated successfully, but these errors were encountered: