{"action":"opened","issue":{"url":"https://api.github.com/repos/acdlite/flummox/issues/170","labels_url":"https://api.github.com/repos/acdlite/flummox/issues/170/labels{/name}","comments_url":"https://api.github.com/repos/acdlite/flummox/issues/170/comments","events_url":"https://api.github.com/repos/acdlite/flummox/issues/170/events","html_url":"https://github.com/acdlite/flummox/issues/170","id":71980169,"number":170,"title":"Issue with server rendering and HoC","user":{"login":"dozoisch","id":4422516,"avatar_url":"https://avatars.githubusercontent.com/u/4422516?v=3","gravatar_id":"","url":"https://api.github.com/users/dozoisch","html_url":"https://github.com/dozoisch","followers_url":"https://api.github.com/users/dozoisch/followers","following_url":"https://api.github.com/users/dozoisch/following{/other_user}","gists_url":"https://api.github.com/users/dozoisch/gists{/gist_id}","starred_url":"https://api.github.com/users/dozoisch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dozoisch/subscriptions","organizations_url":"https://api.github.com/users/dozoisch/orgs","repos_url":"https://api.github.com/users/dozoisch/repos","events_url":"https://api.github.com/users/dozoisch/events{/privacy}","received_events_url":"https://api.github.com/users/dozoisch/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-04-29T20:23:25Z","updated_at":"2015-04-29T20:23:25Z","closed_at":null,"body":"Alright, I don't know if the issue is on the way I'm doing things, but I have a weird issue when using HoC on server side rendering.\r\n\r\nMy stores fetch their data automatically when asked for\r\n\r\nex:\r\n\r\n```\r\nconst ConnectedApplyToEvent = connectToStore(ApplyToEvent, {\r\n  event: store => ({\r\n    events: store.getUpcomingEvents(),\r\n  })\r\n});\r\n```\r\n\r\n`store.getUpcomingEvents()` will return the events if they are already fetched, or will create the action to fetch them.\r\n\r\nSo when rendering server-side, I just do  `renderToString` first. This create the actions needed, and once all the actions are finished, I do a second `renderToString` and the view then gets rendered with all data needed.\r\n\r\nWhen the store dispatches the change event from loading, this function gets called:\r\n\r\nhttps://github.com/acdlite/flummox/blob/master/src/addons/reactComponentMethods.js#L185-L190\r\n\r\n```\r\nfunction createStoreListener(component, store, storeStateGetter) {\r\n  return (function () {\r\n    var state = storeStateGetter(store, this.props);\r\n    this.setState(state);\r\n  }).bind(component);\r\n}\r\n```\r\n\r\nThe problem is that the setState is called on a non-mounted component which creates an error afterwards. That error then stops the dispatching and \"everything breaks\".\r\n\r\nThe only fix I could see was to check whether the component was mounted before calling the set state.\r\n\r\nSo\r\n```\r\ncomponentDidMount() {\r\n   this.mounted = true;\r\n}\r\n\r\nfunction createStoreListener(component, store, storeStateGetter) {\r\n  return (function () {\r\n    var state = storeStateGetter(store, this.props);\r\n    if (this.mounted) {\r\n      this.setState(state);\r\n    }\r\n  }).bind(component);\r\n}\r\n```\r\n\r\nI don't know if there is another way of doing it?"}}