Skip to content

Commit 989d54c

Browse files
committed
Add browser instructions
Signed-off-by: macdonst <[email protected]>
1 parent 2c9e243 commit 989d54c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

app/docs/md/conventions/components.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,29 @@ If you have an existing Enhance Element you can always import it into your Compo
129129

130130
</doc-callout>
131131

132+
### Making Components available in the browser
133+
134+
Now that we have written a client side component we need to register it with the browser at runtime. To do this we will create a new file `app/browser/index.mjs`. This is the file where we will import all of the components that will be rendered client-side. Using our `MyCard` component as an example our `app/browser/index.mjs` would look like this:
135+
136+
```javascript
137+
// app/browser/index.mjs
138+
import MyCard from "../components/my-card.mjs"
139+
export { MyCard }
140+
```
141+
142+
This will create a file called `public/browser/index.mjs` that you include as a `script` tag on any pages you want to use the `MyCard` component. For example:
143+
144+
```html
145+
<script type="module" src="/_public/browser/index.mjs"></script>
146+
```
147+
148+
<doc-callout level="info" mark="ℹ️">
149+
150+
At this point, you may wonder why doesn't Enhance automatically make all components available to the browser at run-time? We've debated this internally and decided that what is best for users is for you to have complete control over which components are available on every page. This way, you can customize each route with a `script` tag that only includes the required components on that page. This reduces the amount of JavaScript needed for each route.
151+
152+
</doc-callout>
153+
154+
132155
## UI Updates
133156
Updates to Enhance Components are triggered by attribute changes. Any change to an attribute listed in the `observedAttributes` will trigger a `<attribute name>Changed` method. For example if you are observing the `title` attribute of our `my-card` component any time that attribute value is updated the `titleChanged` method will be executed. This enables you to write surgical DOM updates which will always be the most performant way to update your page.
134157

0 commit comments

Comments
 (0)