Ticket #10886 (closed bug: worksforme)
$(document).trigger() crashes jquery
| Reported by: | kevin.turner@… | Owned by: | kevin.turner@… |
|---|---|---|---|
| Priority: | low | Milestone: | |
| Component: | event | Version: | 1.7.1 |
| Keywords: | ie6 ie7 | Cc: | |
| Blocking: | Blocked by: |
Description
We have tried jQuery 1.7 and 1.7.1 and both exhibit a problem that we do not have with jQuery 1.6.4.
If we trigger any events in a certain namespace, e.g $(document).trigger('RGD') or $(document).trigger('RGD.changesApplies') or $(document).trigger('RGD.whatever_else_you_can_think_off')
we get this error on line 3175 of the 1.7.1 unminified version: "elem[type] is not a function"
We don't seem to have any problems on any other namespace, so I am not sure what the issue is really.
Change History
comment:1 Changed 18 months ago by dmethvin
- Owner set to kevin.turner@…
- Status changed from new to pending
comment:2 Changed 18 months ago by anonymous
I understand the need for a cut-down test case, but to be honest this is a huge piece of code and, try as I might, I cannot get it into a manageable jsFiddle test case. You can, however, replicate it online by going to http://rns.coraltree.co.uk and logging on with a user id and password of "demo".
You can then click on the large cog icon/button at the top right hand side of the screen. The button will have a tooltip of "Switch to RGD mode". When you click this button the screen will change after downloading various resources. If you do this in Firefox with firebug enabled, you can just replicate the error by executing $(document).trigger('RGD.changesApplied'). In reality the user sees the error by dragging and dropping templates into the viewport.
comment:4 Changed 18 months ago by Kevin Turner
Yes, there is a global object called RGD. However, there are several global objects (like RNS for example) and we can trigger events in their namespace OK. For example, I can do this: $(document).trigger('RNS.something') but I cannot do this $(document).trigger('RGD.something') although it is OK up to and including version 1.6.4.
What sort of property in the RGD object might cause this to screw up now when it didn't before?
comment:5 Changed 18 months ago by dmethvin
If you had a test case it might be possible to isolate the why, but we generally don't want to get into debugging someone's site. I suspect that there is an RGD on document and .trigger() is trying to call that. As documented, if you don't want that behavior call .triggerHandler(), which also won't bubble to window. Can you give that a try? If you can create a reduced test case I'd still like to see it.
comment:6 Changed 18 months ago by Kevin Turner
I can confirm that .triggerHandler() works perfectly.
Is there anything I cando to help you work out why trigger doesn't work? I amhappy to continue with triggerHandler but I think it would be useful to know what went wrong. I have tried a cut down example with just the RGD object present but it seems OK - so some piece of code embedded in the application is cauing it. Trying to find it will be a nightmare without some idea what to look for. I am happy to debug my own application if required.
comment:7 Changed 18 months ago by dmethvin
- Priority changed from undecided to low
- Status changed from pending to open
- Component changed from unfiled to event
I'll mark this open so it won't be auto-closed but I don't have the time at the moment to debug it. To me it seems like the RNS object should cause the same error, not sure why they are different but I haven't looked at the code.
comment:8 Changed 17 months ago by anonymous
This test case shows the error: http://jsfiddle.net/sAy6M/, use real firebug, not lite.
comment:9 Changed 17 months ago by Kevin Turner
Yes, that rather simple test case does show the bug in a firebug console. Thanks. I guess in my case there is a scenario where the object has no properties. Triggering an event with that object name as the namespace causes the error - but only in 1.7.1.
comment:10 Changed 16 months ago by borgar
What is happening is that .trigger() tries to execute the "default action" of the element after having bubbled the event: elem[ type ](); (event.js#L372)
However, the checking that is done prior is whether the property exists on the element and is truthy, but not whether it actually is a function. So: if ( ... && elem[ type ] && ... ) (event.js#L361)
Thus, all events that share a type-name with a non-function member on the element will crash!
An extremely reduced example would be: $('<a href="#"><a>').trigger('href');
And another jsfiddle: http://jsfiddle.net/RBPRh/ - again, use real firebug, not lite.
comment:11 Changed 15 months ago by dmethvin
- Keywords ie6 ie7 added
If we could reliably detect whether a property was callable, we could fix this. Unfortunately, IE6/7 return for example, typeof link.focus == "object" rather than saying it's a function. I suppose we could see if it's either an object or a function, that would at least limit the damage but as I understand the OP report it would not fix his problem.
comment:13 Changed 6 months ago by david71rj
Seems solved in the edge.
comment:14 Changed 6 months ago by dmethvin
- Status changed from open to closed
- Resolution set to worksforme
Not quite sure what status to use for resolution but the important thing (to me!) is that the ticket is closed.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket.
Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to get started.