diff --git a/packages/vite/src/plugins/composable-keys.ts b/packages/vite/src/plugins/composable-keys.ts index 4b365ee473b..6aa6eb38879 100644 --- a/packages/vite/src/plugins/composable-keys.ts +++ b/packages/vite/src/plugins/composable-keys.ts @@ -5,7 +5,7 @@ import { walk } from 'estree-walker' import MagicString from 'magic-string' import { hash } from 'ohash' import type { CallExpression } from 'estree' -import { parseURL } from 'ufo' +import { parseQuery, parseURL } from 'ufo' export interface ComposableKeysOptions { sourcemap: boolean @@ -22,8 +22,8 @@ export const composableKeysPlugin = createUnplugin((options: ComposableKeysOptio name: 'nuxt:composable-keys', enforce: 'post', transform (code, id) { - const { pathname } = parseURL(decodeURIComponent(pathToFileURL(id).href)) - if (!pathname.match(/\.(m?[jt]sx?|vue)/)) { return } + const { pathname, search } = parseURL(decodeURIComponent(pathToFileURL(id).href)) + if (!pathname.match(/\.(m?[jt]sx?|vue)/) || parseQuery(search).type === 'style') { return } if (!KEYED_FUNCTIONS_RE.test(code)) { return } const { 0: script = code, index: codeIndex = 0 } = code.match(/(?<=]*>)[\S\s.]*?(?=<\/script>)/) || [] const s = new MagicString(code) diff --git a/test/fixtures/basic/pages/keyed-composables.vue b/test/fixtures/basic/pages/keyed-composables.vue index 0ed479f62a7..f8591243efe 100644 --- a/test/fixtures/basic/pages/keyed-composables.vue +++ b/test/fixtures/basic/pages/keyed-composables.vue @@ -43,3 +43,10 @@ const { data: useLazyFetchTest2 } = await useLocalLazyFetch() {{ useLazyFetchTest1 === useLazyFetchTest2 }} + +