From 86a4a1b41ed3ac392fc96c8a5bbdd49734c233cf Mon Sep 17 00:00:00 2001 From: ArjixWasTaken Date: Sun, 12 Oct 2025 03:16:12 +0300 Subject: [PATCH] proper support for tree-shakeable Lit components --- src/plugins/navigation/index.tsx | 14 ++--- .../renderer/components/LyricsPicker.tsx | 63 ++++++++++--------- src/solit.tsx | 26 ++++++++ 3 files changed, 65 insertions(+), 38 deletions(-) create mode 100644 src/solit.tsx diff --git a/src/plugins/navigation/index.tsx b/src/plugins/navigation/index.tsx index 410038c8..77e869b9 100644 --- a/src/plugins/navigation/index.tsx +++ b/src/plugins/navigation/index.tsx @@ -6,6 +6,7 @@ import { IconChevronRight } from '@mdui/icons/chevron-right.js'; import { createPlugin } from '@/utils'; import { t } from '@/i18n'; +import { LitElementWrapper } from '@/solit'; export default createPlugin({ name: () => t('plugins.navigation.name'), @@ -17,9 +18,6 @@ export default createPlugin({ renderer: { buttonContainer: document.createElement('div'), start() { - const doNotTreeShake = [IconChevronLeft, IconChevronRight]; - ((a) => {})(doNotTreeShake); - if (!this.buttonContainer) { this.buttonContainer = document.createElement('div'); } @@ -31,8 +29,9 @@ export default createPlugin({ content={t('plugins.navigation.templates.back.title')} > history.back()}> - @@ -40,8 +39,9 @@ export default createPlugin({ content={t('plugins.navigation.templates.forward.title')} > history.forward()}> - diff --git a/src/plugins/synced-lyrics/renderer/components/LyricsPicker.tsx b/src/plugins/synced-lyrics/renderer/components/LyricsPicker.tsx index dd95f59d..3e18626b 100644 --- a/src/plugins/synced-lyrics/renderer/components/LyricsPicker.tsx +++ b/src/plugins/synced-lyrics/renderer/components/LyricsPicker.tsx @@ -23,6 +23,8 @@ import { IconError } from '@mdui/icons/error.js'; import { IconStar } from '@mdui/icons/star.js'; import { IconStarBorder } from '@mdui/icons/star-border.js'; +import { LitElementWrapper } from '@/solit'; + import { type ProviderName, ProviderNames, @@ -58,7 +60,9 @@ const providerBias = (p: ProviderName) => (lyricsStore.lyrics[p].state === 'done' ? 1 : -1) + (lyricsStore.lyrics[p].data?.lines?.length ? 2 : -1) + // eslint-disable-next-line prettier/prettier - (lyricsStore.lyrics[p].data?.lines?.length && p === ProviderNames.YTMusic ? 1 : 0) + + (lyricsStore.lyrics[p].data?.lines?.length && p === ProviderNames.YTMusic + ? 1 + : 0) + (lyricsStore.lyrics[p].data?.lyrics ? 1 : -1); const pickBestProvider = () => { @@ -82,17 +86,6 @@ const [hasManuallySwitchedProvider, setHasManuallySwitchedProvider] = export const LyricsPicker = (props: { setStickRef: Setter; }) => { - const doNotTreeShake = [ - IconChevronLeft, - IconChevronRight, - IconCheckCircle, - IconWarning, - IconError, - IconStar, - IconStarBorder, - ]; - ((a) => {})(doNotTreeShake); - const [videoId, setVideoId] = createSignal(null); const [starredProvider, setStarredProvider] = createSignal(null); @@ -200,10 +193,13 @@ export const LyricsPicker = (props: {
-
@@ -234,9 +230,9 @@ export const LyricsPicker = (props: { /> - - - @@ -270,10 +266,12 @@ export const LyricsPicker = (props: { /> } + fallback={ + + } when={starredProvider() === provider()} > - +
@@ -298,10 +296,13 @@ export const LyricsPicker = (props: {
-
diff --git a/src/solit.tsx b/src/solit.tsx new file mode 100644 index 00000000..bcfaf398 --- /dev/null +++ b/src/solit.tsx @@ -0,0 +1,26 @@ +// A SolidJS wrapper for a LitElement + +import { createSignal, onMount, Show } from 'solid-js'; +import { Dynamic } from 'solid-js/web'; + +export interface LitElementWrapperProps { + elementClass: CustomElementConstructor; + props?: Record; +} + +export const LitElementWrapper = (props: LitElementWrapperProps) => { + const [tagName, setTagName] = createSignal(null); + + onMount(() => { + // Create instance to discover tag name + const el = new props.elementClass(); + setTagName(el.tagName.toLowerCase()); + el.remove(); + }); + + return ( + + + + ); +};