I have built a simple service to compose a series of tweets, http://tweetsmart.in using React and Flux. I am facing a weird error where the page reloads when the user signs in and clicks on the tweet button for the first time.
If the tweet button is clicked the second time things work as expected. It is only the first time after logging in that I have noticed this behavior. The tweet button is just an anchor tag, so it's not the default submit behavior of button which is causing this.
Steps to repro the bug:
- Goto http://tweetsmart.in/popup.html
- Sign in using twitter
- After signing in write something in the Text box.
- Click on the Tweet button to tweet it.
You will find that the page reloads and the tweet fails, though I am not sure which happens first. When I open Chrome developer tools and look at the Network tab, I find that the api call to tweet gets cancelled and the next thing that happens is that the page reloads. It seems to me page reload caused the api call to cancel.
However, I have put some logging statements in my code to debug and I find an anomaly. After clicking on the Tweet button, an Action is dispatched which queues the Tweets and then if there are any queued Tweets, then a subsequent Action is dispatched to tweet the first queued Tweet. This results in the Api call tweetsmart, which is wrapped in a Promise and only when the Promise succeeds or fails further Actions are dispatched to the Store.
However, from the log statements on the console, I find that the componentDidUpdate of my main React component is called before the page reloads. Dominic Decoco is logged if there is an unsuccessful tweet. See https://github.com/singhshashi/tweetsmart/blob/master/js/components/TweetSmartApp.react.js
As I am not dispatching any actions to the store, I am not sure what is causing the react component to update. Is this happening simply because of the page reload? Is this causing the page reload?
============Update 1========
The React component updates because the api call is cancelled and thus the TWEET_FAILED action is dispatched.I think the reason that the api call is cancelled is because a reload is triggered. The question is what is triggering the page to reload?