Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Invalid calling object" error in IE #4465

Closed
euan-smith opened this issue Dec 13, 2016 · 6 comments
Closed

"Invalid calling object" error in IE #4465

euan-smith opened this issue Dec 13, 2016 · 6 comments

Comments

@euan-smith
Copy link

Vue.js version

1.0.28

Reproduction Link

I've identified what is needed to fix the bug and I think, by inspection, it is the right thing to do. Producing a fiddle to reproduce this is somewhat complex and seems out of proportion to the fix, however if I absolutely have to then I will.

Steps to reproduce

Where there is an app with dynamic elements with transitions defined with callback hooks on the transitions, open it in IE (tested in 11 and 9,10 through emulation. No problem in other browsers)

What is Expected?

The transition completes with the hooks called at the right times.

What is actually happening?

The transition does not complete and an error is thrown in Vue: "Invalid calling object" on this code (which starts on line 37 src/transition.js, the error is thrown on line 40):

const raf = inBrowser && window.requestAnimationFrame
const waitForTransitionStart = raf
  /* istanbul ignore next */
  ? function (fn) { raf(function () { raf(fn) }) } //<-- error thrown here!
  : function (fn) { setTimeout(fn, 50) }

The error seems to be because the requestAnimationFrame method of the window object is being called without its parent object.

What seems to fix it?

By changing line 37 to

const raf = inBrowser && window.requestAnimationFrame.bind(window)

the error goes away. Using bind seems, to me, obviously correct. Clealy in other browsers because the default this is the window object anyway it should not matter, however IE seems to take a dislike to this approach and throw the error. Binding window to the method would seem harmless otherwise.

I'm an old-hand at coding but new to github (and relatively new to JS and vue) - The fix works but I don't really know if there are other reasons why this is not a good idea so I'm cautious about just closing it.

@LinusBorg LinusBorg added the 1.x label Dec 13, 2016
@euan-smith
Copy link
Author

As an addendum I can also fix it purely in my own code by window.requestAnimationFrame=window.requestAnimationFrame.bind(window); before the vue import. A bit of a hack, but sorts the problem until it is fixed in vue.

@jyllsarta
Copy link

Hello @zakalwe314 , I tried to reproduce this issue but I can't.
Reploduction link : https://jsfiddle.net/b6kjxhd5/8/
Is there anything I missed?

@euan-smith
Copy link
Author

Thanks for looking into this. I'll checkout your jsfiddle and get back to you. We had the problem in both of our apps in testing on ie - however they are also both quite large so I didn't have much luck isolating the problem last time, but I will try some more.

@euan-smith
Copy link
Author

OK, so I think I know what is hapenning, and unfortunately I don't know how to reproduce it on jsfiddle.

basically my code is built with webpack and "use strict" is the case everywhere.

According to mdn when a method is called with an undefiend this (which is the case here) then when NOT in strict mode then this=window however when "use strict" is enabled then this stays undefined.

It would seem that the call to raf detached from the window object should, then, in strict mode throw the error I see and it would be best practice to fix it. It would also seem to be the case that in everything except ie that all is good. I'm testing the code using the standard vue builder and npm run dev which executes code in eval statements for hot-reloading. Note that on ie the following throws an error:
eval('"use strict";var raf=window.requestAnimationFrame;raf(function(){})');
but not, for example, in Chrome or Firefox.

Is that enough evidence of an issue to get it fixed?

@posva
Copy link
Member

posva commented Jan 16, 2017

eval('"use strict";var raf=window.requestAnimationFrame;raf(function(){})'); is a repro 😆
So it's an issue with hot reloading in IE. I'll create a PR

posva added a commit that referenced this issue Jan 16, 2017
posva added a commit to posva/vue that referenced this issue Jan 16, 2017
Following a fix for v1 at vuejs#4274 for issue vuejs#4465
yyx990803 pushed a commit that referenced this issue Jan 16, 2017
Following a fix for v1 at #4274 for issue #4465
afc163 added a commit to ant-design/ant-design that referenced this issue Aug 3, 2017
with eval-source-map mode of webpack-dev-server

close #7060

ref vuejs/vue#4465
@rheupler
Copy link

Still running into this error in IE Edge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants