4

I want to implement a component versioning in lightning. The versioning would help me when I want to deprecate a component and start to use a new componet without having any impact for the users.

I implemented visualforce page versioning using redirect pages yet, but a similar approach is not applicable to lightning components.

What is the best way to realize component versioning in lightning?

1

Conceptually, since you can nest components, you could just place one in the other:

<aura:component>
   <!-- attributes go here -->
   <!-- optional: include a deprecated notice, perhaps to admins only? -->
   <c:componentDeprecated />
   <!-- give new component values -->
   <c:componentV2 attr1="{!v.attr1}" attr2="{!v.attr2}" ... />
</aura:component>

If you do that, make sure that you're eventually cleaning up the old deprecated versions to avoid excessive nesting, which would have a performance penalty, but I think this approach makes it simple enough to switch versions, since they only have to change a single line of code (assuming full compatibility).

I don't think that this was something really well thought out, much like how they didn't really allow this in Visualforce (we work around it instead of using some special system-platform-specific versioning feature).

| improve this answer | |
  • If only we could version each of our own components, and then declaratively specify the versions of our dependencies! Just like a whole managed package has a version... – Rohit Kunal Jul 16 '18 at 14:52
  • 2
    @RohitKunal Yes, that'd be nice, or even something like how components have API version dependencies. But unfortunately, whatever solution you would design would require an interstitial component to implement dependency injection, at minimum. – sfdcfox Jul 16 '18 at 14:59
1

One can insert versioning logic into the markup like so:

<aura:component>
 ...
 <aura:if isTrue="{!Version > 1.0}"> 
  <c:newVersionFunctionality/> 
 </aura:if> 
 <c:oldVersionFunctionality/> 
 ...
</aura:component>
  • In Apex, use System.requestVersion()
  • In ControllerJS/HelperJS use component.getVersion()
  • In component markup use {!Version}
| improve this answer | |

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.