2

We have built an app using Lightning components.

I have used jQuery and Bootstrap, but whenever I try to use some of bootstrap's native functions (example: popovers) I get a message like the following:

Uncaught TypeError: Right-hand side of 'instanceof' is not an object throws at /resource/jquerymin311:4:31635

I do understand that this is because of LockerService explicitly forbidding the use of 'instanceof'. The issue, of course, is that not all popular libraries follow that rule. Bootstrap and jQuery being two of the most widely used javascript libraries should not be prevented to run in Lightning.

I want to use Lightning components for this project, but if I can't use some basic functions in one of the most popular libraries, it just doesn't make sense. It should be noted that everything works well without LockerService enabled. What can I do to use the functionality we need in Lightning, or will it simply be impossible in the future because of third-party libraries?

  • What exactly are you asking? This sounds like a gripe, that you should just take to SFDC. – Sebastian Kessel Nov 8 '16 at 16:21
  • How to prevent the error coming from JS: Uncaught TypeError: Right-hand side of 'instanceof' is not an object throws at /resource/jquerymin311:4:31635without disabling the lightning locker service. – cloudy-ritz Nov 8 '16 at 16:23
  • 2
    You can't, long term, disable locker service. And, as you well stated, LockerService doesn't let you do it. So, in my mind, there is nothing you can do. – Sebastian Kessel Nov 8 '16 at 16:24
  • Hold on a second folks - that is not what the "don't rely on instanceOf" warning is about. See my answer on this post. – Doug Chasman Nov 8 '16 at 16:39
3

The fix for this is in and currently scheduled for the Spring '17 major release, but may be backported to a patch sooner. We're still discussing the risk involved with that.

If you're curious about the technical details... there were 2 issues at play here.

1) foo instanceof document.constructor was erroring out

This is the error you were seeing. Bootstrap was using this check to do some validation when initializing a tooltip. We've updated the secure wrapper around document to have a constructor property present and for this to properly resolve to true when foo is in fact the document.

2) data-* attributes on elements were not being ignored

Once the above issue was resolved, the tooltips started working but always took on the default values. For example, the popover element would always be on top even if you set data-placement='right'. This has also been fixed (pending release) and tooltips appear to be taking in all the correct options.

7

This is the first problem of this type I have heard of around jQuery and Bootstrap. jQuery is successfully being used by many many developers now in Winter'17 after the recent set of fixes in the past month.

The issue with instanceOf that resulted in the warning about instanceOf is about realms which are not even in play in Winter'17 and would not result in "Right-hand side of 'instanceof' is not an object" error messages. They would result in a failure to match things like el instanceOf HTMLElement.

We need to see the specifics of what that right hand side is supposed to be (e.g. what prototype is being referenced).

We are also planning to deal with most of the instanceof issues in Summer'17 once we can start using javascript Proxy - e.g. our SecureElement will be able to finally respond that it is an instance of HTMLElement etc.

This specific issue looks like something else though. A paired down repro case including specifics on version of jQuery, Bootstrap etc will help speed the process.

If I am not mistaken this is already being investigated with Salesforce case 15064281, correct?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.