Files
stack/packages/mosaic/framework/skills/vue-best-practices/reference/no-passive-with-prevent.md
T
fargo 1a822493ba format: apply repo prettier (3.8.1) to the folded skills tree
963 markdown files reformatted with the repository's pinned prettier so
pnpm format:check covers the folded tree like every other repo file.

The formatter's embedded-language pass also normalized code fences
(TS semicolons, closed HTML tags in examples, lowercased CSS hex colors,
one renumbered list that skipped an index). Alphanumeric token deltas vs
the fold commit were audited file-by-file; all are formatter-equivalent
markup normalizations plus the four sanitized skills.
2026-08-19 14:37:17 -05:00

3.8 KiB

title, impact, impactDescription, type, tags
title impact impactDescription type tags
Never Use .passive and .prevent Together HIGH Conflicting modifiers cause .prevent to be ignored and trigger browser warnings gotcha
vue3
events
modifiers
scroll
touch
performance

Never Use .passive and .prevent Together

Impact: HIGH - The .passive modifier tells the browser you will NOT call preventDefault(), while .prevent does exactly that. Using them together causes .prevent to be ignored and triggers browser console warnings. This is a logical contradiction that leads to broken event handling.

Task Checklist

  • Never combine .passive and .prevent on the same event
  • Use .passive for scroll/touch events where you want better performance
  • Use .prevent when you need to stop the default browser action
  • If you need conditional prevention, handle it in JavaScript without .passive

Incorrect:

<!-- WRONG: Conflicting modifiers -->
<template>
  <div @scroll.passive.prevent="handleScroll">
    <!-- .prevent will be IGNORED -->
    <!-- Browser shows warning -->
  </div>
</template>
<!-- WRONG: On touch events -->
<template>
  <div @touchstart.passive.prevent="handleTouch">
    <!-- Cannot prevent default - passive already promised not to -->
  </div>
</template>
<!-- WRONG: On wheel events -->
<template>
  <div @wheel.passive.prevent="handleWheel">
    <!-- Broken: will scroll anyway despite .prevent -->
  </div>
</template>

Correct:

<!-- CORRECT: Use .passive for performance (no prevention needed) -->
<template>
  <div @scroll.passive="handleScroll">
    <!-- Good for scroll tracking without blocking -->
  </div>
</template>
<!-- CORRECT: Use .prevent when you need to prevent default -->
<template>
  <form @submit.prevent="handleSubmit">
    <!-- Correctly prevents form submission -->
  </form>
</template>
<!-- CORRECT: For touch events where you need to prevent -->
<template>
  <div @touchmove="handleTouchMove">
    <!-- Handle prevention conditionally in JS -->
  </div>
</template>

<script setup>
  function handleTouchMove(event) {
    if (shouldPreventScroll.value) {
      event.preventDefault();
    }
    // ... handle touch
  }
</script>

Understanding .passive

// .passive tells the browser:
// "I promise I won't call preventDefault()"

// This allows the browser to:
// 1. Start scrolling immediately without waiting for JS
// 2. Improve scroll performance, especially on mobile
// 3. Reduce jank and stuttering

// Equivalent to:
element.addEventListener('scroll', handler, { passive: true });

When to Use .passive

<!-- Good use cases for .passive -->

<!-- Scroll tracking analytics -->
<div @scroll.passive="trackScrollPosition">
  <!-- Touch gesture detection (no prevention needed) -->
  <div @touchmove.passive="detectGesture">
    <!-- Wheel event monitoring -->
    <div @wheel.passive="monitorWheel"></div>
  </div>
</div>

When to Use .prevent (Without .passive)

<!-- Good use cases for .prevent -->

<!-- Form submission -->
<form @submit.prevent="handleSubmit">
  <!-- Link clicks with custom navigation -->
  <a @click.prevent="navigate">
    <!-- Preventing context menu -->
    <div @contextmenu.prevent="showCustomMenu"></div
  ></a>
</form>

Browser Warning

When you combine .passive and .prevent, the browser console shows:

[Intervention] Unable to preventDefault inside passive event listener
due to target being treated as passive.

Reference