Skip to content

Commit

Permalink
docs: Update content script UI examples to use Svelte v5 (#1342)
Browse files Browse the repository at this point in the history
  • Loading branch information
rxliuli authored Jan 8, 2025
1 parent 2615e29 commit 1872060
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions docs/guide/essentials/content-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export default defineContentScript({
```ts [Svelte]
// entrypoints/example-ui.content/index.ts
import App from './App.svelte';
import { mount, unmount } from 'svelte';

export default defineContentScript({
matches: ['<all_urls>'],
Expand All @@ -210,14 +211,13 @@ export default defineContentScript({
anchor: 'body',
onMount: (container) => {
// Create the Svelte app inside the UI container
const app = new App({
mount(App, {
target: container,
});
return app;
},
onRemove: (app) => {
// Destroy the app when the UI is removed
app.$destroy();
unmount(app);
},
});

Expand Down Expand Up @@ -381,6 +381,7 @@ export default defineContentScript({
// 1. Import the style
import './style.css';
import App from './App.svelte';
import { mount, unmount } from 'svelte';

export default defineContentScript({
matches: ['<all_urls>'],
Expand All @@ -395,14 +396,13 @@ export default defineContentScript({
anchor: 'body',
onMount: (container) => {
// Create the Svelte app inside the UI container
const app = new App({
mount(App, {
target: container,
});
return app;
},
onRemove: (app) => {
onRemove: () => {
// Destroy the app when the UI is removed
app?.$destroy();
unmount(app);
},
});

Expand Down

0 comments on commit 1872060

Please sign in to comment.