In Salesforce

 

Salesforce is on an amazing journey with Lightning components. Few years ago, Salesforce developers were using Visual force pages, an unique HTML tag-based Mark-up language, and Apex as their controller for logic.

The year 2014 saw Salesforce launch the Lightning Component Framework supported by the Aura Programming Framework. The web standards provided less feasibility to create big web apps at that time, therefore, Aura came with its component-driven model which allowed developers to create big applications on the web. And, forward to 7 years, the web stack world has seen unparalleled changes and standardization that has transformed it from being an elementary page-rendering platform to a web development platform. 

Let’s first understand what lightning web components and why did Salesforce launch it?

What are Lightning Web Components?

Lightning Web Components or LWC is a stack of modern lightweight frameworks created on the latest web standards. It is a document object model element built using reusable code. It is used to generate powerful interfaces without using JS or building a Library. This feasibility makes it easy to use and quicker, thus, saving developers a ton of efforts and time on the web stack. 

Let’s look at few of its remarkable features:

  • Ability to create apps using small codes as the crucial element to create a component is part of the native web browser web stack and engine.
  • Improved performance of the component 
  • Increase in richness of the apps built using LWCs as they include modern web standards
  • Unparalleled interconnectedness and feasibility to use both LWCs and Aura components together in the apps with no visible difference to the end-user experience

Why did Salesforce Launch Lightning Web Components??

At the time, when LWCs was first launched by Salesforce, web standards were less popular. Developing bigger client-side apps came up with a lot of challenges. The components and applications written in different frameworks were not linkable even though they all were based on the JS. The frameworks delivered a higher level of distraction, making each one non-identical and forcing developers to choose one path. This made ramp-ups and skill transfers very difficult. Salesforce is one of the biggest advocates of standardizing the web in order to enhance flexibility. 

The list of standards developed include: 

  • Web components  
  • Templates and slots 
  • Custom elements 
  • ECMAScript
  • Shadow DOM 

LWCs is an extension of web component standards under the Salesforce platform to help perform the same functions as what lightning component does. 

If LWCs get the same UI result, what is in store for Web Stack?

This is a very good remark. Let’s explain in details:

  • Programming languages like Angular, React, Lightning Component framework which use JS are now part of modern web stack. As a result, web stacks do not require an extra mid-layer which is a challenge for developers working with Aura as it impacts the performance and speed of the application. 
  • Aura based lightning components are created using JS, HTML, but LWC is directly built on the web stack.
  • The addition of above features gives more power to the web stack to build lightning UI components. It doesn’t require any mid-layer to the browser. 
  • Web components can interact with Aura components easily and can handle the events of one another. 
  • LWC consists of features like LIghtning Data Service, Security and Base Lightning Components from Aura.
  • A developer who works on Lightning Web Components not only uses his coding skills on a particular framework but also on other frameworks like Angular, React, etc.
  • It is faster to create a LWC as it doesn’t require the user to download JS and wait for compiling it before rendering the component. 
  • It is possible to include LWC in Aura, but the other way round is not possible as the generic elements can not be included into the custom components. 

Why Shall We Go for LWC Instead of Existing Aura Components?</h2

The difference is only visible behind the scenes developers. However, Salesforce and community advises developers to use LWCs for creating SPAs because of the following reasons:

  • Easy to Learn: LWC basically takes the form using native web standards that are in the browser. This means that no added distraction layer like Aura Framework or any other framework is required, just we need standard JavaScript to develop.
  • Higher performance: In the absence of any abstraction layer, LWC is likely to render faster than the aura components since having good performance is important to deliverability.
  • Faster loading sites: LWC is faster in loading the developed components and is a lightweight framework.
  • Less proprietary, more standards: LWC consists of built-in browser security functionality from Web Components Standards, therefore, the usage of out-of-the-box is more and less of customization. 
  • Common components: We can write components that have no/less UI in LWC, and those components can be used again in other components which are more efficient than static resources.
  • Easy to ramp for developers: No extra framework is required to learn for developing LWC. It is therefore easier for the developers.
  • Better security, testing and browser compatibility: With LWC, Script, CSS, and DOM Isolation are better and have more limited event scope. With each of these, we have more consistency in designing the components. Plus, LWC supports two-way data binding using which we can coordinate how the data moves between various components.

Composition Strategies for Using Aura and Lightning Web Components Together 

Nested Composition 

You can use Aura and LWC components side by side. Aura is the ultimate parent component. An Aura contains both LWC and Aura components, but a LWC will contain only its own component. 

Side-by-side composition 

The interaction between an Aura and LWC components is possible in various ways if they are contained within a parent: 

  • interacting directly with the child component through application and component events
  • Receive and data through JS CustomEvent objects 
  • interacting with child component methods and properties exposed through public APIs ‘

Both the Aura components and LWC can receive and send data through LDS. Currently, there is no such mechanism of communication between the Aura and Lightning web components that aren’t in the same hierarchy. 

How to Migrate from Aura to LWC 

Your organization might be thinking of making a migration  strategy to move towards LWC. Before that, you need to understand that the fundamentals of both the models are quite different and aren’t just a line-by-line conversion. And, it is an opportunity to redesign, reorganize and simplify the process.

You can take it one step at a time and after you complete the migration you are in a better position to know the need for a bigger effort. 

Choosing the migration patterns is a bit easier for smaller components. If you have no JavaScript at all, you can just swap the Aura HTML Syntax with its Lightning web counterpart as you go. Redesign it, then rebuild. For the larger components, you might have to start from the bottom-up and understand how you can manipulate the deeply nested hierarchies. For more complex migrations, the Lightning Web Components Developer Guide will provide you with all the tools and resources you need for taking the right migration path. 

Most developers want to see the best of both worlds where they can make the most of server-side rendering and client-side handling by LWC.

Foreword

The good news is that the Aura Framework is here to stay. LWCs are the future of lightning development. If you are creating new functionality, consider using the Lightning Web Components to benefit from the better native operation in the performance and browser.

Do you need assistance in migrating from Aura components to Lightning Web Components? Chat with or Call our Salesforce experts to know how implementing the right framework can help you create an everlasting impact on your customers. Sedin has been delivering end-to-end Salesforce development, consultation, customization and integration services for clients located globally. 

Recent Posts