-
Notifications
You must be signed in to change notification settings - Fork 754
Mounting of components using indirect eval call has cross-browser issues #162
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
Comments
See issue reactjs#162 for more information. http://perfectionkills.com/global-eval-what-are-the-options/
Interesting stuff, I hadn't read about this before. Here's what I understood:
My first thought is that this doesn't really affect us because our use of
I'm certainly not opposed to this change if it gives us some benefit, but can you help me understand what the benefits are? Did you encounter some bugs with this? (For my part, I don't know why |
I actually had misunderstood what was happening before, so actually everything did work correctly. The way If we'd want to not accidentally try to load some component in IE <= 8, which would unfortunately have the same name as some variable in the local scope of What if the eval('window.' + className) Then it would at least force the lookup to happen at the I'll admit that it might not be a big benefit if that case was handled, but maybe it would make the code easier to reason about? |
Haven't heard any issues with the existing behavior, but feel free to reopen if something comes up! |
In
react_ujs
, in themountComponent()
function,react-rails
is using an indirecteval
call as a fallback to element loading. This approach has cross-browser issues, as ES3 allows browsers to throw on indirect eval calls. It will also leak all the variables to global scope, which might or might not be a good idea.What indirect eval, you might say? I suggest you read the following blog post in order to fully understand the quirks and weirdosities of eval.
http://perfectionkills.com/global-eval-what-are-the-options/
Especially regarding the indirect eval and cross-browser issues, check this part of the blog post — Indirect eval call. In practice.
Maybe using plain, direct
eval
call would be better, as it would evaluate the code in the local context ofmountComponent
function, have much better consistency between different browsers and would not leak variables in to the global context. What do you think? What I'm proposing is simply changing the fallback mechanism to just useeval(className)
instead ofeval.call(window, className)
.EDIT: Actually made a PR for the proposed change: #163
The text was updated successfully, but these errors were encountered: