AURA vs Lightning Web Components
Aura and LWC (Lightning web Components) can communicate with each other using Public APIs and Events. LWC can be embedded into Aura, but not vice versa.
Join the DZone community and get the full member experience.Join For Free
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 to enable large scale client-side application development on the web. It came with its component model and its 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?
- 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.
Major Advantages of LWC:
- 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.
Migrating From Aura to LWC
- 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).
Published at DZone with permission of Abhishek Sharma. See the original article here.
Opinions expressed by DZone contributors are their own.
Integration Architecture Guiding Principles, A Reference
Incident Response Guide
Integrating AWS With Salesforce Using Terraform
Java String Templates Today