Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Overriding native function can lead to unwanted side effect #666

Closed
ssougnez opened this issue Mar 8, 2017 · 8 comments · Fixed by #686
Closed

Overriding native function can lead to unwanted side effect #666

ssougnez opened this issue Mar 8, 2017 · 8 comments · Fixed by #686

Comments

@ssougnez
Copy link

ssougnez commented Mar 8, 2017

I'm currently trying to start a project with "angular4" and "ckeditor5" and I noticed that I'm not able to use "ckeditor5" because of "zone.js". The thing is that "ckeditor5" is using "isNative" method from "lodash" library to determine if "addEventListener" is a native method or not and then, based on that, do its stuff. However, when "zone.js" is included un the page, "isNative" returns "false" for "addEventListener". Indeed:

document.getElementById('XXX').addEventListener

returns

function addEventListener() { [native code] }

when "zone.js" is not referenced and:

function addEventListener(){return f(this, arguments)}

when it is, making the "isNative" function of "lodash" not really reliable anymore (this could be argued as the function is indeed not native anymore, but at the end of the day, "addEventListener" is supposed to be native).

The real source of the issue is arguable. Indeed, separately, every library work correctly but it's once we associate them that the problem occurs. I posted an issue on "ckeditor github" (ckeditor/ckeditor5#413) as at first I didn't know where the issue came from and a dev over there said something interesting:

Anyway, there are two options – either zone.js fixes this or we do. From a puristic POV I'd say that it should be zone.js. It's very unlikely that they'll stop changing the native prototypes, so at least they could fix the toString() properties of functions they assign to native prototypes. This would fix the root of the issue and prevent similar errors in the future (we're using Lodash's isNative() function, so there may be more libraries doing so).

Maybe the solution he proposed could be the correct one if it makes "isNative" function returns the correct value.

Otherwise, I think it could be interesting to discuss about a solution.

@JiaLiPassion
Copy link
Collaborator

@ssougnez, thank you for reporting the issue, we will make isNative return true for all methods which were patched by zone.js

@ssougnez
Copy link
Author

Cool, thanks :-D

@ssougnez
Copy link
Author

Hi, would you have an estimate of the date for the release of the version with this fix?

Thanks

@JiaLiPassion
Copy link
Collaborator

Sorry for the late reply,I will try to fix this one this weekend, I will update the status here.

@ssougnez
Copy link
Author

Awesome, thanks a lot.

JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Mar 18, 2017
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Mar 18, 2017
@JiaLiPassion
Copy link
Collaborator

@ssougnez , can you test the attached zone.js to see the problem is gone or not? thank you.
zone.js.zip

@ssougnez
Copy link
Author

ssougnez commented Mar 18, 2017

@JiaLiPassion , works like a charm ;-)

@JiaLiPassion
Copy link
Collaborator

@ssougnez , ok , thank you for confirm.

JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Mar 19, 2017
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Mar 19, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants