From 944134c215f76f9cd3deea716b6936c507a9f41f Mon Sep 17 00:00:00 2001 From: James Wragg Date: Thu, 17 Nov 2022 12:13:02 +0000 Subject: [PATCH] fix(useStyleTag): allow use of existing node (#2442) fix(useStyleTag): wrap all DOM updates in condition --- packages/core/useStyleTag/index.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/core/useStyleTag/index.ts b/packages/core/useStyleTag/index.ts index d89e11203c0..5bf04d330fa 100644 --- a/packages/core/useStyleTag/index.ts +++ b/packages/core/useStyleTag/index.ts @@ -66,17 +66,20 @@ export function useStyleTag( const cssRef = ref(css) - let stop = () => {} + let stop = () => { } const load = () => { if (!document) return const el = (document.getElementById(id) || document.createElement('style')) as HTMLStyleElement - el.type = 'text/css' - el.id = id - if (options.media) - el.media = options.media - document.head.appendChild(el) + + if (!el.isConnected) { + el.type = 'text/css' + el.id = id + if (options.media) + el.media = options.media + document.head.appendChild(el) + } if (isLoaded.value) return