Bug Tracker

Modify

Ticket #8568 (closed bug: invalid)

Opened 3 years ago

Last modified 2 years ago

Live Event callbacks can get out of order in Event liveHandler function.

Reported by: edlebert Owned by: edlebert
Priority: undecided Milestone: 1.next
Component: event Version: 1.5.1
Keywords: Cc:
Blocking: Blocked by:

Description

VERSION: This bug exists in jQuery 1.5.1 (and older versions). I do not believe this is a regression, it has always existed as long as liveHandler has been around. It is browser independent.

PROBLEM: The callbacks in liveHandler are executed first on the order of the selector match, then on the order of when they were attached. This makes it possible to execute your callbacks in a different order than they were attached. The problem is verifiable here:  http://jsfiddle.net/edlebert/thNds/

The fix is VERY easy, just swap the two loops below in the Event::liveHandler function. Before:

	for ( i = 0, l = match.length; i < l; i++ ) {
		close = match[i];

		for ( j = 0; j < live.length; j++ ) {
			handleObj = live[j];

After:

	for ( j = 0; j < live.length; j++ ) {
		handleObj = live[j];

		for ( i = 0, l = match.length; i < l; i++ ) {
			close = match[i];

Change History

comment:1 Changed 3 years ago by edlebert

I created a pull request on github here:  https://github.com/jquery/jquery/pull/280. Sorry, I didn't add a unit test because I'm unfamiliar with the unit testing on jQuery. :) But it shouldn't be hard to create one using the super simple jsfiddle entry listed above in the ticket.

comment:2 Changed 3 years ago by dmethvin

  • Owner set to edlebert
  • Status changed from new to pending

In what situations are you depending on the call order of event handlers? In general this is not a good idea; see #3781. Neither jQuery nor the W3C guarantee the order that event handlers will be called.

comment:3 Changed 3 years ago by rwaldron

  • Component changed from unfiled to event

comment:4 Changed 3 years ago by trac-o-bot

  • Status changed from pending to closed
  • Resolution set to invalid

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.