This content originally appeared on DEV Community and was authored by Eugene Kopich
We are excited to announce the release of Vue.js 3.2 "Quintessential Quintuplets"! This release includes many significant new features and performance improvements, and contains no breaking changes.
New SFC Features
Two new features for Single File Components (SFCs, aka .vue
files) have graduated from experimental status and are now considered stable:
<script setup>
is a compile-time syntactic sugar that greatly improves the ergonomics when using Composition API inside SFCs.<style> v-bind
enables component state-driven dynamic CSS values in SFC<style>
tags.
Here is an example component using these two new features together:
<script setup>
import { ref } from 'vue'
const color = ref('red')
</script>
<template>
<button @click="color = color === 'red' ? 'green' : 'red'">
Color is: {{ color }}
</button>
</template>
<style scoped>
button {
color: v-bind(color);
}
</style>
Try it out in the SFC Playground, or read their respective documentations:
Building on top of <script setup>
, we also have a new RFC for improving the ergonomics of ref usage with compiler-enabled sugar - please share your feedback here.
Web Components
Vue 3.2 introduces a new defineCustomElement
method for easily creating native custom elements using Vue component APIs:
import { defineCustomElement } from 'vue'
const MyVueElement = defineCustomElement({
// normal Vue component options here
})
// Register the custom element.
// After registration, all `<my-vue-element>` tags
// on the page will be upgraded.
customElements.define('my-vue-element', MyVueElement)
This API allows develpers to create Vue-powered UI component libraries that can be used with any framework, or no framework at all. We have also added a new section in our docs on consuming and creating Web Components in Vue.
Performance Improvements
3.2 includes some significant performance improvements to Vue's reactivity system, thanks to the great work by @basvanmeurs. Specifically:
- More efficient ref implementation (~260% faster read / ~50% faster write)
- ~40% faster dependency tracking
- ~17% less memory usage
The template compiler also received a number of improvements:
- ~200% faster creation of plain element VNodes
- More aggressive constant hoisting [1] [2]
Finally, there is a new v-memo
directive that provides the ability to memoize part of the template tree. A v-memo
hit allows Vue to skip not only the Virtual DOM diffing, but the creation of new VNodes altogether. Although rarely needed, it provides an escape hatch to squeeze out maximum performance in certain scenarios, for example large v-for
lists.
The usage of v-memo
, which is a one-line addition, places Vue among the fastest mainstream frameworks in js-framework-benchmark:
Server-side Rendering
The @vue/server-renderer
package in 3.2 now ships an ES module build which is also decoupled from Node.js built-ins. This makes it possible to bundle and leverage @vue/server-renderer
for use inside non-Node.js runtimes such as CloudFlare Workers or Service Workers.
We also improved the streaming render APIs, with new methods for rendering to the Web Streams API. Check out the documentation of @vue/server-renderer
for more details.
Effect Scope API
3.2 introduces a new Effect Scope API for directly controlling the disposal timing of reactive effects (computed and watchers). It makes it easier to leverage Vue's reactivity API out of a component context, and also unlocks some advanced use cases inside components.
This is low-level API largely intended for library authors, so it's recommended to read the feature's RFC for the motivation and use cases of this feature.
CHANGELOG
Compatibility Notes
This release contains no public API breakage. However, there are a few compatibility related notes:
- Due to usage of new runtime helpers, code generated by the template compiler in >= 3.2 will not be compatible with runtime < 3.2.
This only affects cases where there is a version mismatch between the compiler and the runtime. The most common case is libraries that ship pre-compiled Vue components. If you are a library author and ship code pre-compiled by Vue >= 3.2, your library will be only compatible Vue >= 3.2.
- This release ships TypeScript typings that rely on Template Literal Types and requires TS >= 4.1.
Features
SFC
- remove experimental status of
<script setup>
(27104ea) (Docs) (RFC) - remove experimental status for sfc
<style>
v-bind (3b38c9a) (Docs) (RFC) - support non-explicit type imports in
<script setup>
by avoiding exposing unused imports to template during dev (5a3ccfd), closes #3183 - support namespaced component tags when using
<script setup>
(e5a4412) - (experimental) new ref sugar (562bddb) (RFC)
Custom Elements
Reactivity
- new
effectScope
API (#2195) (f5617fc) (RFC) - support
onTrack/onTrigger
debug options forcomputed
(5cea9a1)
SSR
- server-renderer: decouple esm build from Node + improve stream API (0867222), closes #3467 #3111 #3460 (Docs)
Generic
- New
v-memo
directive (3b64508) (Docs) - support
v-bind
.prop & .attr modifiers (1c7d737) (Docs) - add
watchPostEffect
API (42ace95) (Docs) - add
watchSyncEffect
API (d87d059) (Docs) - unwrap refs in toDisplayString (f994b97)
- allow
compilerOptions.comments
to affect comment inclusion in dev (#4115) (dd0f9d1), closes #3392 #3395
Types
Performance Improvements
- reactivity: improve reactive effect memory usage (#4001) (87f69fd), closes #2345
- reactivity: ref-specific track/trigger and miscellaneous optimizations (#3995) (6431040)
- reactivity: use bitwise dep markers to optimize re-tracking (#4017) (6cf2377)
- compiler-core/runtime-core: improve VNode creation performance with compiler hints (#3334) (ceff899)
- compiler-core: also hoist all-static children array (b7ea7c1)
- compiler-core: hoist dynamic props lists (02339b6)
- compiler-sfc: ignore empty blocks (#3520) (b771fdb)
This content originally appeared on DEV Community and was authored by Eugene Kopich
Eugene Kopich | Sciencx (2021-08-10T03:26:05+00:00) Vue 3.2 Released!. Retrieved from https://www.scien.cx/2021/08/10/vue-3-2-released/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.