Table of Contents:
A major announcement for the UI development world in Salesforce, the company introduced Lightning Web Components in December 2018. Now open-source, Lightning Web Components comes one step closer to standardizing development on the Salesforce lightning platform. The new platform is a breakthrough in terms of leveraging web standards. But if you’re a developer who’s new to the salesforce world, or if your org is contemplating a shift from Aura to Lightning Web Components, this article aims to get you a little closer to the answers you need for UI development.
For those who are not familiar, the Lightning component framework was launched in 2014 by Salesforce in an effort to enable large scale client-side application development on the web. It came with its own component model and its own modular programming model. From an application perspective, the Lightning Component framework is a UI framework that you can use to develop SPAs (Single Page Applications) for mobile and desktop devices. A Salesforce Developer builds lightning components and a Salesforce administrator assembles the lightning components and creates a lightning page.
Why did Salesforce launch Lightning Web Components?
The frameworks provided a high level of abstraction, making each one so different and forcing developers to choose one path. This made skills transfers and ramp-ups in organizations quite hard.
As a member of the ECMAScript Technical Committee, Salesforce has been the biggest proponent of standardizing the web in order to improve flexibility. The last 5 years have seen unprecedented developments in web standardization, thanks to W3C and TC39.
The list of standards developed include:
- Web components
- Custom elements
- Templates and slots
- Shadow DOM
Lightning Web Components is an extension or the practical enforcement of Web Components standard under the Salesforce platform, to essentially perform the same functions as what Lightning Components does.
For the developers out there, learning a new programming language takes time, and gets exceedingly frustrating at times. But the worst happens when a framework you’ve just gotten familiar with is now launching something different or upgrading. If you’ve been on the Aura platform and consider that you are at an intermediate level in expertise, you may be wondering whether you should take Lightning Web Component seriously and if you’d like to invest your time in it.
Why choose LWC over Aura?
Sales reps aren’t going to find any difference in their daily Lightning Experience. The difference is only visible to the behind the scenes developers. But Salesforce and the community in general, advises that it is better to choose LWC for building SPAs as much as possible.
The major advantages of LWC are
- Performance: Because of the absence of an abstraction layer, LWC is likely to load and run much faster than Aura components. It is also lightweight and memory-efficient as it is built on Web Components.
- Easy to ramp: As there is no additional framework, LWC developers can make transitions much easier.
- Faster debugging: Debugging is a breeze with LWC as you’re more likely to find answers to development questions through forums and communities and other common places on the web.
- Versatility: LWC allows you to utilize full encapsulation.
Differences between Aura & LWC
If you’re an Aura expert, here’s a gist of notable differences you’ll find between coding in Aura and LWC:
- Bundle structure: LWC requires manual creation of a folder to host all your component files. Component HTML, JS, Configuration files are mandatory. CSS and SVG are optional.
- Naming Convention: The only noted difference in naming is while you’re referring component in another component. The new syntax uses kebab-case, instead of the camelCase ( <c-hellowrold> instead of <c:helloworld>) and the component must have a closing tag.
- Events: Unlike component or application events in Lightning Component, LWC used Standard DOM events.
- Lightning Locker: Lightning Locker is enabled by default in all custom LWC.
While this is not an exhaustive list, it gives you a small insight into how much change you might have to get accustomed to.
Co-existence and Interoperability
It has been made clear that as of, Lightning components are not going away. They will continue to exist in parallel. Aura and LWC can communicate with each other using Public APIs and Events. LWC can be embedded into Aura, but not the other way round.
While you should always think of choosing LWC over Aura, there are some limitations. LWC doesn’t support everything that Aura can do yet. If you do want to use an unsupported feature, experience or interface, develop everything in LWC and wrap it up inside an Aura component. However, if you want to use an unavailable base component, you may need to develop everything in Aura.
Composition strategies for using Aura and Lightning web components together
You can use LWC and Aura Components side by side, but Aura is the ultimate parent. An Aura Parent can contain both LWC and Aura components, but an LWC parent can only contain LWC components.
Interaction between Aura components and LWC is possible in many ways if they are nested or contained within a parent:
– interacting directly with child component attributes or through application and component events
– interacting with child component methods and properties exposed through public APIs
Both Aura components and LWC can send and receive data through LDS.
As of now, there is no mechanism of communication between Aura and Lightning web components that aren’t in the same hierarchy.
Migrating from Aura to LWC
Your org may be contemplating a migration strategy to move towards LWC. Before you decide on taking the first footsteps towards the new path, understand that the fundamentals of both the models are entirely different and it isn’t simply a line-by-line conversion. However, on the brighter side, it’s an opportunity to simplify, redesign and reorganize.
Take it one step at a time, and once you complete one migration you may be in a better position to understand the need for a larger effort.
For more complex migrations, the Lightning Web Components Developer Guide provides you with all the resources you need for considering the right migration path.
Of the looming questions regarding LWC, most developers want to see the best of both worlds scenario where they can make the most of VF’s server-side rendering and client-side handling by LWC.
Salesforce partners Cyntexa is constantly striving for ways in which customers can build faster, innovate and deliver new products to their customers and employees.
While you may be wondering whether you should switch as a developer, it should be noted that it is best for your org to develop new components on LWC.
We provide Salesforce Platform Development that extends Salesforce such as creating extensive automation, complex logic implementation, and custom solutions around Salesforce.
How we at Cyntexa can help you with Salesforce Platform Development?
- Implement deduplication and auto duplicate detectors
- Drive better insights which are not possible by standard reports
- Implement complex record/lead/opportunity assignment rules
- Create extensive automation to better run the process of the Sales lifecycle.
Moreover, since it is mostly developed on HTML, CSS, and JS you may not find it all too difficult to get used to the new syntaxes and conventions. Migrations as of now may be slow, due to limitations in terms of communication between Aura and LWC components but further releases might change the precedent, allowing orgs to completely move over to LWC. But one thing is for sure, LWC is here to stay and is a welcome change as it makes ramp-ups and transitions much simpler, allowing all the good parts of SPAs to scale easily. The robust framework simplifies the need for organizations to look into integrating other frameworks into Aura (which only lead to more chaos and unreadability).
You can know more about Implementing modern Web Standards which is the way to go for a brighter future in web development as a whole. The versatility and robustness that comes with standardization might seem ironic, but is the key to innovation.