Bug Tracker

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#13779 closed bug (fixed)

.remove() semantics have changed in beta3 - and now remove nodes in reverse doc order

Reported by: BorisMoore Owned by: Rick Waldron
Priority: undecided Milestone: None
Component: unfiled Version: 2.0.0-beta3
Keywords: Cc:
Blocked by: Blocking:

Description

The code was like this in b2:

remove: function( selector, keepData ) {
	var elem,
		i = 0,
		l = this.length;

	for ( ; i < l; i++ ) {
		elem = this[ i ];

and like this in beta3:

remove: function( selector, keepData ) {
	var elem,
		elems = selector ? jQuery.filter( selector, this ) : this,
		i = elems.length;

	while ( i-- ) {
		elem = elems[ i ];

Note the i--.

This can break client code quite easily. Also it is difficult to write code that will work both with previous versions and new versions, if the client needs to remove in a specific order...

Change History (10)

comment:1 Changed 10 years ago by gibson042

Owner: set to BorisMoore
Status: newpending

Could you please demonstrate some breaking code on jsFiddle or a similar playground?

comment:2 Changed 10 years ago by Rick Waldron

Owner: changed from BorisMoore to Rick Waldron
Status: pendingassigned

comment:3 Changed 10 years ago by Rick Waldron

Resolution: fixed
Status: assignedclosed

Fixes #13779. Remove nodes in document order (uses for loop matching empty()).

Signed-off-by: Rick Waldron <waldron.rick@…>

Changeset: 332ebeb3105a4cab0091dc6f3f6ba8c17b9265bb

comment:4 Changed 10 years ago by Rick Waldron

Fixes #13779. Remove nodes in document order (test)

Signed-off-by: Rick Waldron <waldron.rick@…>

Changeset: 7a66283d7d35b2024caf85cb588a0972b900cbcd

comment:5 Changed 10 years ago by anonymous

Any app that does its own disposal when elements are removed will need to override cleanData, and may need to remove elements in doc order. An example is https://github.com/BorisMoore/jsviews/blob/master/jquery.views.js.

Here is a jsfiddle using 1.9.1: http://jsfiddle.net/BorisMoore/xzGrj/ Click on Meet Jo Black and then on Eyes Wide Shut. The master detail selection works correctly.

Here is the same fiddle but using 2.x (edge) (Same would apply to beta3, which is not correctly provided in jsfiddle): http://jsfiddle.net/BorisMoore/xzGrj/ Click on Meet Jo Black - it works. Click on Eyes Wide Shut. The deleted nodes on the detail are deleted in reverse order, so disposal fails, and there is a script error.

Version 0, edited 10 years ago by anonymous (next)

comment:6 Changed 10 years ago by BorisMoore

The above comment was from me, BorisMoore. Didn't realize I was no longer logged in...

comment:7 Changed 10 years ago by BorisMoore

Here is a really simple test case: http://jsfiddle.net/BorisMoore/YFNbC/

In the case of JsViews, data-binding is achieved in some scenarios by insertion of script nodes as marker, (with type !== "javascript" of course), before and after the data-bound HTML content. Some frameworks insert comment nodes, though browsers sometimes move those nodes.

Anyway, the framework may need to handle removal of the preceding marker node differently from the following marker node, as part of the process of disposing the binding, and may need to handle the preceding node before the follow one, know which is which, etc...

Up to now jQuery has always used document-order semantics, so code could easily have relied on that. Different users of the framework could be using any number of different version of jQuery. So changing the ordering semantics can create problems...

comment:8 Changed 10 years ago by markelog

Resolution: fixed
Status: closedreopened

Commits were reverted, reopening for futher discussion. I'd say, even if removal order is not documented, some plugins might depend on it (see interesting discussion in #12213 ticket).

comment:10 Changed 10 years ago by Rick Waldron

Resolution: wontfixfixed

Fixes #13779. Remove nodes in document order (uses for loop matching empty()).

Changeset: 77d7f264524677104cd7f37ecdb631d5824eacd4

Note: See TracTickets for help on using tickets.