Skip to content

Conversation

@godgivemegift
Copy link
Contributor

🔧 Fix: Resolve Nuxt DevTools element selection conflict

Problem

The plugin was rewriting source code for all files, even those without preprocessor directives. This caused conflicts with vite-plugin-vue-tracer, breaking the source maps required for Nuxt DevTools element selection functionality.

Solution

Added hasDirective check in the transform method to skip processing when no preprocessor directives are found in the file.

Changes

  • Added directive detection after lexical analysis
  • Skip transformation for files without #if, #define, #message, or other directives
  • Preserve source map integrity for Nuxt DevTools compatibility

Code Changes

// src/core/context/index.ts:79
const hasDirective = tokens.some(token => token.type !== 'code')
if (!hasDirective)
  return

Benefits

  • ✅ Fixes Nuxt DevTools element selection functionality
  • ✅ Improves performance by avoiding unnecessary processing
  • ✅ Maintains backward compatibility
  • ✅ Preserves source maps for debugging tools

Testing

  • Test in Nuxt project with DevTools enabled
  • Verify element selection works correctly
  • Confirm no regression in directive processing

Related

Fixes compatibility issues with Nuxt DevTools and other source map dependent tools.

- Add hasDirective check in transform method to skip processing when no preprocessor directives are found
- This prevents unnecessary source map modifications that conflict with vite-plugin-vue-tracer
- Fixes Nuxt DevTools element selection functionality by preserving correct source maps
- Only processes files that actually contain #if, #define, #message, or other directives
@KeJunMao KeJunMao merged commit 8abfb24 into unplugin:main Sep 17, 2025
@godgivemegift godgivemegift deleted the fix/nuxt-devtools-sourcemap-conflict branch September 17, 2025 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants