Bug Tracker

Opened 11 years ago

Closed 10 years ago

Last modified 10 years ago

#10886 closed bug (worksforme)

$(document).trigger() crashes jquery

Reported by: [email protected] Owned by: [email protected]
Priority: low Milestone:
Component: event Version: 1.7.1
Keywords: ie6 ie7 Cc:
Blocked by: Blocking:


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 (15)

comment:1 Changed 11 years ago by dmethvin

Owner: set to [email protected]
Status: newpending

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.

comment:2 Changed 11 years 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:3 Changed 11 years ago by dmethvin

Do you have a global variable named RGD perhaps?

comment:4 Changed 11 years 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 11 years 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 11 years 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 11 years ago by dmethvin

Component: unfiledevent
Priority: undecidedlow
Status: pendingopen

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 11 years ago by anonymous

This test case shows the error: http://jsfiddle.net/sAy6M/, use real firebug, not lite.

comment:9 Changed 11 years 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 11 years 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 11 years 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:12 Changed 11 years ago by dmethvin

Milestone: None2.0

comment:13 Changed 10 years ago by david71rj

Seems solved in the edge.

comment:14 Changed 10 years ago by dmethvin

Resolution: worksforme
Status: openclosed

Not quite sure what status to use for resolution but the important thing (to me!) is that the ticket is closed.

comment:15 Changed 10 years ago by dmethvin

Milestone: 2.0
Note: See TracTickets for help on using tickets.