-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
let vue-template-compiler work in strict mode #3832
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
Hi, thanks for filling this issue.
No.. Using However it's relatively easy to remove For now, you can try using jsx (if you don't have negative opinions about it..), there's a official babel plugin for compiling jsx to vue's render function, which really works great and is much more flexible than templates (and doesn't require |
Hmm, pre-compiled templates, although using As of now, removing The alternative solution, as @fnlctrl suggested, is using render function / JSX. |
Hi @yyx990803 , the problem here is that Salesforce exposes a SPA in which you can develop components.. these components must not directly manipulate the DOM of others components, but should use the "official" way based on events to communicate with other components. Strict mode and other security features are required to keep a component in a sort of sandbox. That said, I've tried with JSX/render functions. It works, but pre-compiled templates are a lot better. You can still be productive even with JSX except for the lack of a valid v-model alternative (you can use a value + on-click binding but is clearly not optimal if you are doing a lot of data entry)... I understand that my situation is probably an edge case, but I'm still very sad to hear that this feature is not in the roadmap |
Also concerned about having to turn off security features to use vue, which could be a deal breaker. I'm just casually cruising through the code and I haven't come across anything that necessitates I'd like to know if there's a technical reason for it, but there doesn't seem to be.
can be replaced with
And then also replacing lines like this
with lines like this:
Furthermore, I don't understand the purpose of building with strings rather than using actual functions and replacing dynamic closure variables templates like this:
I believe that such a pattern would make it possible to not violate any CSP and still have the build tools get the strings that they need for export. If I could get some help from someone a little more familiar with the code I'm pretty confident that I could get this converted from insecure non-standard es3 with proper and secure es5.1 Is there something that I'm missing as to why this isn't possible to do in this way? |
I've resolved my issue modifying the compiler in this way:
This simple modification let me compile templates in strict mode. The only difference with the
becomes
I think that this could be avoided introducing an expression parser and some logic to determine if an expression variable is a view model variable, but this could slow down compilation and it is not so easy to do as the patch I did. It would be great to have an option to instruct vue-loader or vueify to compile templates in strict-mode. I think that users that need this functionality could accept to prefix the vm variables with |
You really don't even have to get that fancy, check this out: All I do is add a prefix in a few key functions. I just tested with a simple demo, but perhaps you can test too and help me find where I'm missing the fix. Beyond strict mode, I don't see any reason (yet) that this needs to be created from insecure strings and run through eval. It should be easy to create as functions and stringify them later. |
See the reasons explained in #4115 |
I have modified the compiler to be strict mode compliant changing just 2 lines of code. Why are you saying that this solution is fancy? I agree with you that your PR is trying to address the issue in a more 'clean' way, but be careful because there could be a lot of edge cases to address. Maybe I would change It seems that we are trying to do exactly the same thing, using two different approaches. Maybe my approach could be easier if you want to modify the compiler to have an additional |
@micheletriaca sorry, when I was looking at it on my phone and it looked like a lot lot more because of the extensive line wrapping. Now that I see it in the browser I see it's just the two. I agree. I think the controller-as syntax in Angular is basically the same idea of the in-template prefix as you're saying (and honestly that's what I would prefer). Do you think there's mix between our two approaches that could keep api compat and not break existing apps? |
Using, for example, my approach, the users could compile templates in strict mode but, in that case, they would need to write the expressions referencing also the scope (as you do in JSX, for example). That's what I'm doing now, but it seems to me that this solution is unlikely to be accepted (this is the reason why I haven't created a PR). If you want not to break existing apps, I think the correct approach to address the issue is the one suggested by @yyx990803 : a babel plugin to postprocess templates. You have to use some full javascript parser to assign the correct scope to the variables in the expressions :-( |
Hi,
I really love vue and I would like to use it to customize the user interface of Salesforce.
The problem is that Salesforce has recently introduced a security feature called LockerService, that enforces strict mode on any 3rd party libraries that are included in the project and in the near future will enforce also CSP.
I've done some tests and it seems that the only thing that prevent a Salesforce developer from using vue is that the compiler renders the templates using the "with" functionality.
Using inline templates is not an option because they use 'new Function', violating CSP.
It seems to me that it should be possible to modify the compiler to be strict mode compliant.. Is this improvement in the roadmap? Thank you for your awesome work
The text was updated successfully, but these errors were encountered: