What Is New in Vue.js 3.5
| Category | Key Updates |
|---|---|
| New Features | defineModel macro, reactive props destructure, v-model modifiers for component bindings |
| Performance | Faster computed property tracking, optimized template parsing, improved SFC compilation |
| Developer Experience | Enhanced TypeScript support, improved SFC script compilation, better IDE tooling |
| Bug Fixes | Memory leak fixes, v-model edge cases, SSR hydration improvements |
How does the new defineModel macro simplify two-way binding?
The defineModel macro is a game-changer for component authoring. It eliminates the boilerplate of declaring a prop and emitting an update event for v-model bindings. This macro automatically handles the value prop and update:value event, making two-way binding declarations much cleaner.
In practice, this means you can replace multiple lines of code with a single macro call. It works seamlessly with built-in modifiers like .trim and supports custom modifiers, which streamlines component development significantly.
<script setup>
// Before: Manual prop and event declaration
const props = defineProps(['modelValue'])
const emit = defineEmits(['update:modelValue'])
// After: Simplified with defineModel
const modelValue = defineModel()
</script>
What reactive prop destructuring improvements were introduced?
Vue 3.5 now maintains reactivity when destructuring props that contain complex types like objects or arrays. Previously, destructuring would break reactivity, forcing developers to use toRefs or work with the props object directly.
This enhancement means you can safely destructure props in your setup function without losing reactivity tracking. It's a quality-of-life improvement that makes code more intuitive and reduces potential bugs from unexpected loss of reactivity.
<script setup>
const { user, settings } = defineProps<{
user: User,
settings: Config
}>()
// Both 'user' and 'settings' remain reactive
</script>
How did computed property performance get better?
Computed properties now track dependencies more efficiently, reducing unnecessary re-computations. The optimization comes from improved dependency tracking algorithms that avoid over-triggering computed values when unrelated reactive states change.
This matters because complex applications with many computed properties will see measurable performance gains. The improvement is most noticeable in components with deep reactive object graphs where previous versions might have triggered more computations than necessary.
What TypeScript enhancements were included?
TypeScript support received several refinements, particularly around SFC script compilation and type inference. The update provides better type checking for component events, slots, and v-model bindings, catching more errors at compile time.
These improvements make the development experience more robust, especially for large codebases. The enhanced type safety reduces runtime errors and improves IDE autocompletion accuracy for Vue-specific constructs.
FAQ
Is the defineModel macro backward compatible with existing components?
Yes, the macro is additive and doesn't break existing code. You can gradually adopt it in new components or refactor existing ones without affecting functionality.
Do I need to update my build tools for Vue 3.5?
You should update Vite to the latest version and ensure your Vue-related plugins are compatible. The SFC compiler changes might require updated tooling for optimal performance.
How significant are the performance improvements for real applications?
While benchmarks show measurable gains, the impact varies by application structure. Apps with complex computed properties and deep reactive objects will benefit most from the optimized tracking.
Can I use reactive destructuring with all prop types?
Yes, the reactive destructuring works for both primitive and complex prop types. The reactivity system now preserves reactivity through destructuring assignments automatically.
What happens to the old v-model syntax with this release?
The existing v-model syntax remains fully supported. defineModel provides a cleaner alternative but doesn't deprecate or remove the traditional approach to two-way binding.