Salesforce Architects who are considering a design shift from Aura to Lightning Web Components (LWC) might be wondering what kind of tradeoffs are involved and what impacts such a decision might have on their development teams. How long will it take developers who are familiar with Visualforce or Aura to learn LWC? Are there special tools or toolchain adjustments that come with adopting LWC? Is application performance significantly changed (or improved) by migrating to LWC? How can you decide which Aura applications should be targeted for refactoring or migrating to LWC? Is migration an all-or-nothing process?
If these questions sound familiar to you, read on. In this post, I cover how adopting LWC can make development simpler and increase business value, what will change for your development teams and toolchains, and how you can get started prioritizing your migration roadmap.
Why make the move?
Use of native browser APIs
Since Salesforce released the Lightning Experience in 2014, the web has evolved in amazing ways through investments in web standards. This evolution has been steered by several well-known organizations, including the World Wide Web Consortium (W3C) and the ECMA International Technical Committee 39 (TC39), both of which Salesforce is part. Salesforce has played a key role leading web standards conversations, especially for those standards that LWC uses, such as Web Components. As web standards evolve, browser vendors implement them in the form of native browser APIs. Salesforce regularly meets with major browser vendors to align priorities and directions.
While the Aura framework needed to implement a proprietary component model, proprietary language extensions, and proprietary modules, LWC uses web stack features implemented natively by browsers, which means that LWC apps are substantially more performant.
One difference between LWC and standard Web Components is the amount of code that you have to write to create a component. To create a component with LWC, you just write a few lines of code, and then the LWC compiler will transform that code, adding the necessary boilerplate code so that those become, at the end, Web Components. This empowers your teams to be more productive, maximizing the time developers can spend on more critical application logic or UX considerations and minimizing time-to-value for the business. For more about Web Components standards and how LWC uses them, a good place to start is with two five-minute YouTube videos, Explaining the Shadow DOM and Custom Elements & HTML Templates.
Major modern browsers are usually up-to-date with the latest standards, but older browsers — some of which are supported by targets in which you can run Lightning Web Components — are often missing some modern features. Salesforces helps with this by enabing you to write your LWCs using the latest syntax and features, transpiling (transforming) the code to ES5, and adding the needed polyfills (emulation of missing features) when your code runs in an old browser. This means that you don’t have to worry about backward compatibility, and can deploy LWC-based apps to wider audiences with more predictable behavior across (supported) browsers.
Because LWC aligns with web standards and is open source (what we call LWC OSS), the components you create can easily work outside the platform. This means that you can write a component on the platform and reuse it somewhere else, for instance, in a non-Salesforce runtime. You have even more flexibility because can use base UI components and Salesforce Lightning Design System (SLDS) stylesheets outside of the platform, as they are also open source. Learn more about LWC OSS in the Build Apps with Lightning Web Components Open Source Trailhead trail.
Keys differences in Aura and LWC development
Let’s look at the key differences between Aura and LWC that Aura developers on your team must understand.
You cannot edit or develop LWC components in the Developer Console. You’ll need to use another integrated development environment (IDE), and I recommend Visual Studio Code (VS Code). Why this particular IDE? Because Salesforce has released an extension pack that makes it easy to work with LWC (and not just LWC, but also Apex, Aura, and Visualforce, too). The extensions provide autocomplete and syntax highlighting capabilities, direct access to documentation and help, shortcuts for using the Salesforce CLI more easily, CSS validation, testing and debugging tools, and more. The extensions enable developers to write high-quality code much faster, to understand the execution flow of their code more easily and with more depth, and to simply ship better first drafts of code.
Because using an IDE means developers write their code locally, teams will need a way to deploy code to Salesforce environments. For that, I recommend using the Salesforce CLI. The Salesforce CLI works with any organization and has source tracking capabilities (ways to identify and compare what’s changed in an environment). It makes development teams, especially distributed teams, more productive.
This complete toolchain vastly increases developer productivity and code quality.
Note: The new developer tooling is something that I recommend all your Salesforce development teams use, even if they don’t work with LWC. All the benefits apply to Apex, Visualforce, and Aura development as well.
Standard syntax and files
Reorganization of responsibilities
LightningElement (which, in turn, extends
The metadata file becomes the one and only place that binds the component to the platform. Everything that’s platform-related — such as the experiences a component supports or the design attributes that are configurable in App Builder — are defined in that file. And, as a bonus, the metadata file now is more versatile, supporting more configuration options for LWC.
In summary, LWC component responsibilities are better distributed, and follow industry standards. LWC components are less verbose and more configurable. They’ll be easier to understand, test, and refactor in the long-term.
On top of the general performance benefits you get from using modern web standards, component performance has also been improved with some key changes in LWC framework behavior.
The first such change involves property reactivity. In Aura, to trigger a component re-render, attributes need to be set explicitly using
The second important change is with the component lifecycle. Without going into too much detail, I’d summarize it like this: In Aura, most lifecycle events propagated from child to parent, and in LWC it’s the opposite. However, you and your team should take a look at the documentation to understand the whole component lifecycle paradigm. The LWC lifecycle adheres to the Custom Elements standard.
Lastly, Aura uses attributes to pass information down to a child component; in LWC, you use properties for this. However, to pass information from a child component to a parent, the story changes. In Aura, there are two methods to propagate information up: bidirectional data binding and events. In LWC, only events (the standard approach!) are supported. In other words, data binding in LWC unidirectional. This is one of the best improvements in the LWC framework. Information flow is much clearer and well-defined. In nontrivial (for example, enterprise) applications, the predictability of data flow significantly improves the developer (and architect) experience. It’s easier for teams to understand the behavior of an LWC-based component simply by how it’s written. This change is also a significant factor in LWC’s improved performance.
Lightning message service
In Aura, you use Application Events to communicate between components in different DOM hierarchies. The replacement in LWC is the Lightning message service. This service enables you to publish and subscribe to messages on a message channel. Lightning message service not only enables communication between LWCs in different DOM hierarchies, it also enables communication with Visualforce pages and Aura components.
Improved ways to work with Salesforce data
In Aura, Salesforce introduced Lightning Data Service, which lets you retrieve and modify Salesforce data and metadata easily from your components, with built-in optimizations (like caching and synchronization). In LWC, Lightning Data Service has also undergone dramatic evolution. The base Lightning Data Service engine has been refactored for maximum performance across the various ways developers can use it: base form components, wire adapters and functions, and Apex. Each Lightning Data Service invocation point is suitable for different use cases; therefore, an Aura developer should take some time to understand all the options for choosing the best pattern for Salesforce data consumption in LWC components.
By the way, the Lightning Data Service cache is shared among Aura and LWC components, which means all your components will synchronize if they use Lightning Data Service no matter which framework they use. Isn’t that great?
The built-in services of Lightning Data Service enable developers to access Salesforce data and metadata without having to go in-depth to understand the particular customizations of an organization or write Apex. This means development teams can save development time when working with unfamiliar organizations. Check out the Lightning Web Components and Salesforce Data Trailhead module to learn more.
Better unit testing with Jest
A common pain point in Aura development was the heavy lift for developers to find a solution for testing their components. In LWC, the testing experience is much more straightforward.
@wire, and more.
To migrate or not to migrate
Finally, there’s one remaining question I would like to help you answer: How do you decide whether Aura components should be migrated to LWC? First, it’s important to understand that you can combine Aura and LWC components within your organization and your apps. Here are some of the ways LWC and Aura are interoperable:
- Lightning Message Service can be used to communicate between Aura components and LWC. So, ideally, you could extend your existing Lightning pages in App Builder with LWC even if most of the components are written in Aura.
- Lightning Data Service shares its cache between Aura and LWC. This means components can synchronize data, regardless of which framework they’re written in.
- Aura components can include LWC. As a result, you can extend the functionality of an existing Aura component by writing the new bit of code in a child LWC component.
In most situations, you can extend and maintain your Aura applications by simply writing new functionality in LWC. For Aura-based apps that are working (and performing well) you can spare your team the work of undertaking a large migration effort for existing components.
In many ways, Aura technical debt is actually not such a heavy weight, as Aura can easily coexist with LWC and Salesforce provides many services to help.
However, there are certain situations in which you may want to prioritize migrating Aura components to LWC:
- When you have an Aura component (or application) that’s experiencing poor performance. The significant performance boosts with LWC might help users struggling with an app that feels unresponsive or slow in Aura.
- When you want to use platform features that only support LWC, such as custom property editors in Flow.
In my opinion, it’s a good idea to start building all new components in LWC now — if you are not doing so already — and plan an incremental approach to transition Aura components or apps that fall into one of the two categories above.
A transition from Aura to LWC can bring significant benefits in terms of performance, productivity, and portability. To maximize these benefits, however, the Aura developers on your team must learn the key concepts covered in this post as they make the move to LWC. I can tell you it won’t be that hard, as the two frameworks are not radically different. I’m also sure you’ll start enjoying the new coding features and that you will be much more productive soon. Keep in mind the scenarios in which it’s recommended to migrate existing Aura components or rather use the integration features that Salesforce provides to address any technical debt concerns you have in your system.
If you want a deeper look at these topics, set aside some time to watch this one-hour video in which I explain them in detail, showing side-by-side Aura and LWC code examples from a real application.
About the Author
Alba Rivas works as a Lead Developer Evangelist at Salesforce. She focuses on Lightning Web Components and Lightning adoption strategy. You can follow her on Twitter @AlbaSFDC.