Philippe Ozil joins to talk about the Lightning Web Component at a high level. Philippe, France based, is a Lead Developer Evangelist at Salesforce.
Main Points
- What is the developer evangelist role in Salesforce?
- What is the Lightning Web Component (LWC)?
- What are web standards and how browser vendors follow web standards?
- What is the difference between LWC and the popular JS frameworks such as Angular and React?
- What components does LWC contain? LWC engine, data binding, and base component
- The shadow DOM feature in LWC
- What does the LWC repository in Github contain?
- What are the upcoming features in the LWC roadmap?
- What good learning resources do we have for LWC?
Links
- Salesforce Sample Gallery
- LWC Developer guide
- Blog: Introducing Lightning Web Components Open Source
- Blog: Differences Between Building Lightning Web Components on Lightning Platform and Open Source
Video Teaser
Thoughts
Lightning Web Component (LWC) is the Salesforce new generation front-end framework. It’s brand new and has many cool cutting-edge features, such as ES2015 supported, Web Component supported and so on. Besides, the LWC core is also open-sourced In TDX19′.
Because of all these, LWC becomes absolutely a buzzword in the Salesforce Ohana.
However, buzzwords usually come with many misconceptions, so does LWC. Many people throw this jargon without quite understanding it.
For example, these questions below are remarkable important for any Salesforce developers to grab the big picture.
- Why yet another framework since there exists Aura, React, Angular, VueJS, etc.?
- What does it mean “LWC goes open source” to me — each individual developer?
- Where is the boundary between things open-sourced and things still in proprietary?
- Can we use LWC outside of the Salesforce lightning platform?
- Can we reuse LWC components developed for the Salesforce lightning platform outside?
And the good news is, Philippe has answered all the questions above in this episode :)!
Questions of today
What is your experience in learning LWC? Let me know your thoughts :)!
Contact Me
If you enjoy this podcast, please reach me out to let me know your thoughts or simply say Hello. My (Xi’s) contact info:
Take care, until next time :)!
Transcript
AI-generated, unedited.
[00:15] Hey everybody! This is Xi Xiao. This is yet another episode of Salesforce Way podcast. Today I'm sitting with Philippe Ozil from France. Hello Philippe, how are you doing today? Hello, everybody, and hello, Steve. Thank you for having me. I'm great, and it's a real pleasure to join you. Yeah. So, Philippe, I understand that you are working in Salesforce organization, right? Yes, that's true. I'm a Salesforce Developer Evangelist, and I've been working for Salesforce for the last three years. Before that, actually, I wasn't part of the ecosystem, but I think I've grown to to love the ecosystem and the Ohana. I would say. Okay, it's so great to have you. One quick question, actually, I never understand what is developer evangelist in Salesforce. We know there are many of you like as with this title. That's a great question. So yeah, this title is not so common, but it's what it means basically is that we're bringing knowledge to developers. We are evangelists in the sense that we preach good practices. We teach about innovation, and we. Tell developers how to better adopt our different technologies. I would say, so whether it is from things which are for the day-to-day work or from the most innovative features, we work on both ends of the spectrum. And generally, we are fairly technical people with also some skills in marketing. So we we know how to message or convey
[01:45] our ideas. That's okay. Kind of how to put it. Yeah, I see a lot of you are writing the Trailhead content as well, right? That's definitely one of the message channel to teach the developers how to write the code. How what's the best practices. So we work on different mediums. We work on on the blogs. That's I would say the most common form of expression. We work also on sessions. We travel around the world in person or remotely to give presentations about the technology. We also work on Trailhead content, and we generally also work on bigger events like Dreamforce or Trailhead DX. We're part of the experience. You're the best guest to fit into this topic today. You know, I wanted to to bring you in to talk about Lightning Web Components, which is hot, which is new, but still there are a lot of things around the Lightning Web Component coming up recently. And many developers like I, we have the puzzles, we have get confused. So that's why I think you will definitely help us to to clear those airs. All right, with pleasure. So let's start with the Lightning Web Component from the high level. So, so what does it really mean? You know, each time when we talk about Lightning Web Component, there are different things. Like we have a built-in UI, we have the the framework, we have a compiler, all sorts of like a component belongs to the Lightning Web Component. Could you clarify this point first of all?
[03:16] Yes. So, what is really important in Lightning Web Components is actually the web components part. The idea behind this new framework is that we spent years working on
[03:30] Aura, creating the previous experience for for developers on the Salesforce platform. We had at that time to work with what was available in terms of web standards, and at that time it was. Next, around 2014, the standards on the web weren't so mature. The reality was that we had to do a lot of things called abstractions on the JavaScript side. We had to simulate basically a templating engines that we could integrate components together, and we had to to do all of that with JavaScript running in a browser. So this was actually not very performant, and it also it wasn't really portable. So we had to adjust for every browser to make sure it runs seamlessly. Now with the current web stack in 2019, we have a whole different landscape. We can actually leverage things from that are called web standards. So we can use web components. That's the main one, but we can also use others like. Custom elements, decorators. This is really part of the of the new JavaScript ecosystem, and that allows us to have a really lightweight framework. Oh, that's really find a way we build things. You mentioned the web standard. What does it mean? Does it mean the browser already support those features, built-in feature? Absolutely. So, web standards are the different bodies that regulate how, for example, an HTML page is displayed, how CSS is structured, how JavaScript language is built. So there are different sets
[05:00] of web standards. You can look on the internet. This is, for example, W3C standards, which just dictates. How web pages are rendered, or DOM elements are composed, and then there's also TC39, which is the body that governates how the JavaScript language evolves. And this is this last body that has made a lot of changes in the last years, which allows to have those web components, basically. Okay, but those browser vendors are not necessarily following exactly the web standards. So the the idea the idea is to follow all of them. So in the past, actually, everybody did a bit implemented the different there different browsers in the way they wanted. But nowadays, most of browsers are actually running on those standards. Now that there are some differences, of course, depending on the browser types, and that's still a bit of a pain, especially when we have to support legacy infrastructures for enterprise customers. So we still have to adapt to this. Yeah, but I would say nowadays most vendors are pretty much line. And when I'm talking about this, of course, I'm talking about the latest versions of the browsers. I'm not talking about all the browsers. Yeah, just to name it, I try to refrain myself from naming it. But yes, that is definitely the the least advanced one. Okay. But if you consider modern equivalents like Edge and Chrome or Firefox, these are pretty much in line
[06:30] with Webstones. The gap is very small between them. Yeah, that's so good for the web developers and for us as well when we write the Lightning Web Component, right? Then you mentioned the web standards evolved, of course, along the time, and in you mentioned in 2014 there weren't that many features supported in the web standards, and now in 2019, five years passed, we have more features already built in. You mentioned, for example, what was the custom custom element? Custom elements, yeah. And you mentioned some other features as well. Those decorators, for example. I understand these two features. We already have them in the Lightning Web Component. We can use those two features already. Absolutely, and the idea is that we have. If you just take the framework itself, there is very much less JavaScript code written to support. Developers, because what we do is we leverage native code that runs on the browser. So if you compare that with Aura, on Aura we had to emulate all of those web standards by having lots of JavaScript code that would run and simulate the templating engine, for example. And with web components, we don't have to do that. That's the browser who actually does the templating for us. So that's the power of custom components. Yeah, and so that means the the framework runs really smoothly and it's also very lightweight. Just just out of curiosity, for those like like a famous third-party framework
[08:01] like React, Angular, do they also evolve along the web standards? Do they take off, take out those third-party, you know, their implementations? They are. They are trying. They're actively trying to do that, but they have legacy to. to to support so that's that's actually why we broke away from Lightning Web Components because this was going in a really different direction now that's good. Okay, now I understand better. Like, where do we start from the Lightning Web Component? Exactly, and we really have a leading edge on this because actually Salesforce now is part of the of the body called W3C and TC39. So we are actually actively influencing the web standards of tomorrow with that. So. We're really we're really shifting away from this proprietary approach into building something that is more open source and standard. Yeah, I understand. I remember. I remember that news. Salesforce joining the W three C standard. Yeah. Right. Yeah. Yeah. That's great. All right. Then now let's talk about the like what is Lightning Web Component. Always there are different components inside a LWC, right? Yeah, so there are different things, and if you if you really step back from the world of Salesforce, there is actually a an open source framework. We only announced it very recently, but the fact. Is that it existed before we actually had
[09:31] the Salesforce specific implementation? We only went public with it recently, but the idea is just like Aura. It's kind of the same approach. We first built something that is open source, that is totally decoupled from Salesforce ecosystem. And then we have an additional layer that is so specific, which allows you to have declarative features, and like you know, support for Lightning App Builder, things like that, connecting to Lightning Data Service. But this is just an additional layer on the base open source framework, and so you got exposed to this one first. You got exposed to the full range of features, but before that, it was the foundation, which is just the rendering engine, which is the one you can see in the open source system. Okay. Yeah, I think I got your point. So we have this generic foundation, right? So that is kind of detached from our Salesforce Lightning platform. Exactly. And on top of on top of that, we build this kind of data connection. How you fetch and transfer the data between your Lightning Web Component and the the Lightning platform, which is Salesforce specific. Yeah. So the idea is that the Lightning Web Component open source framework is not tied to a specific backend. So it's really something that runs on the client side, on the browser, and then you can put whatever you want to act as a backend, basically. And when you go for Lightning Web Components on the platform, the backend
[11:01] is the Salesforce platform, and this is all tied up together for you. You don't have to worry about all the backend operations. This is done by Salesforce. It's kind of like a separation of concerns. It only handles the rendering, so it doesn't. It doesn't matter how you deliver the data to it. You have to implement it by yourself if you want to do that. Yeah, and so when you explore the open source framer, you'll see that you have the same features that are available. For example, you can write your own wires that lets you fetch some data, but you have to have a backend support that. So it's up to you to implement that. For example, that wire. It's also part of this decorator in the web standards. Yes. So a wire is a is a decorator. So a decorator is is it's pretty similar to to an annotation when you look Apex or or Java, for example. The idea is that it starts with a an at symbol with a name, and this influences the behavior of a function or a property that is attached to it. And so, for example, if we take the wire decorator, the wire decorator lets you fetch data from external data source. And that external data source can be something you define when you're on the open source framework, or it is the Salesforce platform when you're inside the Lightning Web Components platform. Okay, it's like the encapsulation of the data connection. Yes. Okay, I get that. So this way
[12:31] you have your data separated from the logic that actually does the retrieval. I like that. It's more clear when you see the code. You just see, oh, there's a decorator, and you immediately understand what things it does. So you don't really need to look into the code. Exactly, it keeps the code very simple. Yeah. If you compare back to Aura, when you were doing something that required to fetch some data from the server, you had to write about a hundred lines of code to do the server action service, the server action, and then send it, etc. Now with that, you just have an at wire name of the. Adapter that fetches your data and you're good to go. So that's really simpler. Okay. So in in addition to the Lightning Web Component framework and this the data binding, and I understand there is also this a base Lightning component which is we can just use them, which was built like built by Salesforce. Am I right? Yeah, there are certain differences in terms of platform availability. So the base components are the implementation of the Salesforce Lightning Design System components. So this is just a set of components with style that looks like the Lightning experience, basically. Okay. And these components are implemented and provided by us, but they're only available for now on the Salesforce platform. You could recreate components that look alike on the open source version of it, but you wouldn't have all the bindings with the data structure behind it. Okay.
[14:02] Okay. Which makes sense. Yeah.
[14:06] Hi. Here's a quick note. Don't forget to check the show notes of this episode, where you can find short video teasers, the guest contact information, the important complementary materials, and my own learning points, among many other useful information. In addition, I have also started a YouTube channel to share important stuff I learned from my guest. If you are serious about your Salesforce developer journey, you should definitely consider subscribing to this channel. And obviously, the name of this YouTube channel is Salesforce Way. Now let's get back to the show, shall we? Okay, so we talked about these three components, which is underneath the Lightning Web Component umbrella. So. You mentioned only the framework is open source. The other two, we cannot really see the source code. Am I right? The base lightning components and the data. Yeah, the base components are are not open source as of now. Okay, but you can you can easily recreate them because if you look at the Salesforce Lightning Design System website, you have access to the HTML templates of the components, so you you can recreate them if you need to. And for example, if you look at resources provided by the community, there was an equivalent of those components made available under React, if I recall. So there's, you can
[15:36] use whatever technology you want to recreate those base components. Basically, of course, it's a, I mean, it's some work. It's not something that would go instantly. So the structure of the code is is still easier to reverse engineer if you do want to create your versions. Yes, it is easier to use. Now, the other good news is that you can also decide to go with another styling framework if you want, because you have full control over the styling and your components. So, if you want to do something with Bootstrap or something like that, you could as well explore this option. I see some articles when they talk about the Lightning Web Component open source version, they always talk that it's linked to CSS. Have you heard about that? Does it mean the CSS styling? So, part of the part of the different standards we use for Lightning Web Components include something called the Shadow DOM. That's another standard we use along with decorators and custom elements. And what this means basically is that when you build a web page, it's actually a tree of the different components that compose this page. This is called the DOM, Document Object Model. Now, this tree contains divs, tables, whatever we put in there, and. In a in a classical page, this is just a single tree. So when you apply CSS on that tree, the CSS can impact all of the elements on that tree. Now with web components, we're using something called a shadow
[17:06] DOM, which isolates portions of that tree. So for example, if you have a button component, the the button component is has its own standalone shadow DOM, so its own tree, and you can style this. Component in isolation so that it doesn't get style leaked from the overall page. Okay, that's the idea. So this is true for the style, but it's also true true for for other APIs like if you do DOM traversal, if you navigate in the DOM elements on the page, you can actually hide the implementation of a specific component with this shadow DOM. Okay. I more or less get the high-level picture. When we write the Lightning Web Component, or even in the in the in the past, writing the Aura, we in the CSS we can define this dot something. Is that what you mentioned the encapsulation of the CSS? So yeah, this was actually a way to to simulate this encapsulation. But this was, I mean, this was done by the framework itself. So we were trying to do that by generating the CSS and making sure it was isolated with some JavaScript applied to it. Now, with the shadow DOM, this is done natively. We don't have to do the dot this. The browser natively takes care of this. Of not applying the style to the subcomponents. There's also another difference with Aura. In Aura, you can actually you're not you don't
[18:37] have access to the top elements above you, but you can still access a few things from the elements that are below you. And with Lightning Web Components, you're more in isolation. Okay. No, I actually really come up with another thing which might be related, because previously we talked about the locker service. Locker service, I understand is also kind of um isolation, the different component. So is it similar to what you just mentioned, the shadow down isolation? So yes, again, that's a good example of what we tried to do with a lot of abstraction code that wasn't super efficient in terms of resources. But it's not provided by standards, so not everything that we do with the Locker Service is actually part of the standards now. But part of what we did is now replaced by the standards. So the implementation of Lightning Locker Service is probably lighter now using those new standards. Okay, I got it. But it's still part of a very important aspect of the framework. And for now, there's a big difference between the open source version of the framework and the on platform version. The Lightning Locker service, for instance, is not deployed on the open source version of the framework for now. Why? Why is that? Well, because we want to leave the freedom to the JavaScript developers to use the APIs they want, and the thing is, when they're on on the Salesforce ecosystem, they're not putting the Salesforce infrastructure at risk.
[20:07] They're putting at risk their own application. So it's up to them to secure them. But when you do the same thing on the Salesforce platform, you're actually risking the org sanity and also all the other users on the same tenant of the server of the Salesforce org. Okay, I don't know if I'm clear. I think what you explained is clear. I just need more, maybe later, more examples when I write the code. I can really see what does that really apply. So let let's imagine an example. So if you don't apply lock of service, you could be vulnerable to coding injections, for example. Yes. So. You could get some custom JavaScript code injected on your page, and that could do malicious activities on your page. Now, if you're running that on the Salesforce, or you can imagine that the problem in terms of trust, you can get I don't know account details being pushed to a third-party site, for example, things like that. Yeah, that would be very nasty. So that is part of our mission to keep the trust in Salesforce, to make sure that we we're not exposing our customers to such a such such risk. Now, when you build your own application on the OSS framework, on the open source framework, we don't have the same level of guarantees to provide in terms of trust. So it's up to the developer to do whatever he feels he should do. I understand. So it's more in open source version. It's more open, more flexible. But of course, you you as a developer, you have more responsibilities to take care. Yes, absolutely. Okay. Okay. Now I get it.
[21:39] When I search in Google, Lightning Web Components GitHub, I will hit the like the main GitHub repo for Lightning Web Component, and what does that repo really contain? So, I guess you're talking about yeah the LWC at Salesforce slash LWC. Yes. Yes. Salesforce slash. Yeah. So that's that's the rendering engine. So. Rendering engine is the base, and there are some modules that are supplemental and that are optional. For example, if you consider the the Wire service, this is something that is optional. You could very much use the open source framework without using the Wire service if you decide not to use it. So that acts as a as an add-on, and there are other things like that. Like for example, we have also some ESLint rules. So ESLint is something called a linter, which does code quality checks. Yeah. Basically, tells you if you're writing, for example, using variables which are not read, or if you're using asynchronous code while you should not be. It's a very flexible rules engine. Okay, and we have a plugin made specifically to work with the Lightning Web Component syntax. There are also things like, for example, the Lightning Web Component testing. Framework, so we are using one of the most popular testing libraries for JavaScript. It's available. That's called Jest. Okay, it's it's a universal framework which
[23:09] lets you test any JavaScript code, and we've made an extension to that to support Lightning Web Components. So that's something also that goes optional. The reason why this is optional is that we don't enforce code coverage for Lightning Web Components. So that's a big difference compared to, for example, to Apex. What else? So there are various smaller dependencies that I've had, which are not part of the core framework, which you can basically take apart and not use or or include in your projects. But the main thing is the engine, the templating engine. That's really the core of what you get when you use the Salesforce framework. Okay, cool. Thanks for helping me to clarify all these questions. You know, they are actually really a long time in my head as a puzzles, and then finally I get it cleared out. Would you mind to share like what's the long term roadmap actually in the Lightning Web Component team? All right, so I'll have to give you the forward-looking statement, and also to tell you that I'm I'm not part of the engineering team, so I'm not necessarily the best person to ask this. We're probably going to make some announcements around Dreamforce, and I think what we're trying to do right now is work a lot on having parity with Aura. So there's still a few things. You can do in Aura, but you cannot do directly in Lightning Web Components. And I think we want to catch up and have the same level of features. A very
[24:39] precise example of that is part of the Release 20 effort. For example. I mean, part of the features we're releasing as part of Winter '20 are the ability to support mobile Lightning Web Components. So you can have Lightning Web Components on mobile pages. We can also have, for example, Lightning Web Components inside tabs directly, without having to have Aura wrappers.
[25:05] There are other things like, for example, around flows. So we have a set of options to customize flow screens with Aura, but we don't have those yet in Lightning Web Components. So we're probably going to work on that as well to really have the same kind of features. Now the good news. The good news with that is that you don't necessarily need to wait for for these new features to be released. You can already work with Lightning Web Components because of the backward compatibility. For any Aura component that you have, you can actually inject a Lightning Web component inside. So that means that while you're waiting for those new features, you can use Aura wrappers around your Lightning Web component code, which lets you already implement your new feature. And once the feature is released, you can remove the wrapper and go back directly to Lightning Web components. Okay, that that sounds that sounds like a really good plan. All right. Yep. So. Uh huh. Cool. Yeah. Um. By the end, since we talked about all these high-level questions and really helped people to understand where we are going and what things we should really learn, how to differentiate these components, where are the best resources for us to learn better the Lightning Web Component when we really want to hands on. Yeah, so as you mentioned, there are a lot of trailhead resources available. That's a good start. And it also depends on what type of learner you are. For
[26:35] my part, I'm I'm someone who learns by looking at code rather than looking at instructions. So there are different paths you can take. If you like a hands-on approach and you want to be guided, you can. Look at the different projects that are available on trial. But if you want to look at code, there's a really good thing we've released as part of my V Developer Evangelism team. That is called sample applications. So if you if you look online for trial sample gallery, you'll find a list of sample applications that we provide as open source. There I don't remember exactly how many there are, but there there are about six or eight. And the idea is that I want to focus on on two of those, which are the top ranked ones. These are called recipes. And these two applications are actually really bite-sized code examples of very specific use cases. So, for example, you start with the hello world, and then you see how you can work with. Compositions, having a parent component, a child component, how you can communicate with those, with very very small code examples, about 30 lines of code max. So this teaches you basically everything you need to know about the different use cases that you you are gonna encounter, and then it's up to you to imagine how you can combine those different use cases to build a full fledged app. So, if you want to look at more advanced example, the good news is that there are other apps on the sample gallery, really more complete apps. You can look at, for example, eBikes, which is a fictitious
[28:05] bike rent manufacturing company with a lot of graphics, a lot of interactions, drag and drop, and also other platform features, not just the UI part. Okay. What is interesting? What is super interesting with those application, simple applications, when I go back to recipes, is that we have actually two versions of recipes. There's the recipes application that goes on the platform, but there's also the open source version of recipes, so you can actually compare the on platform implementation with the off platform or open source implementation. Okay. Yeah. Yes, I opened the page, the sample gallery, and we will also put it in our show notes for our listeners. So it contain this page contains multiple multiple repositories. So start with the recipe, the repository, an open source version, and e-bikes. Even the Dream House—it's called Dream House—is here as well, right? Yeah, the old old Dream House. Yeah, it evolves all the time. I think there are new ones as well. The Pure, Allo, and the Dream Invest. There are those. Yeah, actually, there are multiple, really multiple of them. And nowadays, I like this. You know, nowadays we can really check the GitHub. It's the open source project. You can really go there to dig into the code to really learn complex stuff. So yeah, it's it's definitely definitely good. I think that's really a treasure trove to to explore. And so where where's that? Where's the sample gallery?
[29:36] Where's Trailhead, and where's also the um. the the developer guide which is also very well written I think and covers more advanced subjects like how you do integration with other types of components how you can write tests things like that oh by the way the recipes also include test code so if you you can look at how components can be tested so that's also super valuable is this yes the test framework you mentioned right. With just yes, just yes, okay, good, excellent. We got a lot of good information from you. Thanks a lot, Philippe. It's really good pleasure on the
[30:14] show. If
[30:23] you enjoyed listening to this session and want to have a really easy way to support this podcast, Why don't you give us a quick rating or even a review on whatever channel you are listening to this show? If you are using iTunes, just go to SalesforceWay.com/itunes. It should open up the iTunes page for you. I read pretty much all the reviews you leave over there, and it really helps other people discover this show. So your support is very much appreciated, and I'm super grateful you have spent your invaluable time with me here. And I'd really love to hear how you think about this podcast. At last, I hope you are doing well, taking care, and see you next time.
Thanks for this content!!
You are welcome Andreas, hope it brings some value to you :)!