Sub topic 2
Making the component available with isExposed
This chapter covers the isExposed flag in the component's .js-meta.xml file. It explains what the flag controls, how it works with targets, and what goes wrong when the two disagree. It assumes you can already create a Lightning web component bundle (HTML template, JavaScript class, metadata file). It also assumes you can read basic XML and deploy with Salesforce CLI to an org you control.
What isExposed does
Every Lightning web component bundle has a metadata file named after the component, such as accountSummaryCard.js-meta.xml. Salesforce reads this file at deployment time to decide where the component can be used.
isExposed is a boolean element in that file. It answers one question: may tools outside the component's own code base use this component?
true: builders such as Lightning App Builder can list the component, subject to the targets you declare.false, or missing: the component is private to code. Other components can still include it in their templates, but admins cannot drag it onto a page.
The default is false. A component you generate with a scaffolding tool, or one you write by hand without this element, will not appear in App Builder until you add it.
Here is a minimal file that exposes a component:
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<isExposed>true</isExposed>
<masterLabel>Account Summary Card</masterLabel>
<description>Shows a titled card with the current record context.</description>
<targets>
<target>lightning__AppPage</target>
<target>lightning__HomePage</target>
<target>lightning__RecordPage</target>
</targets>
</LightningComponentBundle>The isExposed line is the gate. The targets block, covered in its own chapter, says which kinds of page the component may be placed on.
Two conditions, not one
A common misunderstanding is that isExposed alone puts the component in App Builder. It does not. App Builder lists a component only when both of these hold:
isExposedistrue.- At least one
targetthat App Builder understands is declared, for examplelightning__AppPage,lightning__HomePage, orlightning__RecordPage.
If isExposed is true but no page target is present, the deployment succeeds and the component still does not show up. If a target is present but isExposed is false, the same thing happens. In neither case does Salesforce warn you, because both files are valid. The component is simply not offered.
The third check in the diagram matters when you edit a page. A component that declares only lightning__RecordPage appears when you edit a record page. It does not appear on a home page, because the page type does not match.
What isExposed does not control
It helps to keep isExposed separate from nearby settings.
| Setting | What it controls |
|---|---|
| `isExposed` | Whether builders can see the component at all |
| `targets` | Which page types and builders can use it |
| `targetConfigs` | Which properties admins can set, and per-target restrictions such as objects |
| `@api` in JavaScript | Which fields and methods other components can set or call |
| User permissions and page access | Who can open the page that contains the component |
Marking a property with @api does not expose the component. Setting isExposed to true does not make any property editable in the property panel. Properties appear there only when you list them in targetConfigs.
A component can be private on purpose
Not every component should be exposed. A typical project has two kinds:
- Page-level components, which admins place and configure. These need
isExposedset totrue. - Helper components, such as a row renderer or a formatted address block. Parent components include these in their templates, and admins never need to see them.
Leave helper components unexposed. Exposing them clutters the components list in App Builder and gives admins pieces that make no sense on their own. It also makes them part of your public surface, so you have to think twice before changing their @api properties.
A parent component can still use an unexposed child in the same namespace:
<template>
<lightning-card title="Account details">
<c-address-block street={street} city={city}></c-address-block>
</lightning-card>
</template>Here c-address-block can have isExposed set to false and still render inside the parent. The flag matters for builders, not for ordinary composition in the same namespace.
If you ship components in a managed package, the rules are stricter. A component used by code in a different namespace must be exposed. Treat isExposed as a statement about what you are willing to support.
Deploying and checking the result
After you set isExposed to true and add targets, deploy the bundle:
sf project deploy start --source-dir force-app/main/default/lwc/accountSummaryCardThen open App Builder and edit a page of a matching type. The component appears in the Components panel on the left, under the Custom section. The label shown is masterLabel if you set one. If you did not, the panel shows the component name instead.
Check these things in order when the component does not appear:
- The deploy finished without errors. Read the command output, and do not assume success.
- The file is named exactly
<componentName>.js-meta.xmland sits inside the component folder next to the.jsand.htmlfiles. Case matters, soaccountSummaryCardandAccountSummaryCardare different names. isExposedis spelled with a capitalEand its value is lowercasetrue.- A target matching the page you are editing is listed.
- You reloaded the App Builder tab after deploying. A page that was open before the deploy can show stale lists.
- You deployed to the same org you are looking at. Run
sf org displayto see the default target org.
Errors you are likely to meet
Most isExposed problems come from a few causes.
Misspelled elements are the first. <isexposed> and <IsExposed> are rejected by the metadata parser. The deployment fails with a message that names the unexpected element. Fix the spelling and redeploy.
A missing targets element is the second. This one is silent, as described earlier. The bundle deploys and the component is invisible in App Builder. The cure is to add at least one target.
A wrong value is the third. Writing <isExposed>True</isExposed> or <isExposed>yes</isExposed> does not parse as a valid boolean. Use true or false.
Un-exposing a component that pages already use is the fourth. Say you change isExposed from true to false after admins have placed the component on pages. Pages that reference the component can fail to save or can render an error where the component was. Salesforce may also block the deployment. If you need to retire a component, first remove it from every page that uses it, then change the flag. Deploying to production is a good time to check for this, so search your pages first.
A stale view in the builder is the fifth. The metadata is correct but the browser shows the old list. Reload the page. If you work in a scratch org that you just created, confirm the deployment actually landed in that org.
Choosing whether to expose
Decide by asking who will use the component:
- Admins arranging pages: expose it, declare targets, and name it clearly.
- Only other components in your project: leave it unexposed.
- Both: expose it, and keep its public properties small and stable, since two audiences now depend on them.
Exposing is easy to do and awkward to undo once pages depend on it. Expose deliberately, and treat the first deployment with isExposed set to true as a commitment.
Summary
isExposedis the on/off switch for visibility in builders such as App Builder. Its default isfalse.- A component appears only when
isExposedistrueand a matching target is declared. - Neither condition produces a warning when it is missing, so check both when a component is absent.
- Keep helper components unexposed. Expose only components that admins should place.
- Remove a component from pages before you set
isExposedback tofalse.
Exercise
A teammate deploys a bundle whose meta file has <isExposed>true</isExposed> and a <masterLabel>, but no <targets> element. The deployment succeeds. Will the component appear in App Builder? Explain why, and say what you would change.
Show answer
No. App Builder lists a component only when isExposed is true and at least one page target (such as lightning_AppPage, lightningHomePage, or lightning_RecordPage) is declared. Without targets, the file is valid, so the deploy succeeds, but the component is not offered. Add a <targets> block with the page types you want, deploy again, and reload App Builder.
Exercise
You have a child component, c-address-block, used only inside the template of accountSummaryCard. Should its meta file set isExposed to true? What happens to the parent if you leave it false?
Show answer
Leave it false (or omit it). The child is only needed for composition, and a parent in the same namespace can render it regardless of the flag. The parent keeps working. Setting it to true would only add a component to the App Builder list that admins have no reason to place.