Ticket #9217 (closed bug: fixed)
javascript error in IE8 when animating element is removed before animation finishes
| Reported by: | JorisDebonnet | Owned by: | gnarf |
|---|---|---|---|
| Priority: | low | Milestone: | 1.8 |
| Component: | effects | Version: | 1.6 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
I had some IE8 users report that my application was sometimes 'crashing', and it took me many, many hours to pinpoint the problem (because all IE8 said was: 'unspecified error' somewhere in jQuery). I should just have used a non-minimized version of jQuery to save me those hours, but anyway.
Apparently, if an element's scrollTop is being animated, and that element is removed during the animation, then jQuery will crash in IE8. In the git at the time of writing, it's on line 8499 in a piece that extends jQuery.fx's step, and says:
fx.elem[ fx.prop ] = fx.now;
http://jsfiddle.net/NGBaX/2/ (note: I always need to run it twice before it crashes)
Change History
comment:1 Changed 2 years ago by timmywil
- Priority changed from undecided to low
- Status changed from new to open
- Version changed from git to 1.6
- Component changed from unfiled to effects
comment:2 Changed 2 years ago by JorisDebonnet
Well, yes, the javascript error is what I mean. Since it also affects future animations, at least in my application, I called it a 'crash'. In my application's case, even logging out would not work anymore ... since that does an animation (which only redirects the page upon finishing it).
It does sound sensible of course to stop the animation before removing the element, but it was not obvious to think about it in my case. It's a stylized dropdown in a form that is slid up when an input element is blurred. Makes sense to me, but 'sadly' this element is of course also blurred when the form is submitted via ajax, which (when response is received) overwrites part of the page. And, well, the ajax call seems to return faster than the animation, so it does that. :)
(I temporarily solved my app by simply removing scrollTop from the animation)
So anyway, all this just to say that I do believe it's something a developer should be able to rely on, in complicated systems :)
The point is perhaps that scrollTop is not very often animated, leaving the problem unreported until now.
comment:3 Changed 21 months ago by gnarf
- Owner set to gnarf
- Status changed from open to assigned
- Milestone changed from 1.next to 1.7
Originally commented on this pull: https://github.com/jquery/jquery/pull/542#issuecomment-2369920
I really really dislike this "catch and release" pattern here... There HAS to be a better way to fix this bug.
Timmy's suggestion in the bug ticket has some merit, to fix the crash/bug you just need to .stop() the animation before removing the element - which makes sense anyway...
Why are we still animating an element that has been removed? Should these timers be stopped? etc..
If we are going to fix this bug, we should probably be REMOVING the timers from jQuery.timers in cleanData. If not, we need to tell users to .stop() before .remove(), but that has problems. It's probably easier for us to remove timers than it is for the user to .find("*").stop().end().remove();
comment:8 Changed 12 months ago by mikesherov
- Milestone changed from 1.next to 1.8
Gnarf, you mentioned you were going to roll this up into the animation rewrite. The fiddle is still failing on edge.
comment:9 Changed 12 months ago by mikesherov
- Summary changed from jQuery crashes in IE8 when scrollTop-animated element is removed to javascript error in IE8 when animating element is removed before animation finishes
comment:10 Changed 12 months ago by gnarf
I'll jump on this one soon.
comment:11 Changed 11 months ago by Corey Frang
- Status changed from assigned to closed
- Resolution set to fixed
Fix #9217. oldIE error when changing detached elements, close gh-861
Changeset: 74cc5b0984335532ab272b8286566000c4bf3daf
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

I'm unable to reproduce the crash, but I do notice a javascript error. Regardless, you should probably stop the animation before the removing the element.