JohnP
JohnP

Reputation: 50009

All events in Backbone app fire twice. Occurs randomly

First, some background. I'm fairly certain this is not because of zombie views. I use requireJS and I have only one instance of main views at any given time.

Also, this behavior is random, I haven't been able to reproduce it even once, but several of my users have pointed it out and shown me a video where every click on the app seems to trigger the handler twice. The clicks happen very very fast. It can't be mechanical failure of the mouse because the problem has been reported on multiple machines. The reports are from people with fast Internet connections, for what it's worth.

Is it possible that two instances of the app are running at the same time? Are there any steps I can take to isolate a problem of this kind in backbone?

Apologies for the wall of text, please let me know if I can put up any extra information or relevant pieces of source.

Edit : I've managed to recreate this in Opera. After stepping through part of the code that fires twice (I was inspecting code that opens a modal), I was able to look at the view that triggers the event. Both views have the same CID, so this cannot be attributed to Zombie views right?

Upvotes: 0

Views: 350

Answers (2)

JohnP
JohnP

Reputation: 50009

The problem here was that I was running a third party library that reports JS errors. Due to a n error on their part, event bindings on page were affected and this caused the confusion inside the application.

Moral of the story - Whenever you hit an error you feel is impossible, remove your third party dependencies one by one and confirm the problem is your fault to begin with.

Upvotes: 0

Laurent Perrin
Laurent Perrin

Reputation: 14881

In my experience, this is almost always related to zombie views, or other DOM leaks. My best friend in this case if the Web Inspector Profiles -> Take Heap Snapshot and look for detached DOM tree (type "detached" in the search field).

It can occur in tricky cases, even if you think you're only instanciating views once.

Beyond that, you'll have to show us some code ;)

Upvotes: 1

Related Questions