Repository navigation
Closed
Labels
docsImprovements or additions to documentation
Description
Describe the bug
Very impressed with this framework btw, nice work.
This regards the method createContentScriptUi defined in https://wxt.dev/entrypoints/content-scripts.html#ui.
The docs refer to two methods mount and onRemove. There are a few discrepancies in the TypeScript interface:
mountshould take a parametercontainer: Element- The interface defines a method
remove, but notonRemove - The docs say that
remove/onRemovetake a parameteronRemove(app), but this isn't in the interface and I'm not sure what this should be
wxt/src/client/content-scripts/content-script-ui.ts
Lines 118 to 145 in 59094c9
| export interface ContentScriptUi<TApp> { | |
| /** | |
| * The `HTMLElement` hosting the shadow root used to isolate the UI's styles. This is the element | |
| * that get's added to the DOM. This element's style is not isolated from the webpage. | |
| */ | |
| shadowHost: HTMLElement; | |
| /** | |
| * The container element inside the `ShadowRoot` whose styles are isolated. The UI is mounted | |
| * inside this `HTMLElement`. | |
| */ | |
| uiContainer: HTMLElement; | |
| /** | |
| * The shadow root performing the isolation. | |
| */ | |
| shadow: ShadowRoot; | |
| /** | |
| * Custom data returned from the `options.mount` function. | |
| */ | |
| mounted: TApp; | |
| /** | |
| * Function that mounts or remounts the UI on the page. | |
| */ | |
| mount: () => void; | |
| /** | |
| * Function that removes the UI from the webpage. | |
| */ | |
| remove: () => void; | |
| } |
Expected behavior
The interface aligns with the docs and these parameters are defined
Metadata
Metadata
Assignees
Labels
docsImprovements or additions to documentation
Activity
aklinker1 commentedon Dec 9, 2023
Thanks, glad you like it! 😊
The docs for
createContentScriptUiandcreateContentScripIframecould be cleaned up and improved... They are confusing, and a full example would help.But it does behave as described.
I think the thing that's confusing you is that there's two mount functions. One gets passed into
createContentScriptUi, the other is called from the return value.The interface you shared is the type for the return type, which only includes
mountandremove.Right underneath it is the options interface that gets passed into the function.
wxt/src/client/content-scripts/content-script-ui.ts
Lines 147 to 173 in 59094c9
This is the interface with
mount(container): appandonRemove(app).This mount function is passed into
createContentScriptUi, and cannot be called from the return value. It is used to mount your UI inside the ShadowRoot.Anchor and alignment are used to position your UI on the page. That is why the mount function on the return type provides no arguments - you've already defined where the UI will be mounted.
onRemove is passed into
createContentScriptUi, not called on the return value.The
removefunction on the return value doesn't take any parameters because, once again, you already defined the onRemove behavior when calling thecreayeContentScriptUi.I will improve the docs and add an example. I'd really appreciate your feedback once complete, it's hard to judge how understandable docs you wrote are 😅
aklinker1 commentedon Dec 10, 2023
@AndrewWalsh I published the new docs. When you have time, let me know what you think! Thanks
https://wxt.dev/guide/content-script-ui.html
aklinker1 commentedon Dec 10, 2023
Great feedback! I'll update the docs today.
aklinker1 commentedon Dec 12, 2023
I've added your suggestions in #272.
I want to add a helper function for integrated UIs, similar to
createContentScriptUiandcreateContentScriptIframe, but I'm recognizing that adding a third function would be confusing and that the API reference is hard to follow because of how I've constructed the options type.So I think I'm going to simplify all that into a single function with a basic type for the options. Something like this: