diff --git a/apps/oxfmt/src-js/libs/prettier.ts b/apps/oxfmt/src-js/libs/prettier.ts index 023c964098c41..3bef4421426de 100644 --- a/apps/oxfmt/src-js/libs/prettier.ts +++ b/apps/oxfmt/src-js/libs/prettier.ts @@ -53,8 +53,7 @@ export async function formatEmbeddedCode({ // SAFETY: `options` is created in Rust side, so it's safe to mutate here options.parser = parserName; - // Enable Tailwind CSS plugin for embedded code (e.g., html`...` in JS) - // when `options._tailwindPluginEnabled` is set + // Enable Tailwind CSS plugin for embedded code (e.g., html`...` in JS) if needed await setupTailwindPlugin(options); // NOTE: This will throw if: @@ -92,8 +91,7 @@ export async function formatFile({ // But some plugins rely on `filepath`, so we set it too options.filepath = fileName; - // Enable Tailwind CSS plugin for non-JS files - // when `options._tailwindPluginEnabled` is set + // Enable Tailwind CSS plugin for non-JS files if needed await setupTailwindPlugin(options); return prettier.format(code, options); @@ -118,8 +116,12 @@ async function loadTailwindPlugin(): Promise { if (!options._tailwindPluginEnabled) return; + // Clean up internal flag + delete options._tailwindPluginEnabled; + + // PERF: Skip loading Tailwind plugin for parsers that don't use it + if (!TAILWIND_RELEVANT_PARSERS.has(options.parser as string)) return; + const tailwindPlugin = await loadTailwindPlugin(); options.plugins = options.plugins || []; options.plugins.push(tailwindPlugin as Plugin); - - // Clean up internal flag for sure - delete options._tailwindPluginEnabled; } // ---