Skip to content

Chapter 6 of 6

Debugging, Performance, and Testing

When reactivity misbehaves, Vue exposes dedicated hooks to help you see what is happening. onRenderTracked reports every reactive dependency the component tracks during render, while onRenderTriggered reports which dependency caused a re-render. Together these debug hooks are invaluable when a component updates too often or unexpectedly, because they tell you exactly which pieces of state the reactivity system is paying attention to and which one tipped the schedule. Used sparingly during development, they cut the time spent staring at reproduction steps in half.

Performance in Vue is largely a matter of not doing unnecessary reactive work. Good habits include choosing stable, unique keys for list items, memoizing expensive derivations (either through computed or careful caching), and avoiding reactive wrapping for data that does not need it, such as large configuration blobs or third-party instances. For very large lists, virtualization keeps the rendered DOM count bounded as the user scrolls, so only what's on screen pays the mount cost. Combined with shallowRef and triggerRef() patterns for inner mutations, these choices keep large interactive surfaces responsive.

The same outward-looking mindset applies to tests. A well-tested Vue component asserts rendered behavior and emitted effects from the user's perspective rather than coupling to implementation details like which component owns which piece of state or how internal helpers are wired. Combined with the broader API surface (render functions built via Vue.compile() for runtime-compiled templates, and the layout machinery of Teleport, KeepAlive, and Suspense covered earlier), these habits make a Vue application easier to evolve and reason about as features are layered in.

All chapters
  1. 1Reactivity Essentials
  2. 2TypeScript and Component Definition
  3. 3Built-in Components and Rendering
  4. 4Transitions and List Rendering
  5. 5Routing, State Management, and SSR
  6. 6Debugging, Performance, and Testing

Drill it

Reading is not remembering. These come from the Vue Cards deck:

Q

What is <code>shallowReactive</code> in Vue?

It creates a reactive object where only the top-level properties are tracked; nested objects stay non-reactive unless wrapped separately.

Q

What is <code>triggerRef()</code> used for?

It manually notifies Vue that a shallowRef changed after you mutated its inner value without replacing the reference.

Q

What does <code>getCurrentInstance()</code> return?

It returns the current active component instance and is mainly useful in advanced framework or library code.

Q

What is <code>Vue.compile()</code>?

It is a runtime+compiler API that turns a template string into a render function at runtime.