-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Set view models as shareable by default #18541
Set view models as shareable by default #18541
Conversation
Does anyone can point me a direction to resolve the failed phpunit test? |
Hey @thomas-blackbird. Thank you for the contribution! You modified class but didn't modify its unit test. You need to update it:
|
Hi @slavvka, thanks for the advice! I didn't pay attention 🙄 |
lib/internal/Magento/Framework/View/Test/Unit/Layout/Argument/Interpreter/ObjectTest.php
Outdated
Show resolved
Hide resolved
@thomas-blackbird I am worrying more about changing the behavior for such objects. Could you investigate deeper if we may have issues with objects that weren't supposed to be shared earlier? |
@slavvka I'm currently investigating the issues cases which can occur whit this change. I think it's more common in developers mind that the instance should be shared by default (it's actually the case in Magento di). However it can break third part extension.. |
lib/internal/Magento/Framework/View/Layout/Argument/Interpreter/DataObject.php
Show resolved
Hide resolved
lib/internal/Magento/Framework/View/Test/Unit/Layout/Argument/Interpreter/ObjectTest.php
Outdated
Show resolved
Hide resolved
Hi @slavvka I don't think that the attribute "shared" should be false by default. The goal of this PR is to fix, which I consider as, a conception error. In Magento 2, usage of ViewModel is encouraged, it's purpose is to provide data to the view. The main strength of the view model is that it could be reused in many views, and the data could be shared. I guess all developers have in mind that the instances are shared. Indeed, why should it works differently as the DI works in the framework? If you really think that backward compatibility should be maintained, this PR won't have any impact on performance. |
@thomas-blackbird Thank you for the reply! I totally agree with you but my concerns are about potential BIC issues all over Magento (CE, EE, B2B, 3rd party extensions) that may occur. Could you please share any statistics on performance improvement that can be achieved with this fix if any? It would be very helpful to making the right decision. |
@slavvka Ok 👍 |
@thomas-blackbird np. I think it's more important to deliver a correct solution rather a quick one :) |
Hey @thomas-blackbird I am closing this PR. Please feel free to reopen it once you gather additional data |
Hi @slavvka , actually I've no clue how to fetch these information. I still think that the instance should be shared by default. I'm ready to apply the changes in that way (not shareable by default) and to check the view models which might be shared or not. |
Hey @thomas-blackbird You did't need to change defaults. I discussed that with Magento Architect and we agreed that your improvement is useless if shareable isn't default behavior. So please revert last changes and we will run all the tests to see what happens. |
@slavvka Haha good news 🎉 May I squash the commits too? |
@thomas-blackbird Yep, it would be good :) |
@slavvka done, I've also applied the modification to existing modules. |
@thomas-blackbird Awesome. What principles did you use to mark models as non-shareable? |
@slavvka How should I process? How can I relate the PRs? |
@slavvka Please, could you update? |
Hey @thomas-blackbird we are working on making changes in all related repos and testing Magento. Please be patient. |
Yes I know, my message was for some guidance request to port this PR to the repositories you have mentioned here:
|
|
…-block-argument-shareable
Hi @thomas-kl1 , please, sign CLA, otherwise, we can't process your pull request |
Hi @sidolov I've already signed the CLA, before and after I've renamed my account, I don't know why it's displayed as failed.. |
Pending merge of magento/inventory#1954 to MSI |
Hi @thomas-kl1, thank you for your contribution! |
Until now, when a viewModel is set to a block via the layout xml, a new instance is created. But by default, all dependencies of a class are a single instance which is shared.
Description
The purpose of this PR is to allows developers to choose if a view model must be shared or not. By default all view models are shared in order to increase performance (data only needs to be loaded once).
Contribution checklist