Diagram comparing ref() deep proxying every nested object versus shallowRef() wrapping only the top level

Most Vue 3 code reaches for ref() by reflex, and 95% of the time that is correct. But ref() makes its value deeply reactive, and on large data structures or third-party class instances that deep proxy is either pure overhead or an actual bug. shallowRef() is the escape hatch — and it has sharp edges worth knowing before you use it.

What ref() actually does to your object

When you pass an object to ref(), .value does not give you your object back. It gives you a reactive() proxy of it:

import { ref, isReactive, toRaw } from 'vue'

const raw = { user: { name: 'Ada' } }
const state = ref(raw)

console.log(state.value === raw)        // false — it's a Proxy
console.log(isReactive(state.value))    // true
console.log(isReactive(state.value.user)) // true — nested too
console.log(toRaw(state.value) === raw) // true — the original is in there

An important nuance that people get wrong in both directions: Vue 3 does not walk your whole object graph up front. Nested proxies are created lazily, on first property access. So ref(hugeObject) is cheap to create. The cost shows up later, at read time — and rendering a big list reads everything.

Where the cost actually lands

const rows = ref(await fetchRows())  // 10,000 rows × 12 fields

Render that in a table and Vue will, per row:

  • allocate a Proxy wrapper for the row object (cached, but still allocated once per row),
  • run a get trap for every field you read,
  • register a dependency entry for every field you read, so it can re-render on change.

That is 120,000 tracked dependencies for data you never mutate. It costs memory, it costs GC pressure, and it slows down every subsequent re-render because the dep bookkeeping grows.

shallowRef() opts out of all of it:

import { shallowRef } from 'vue'

const rows = shallowRef(await fetchRows())
// rows.value is the RAW array. No proxies, no per-field tracking.

Only one thing is reactive now: replacing .value itself.

rows.value = await fetchRows()  // ✅ triggers re-render

Trap 1: in-place mutation is silently ignored

This is the number one bug people ship with shallowRef:

const rows = shallowRef([{ id: 1, done: false }])

rows.value[0].done = true   // ❌ nothing re-renders
rows.value.push({ id: 2 })  // ❌ nothing re-renders either

The data is updated in memory — the UI just never hears about it, which makes it a delightfully confusing bug. Two correct fixes:

Option A — immutable replacement (preferred). Replace .value with a new reference:

rows.value = rows.value.map(r =>
  r.id === 1 ? { ...r, done: true } : r
)

Note that Object.is is used for the change check, so you must hand it a genuinely new reference. rows.value = rows.value does nothing.

Option B — triggerRef(). Mutate in place, then force the notification. This is the cheap path when copying a 10k-row array would itself be the bottleneck:

import { triggerRef } from 'vue'

rows.value[0].done = true
triggerRef(rows)  // ✅ manually flush the update

triggerRef re-runs every effect that depends on that ref — it is a blunt “assume everything changed” signal, which is exactly what you want here.

Trap 2: shallowRef is not shallowReactive

They sound like siblings but the boundary sits in a different place:

  • shallowRef(obj) — nothing inside is reactive. Only ref.value = newObj triggers.
  • shallowReactive(obj) — root-level properties are reactive; anything nested is raw.
import { shallowRef, shallowReactive } from 'vue'

const a = shallowRef({ count: 0 })
a.value.count++          // ❌ no update

const b = shallowReactive({ count: 0, deep: { n: 0 } })
b.count++                // ✅ updates
b.deep.n++               // ❌ no update (nested is raw)

If you want “top-level fields reactive, big payload not”, shallowReactive is usually the better fit than shallowRef.

Trap 3: deep ref breaks identity checks

This one bites even in code that never touches shallowRef, and it is worth internalising. Because ref() hands out proxies, reference equality against your raw objects fails:

const rawItem = { id: 1 }
const list = ref([rawItem])

list.value[0] === rawItem              // false 😱
list.value.includes(rawItem)           // false
toRaw(list.value[0]) === rawItem       // true ✅

So selected === item comparisons, Set/Map keys, and indexOf lookups can all quietly misbehave. Fix it by comparing IDs, by wrapping with toRaw(), or by using shallowRef where identity matters more than deep tracking.

The other big win: third-party instances

Deep-proxying a class instance is not just slow, it can genuinely break the library. Chart.js, Monaco, Leaflet, a WebSocket, a video player — these keep internal state, use private fields, and sometimes compare this identity. Wrapping them in a reactive proxy is asking for trouble:

import { shallowRef, markRaw, onMounted } from 'vue'

const chart = shallowRef(null)

onMounted(() => {
  // shallowRef alone is enough here; markRaw is belt-and-braces
  // for when the instance also gets stored inside a reactive() object.
  chart.value = markRaw(new Chart(canvasEl, config))
})

markRaw(obj) permanently flags an object as “never make me reactive”, so even reactive({ chart }) will leave it alone. Use shallowRef for the slot, markRaw for the object itself.

Decision cheat sheet

  • ref — default. Form state, small objects, anything you mutate field by field. Do not optimise this away.
  • shallowRef — large read-mostly payloads (tables, parsed JSON, geo data), or a slot holding a class instance. Update by replacing .value, or mutate + triggerRef.
  • shallowReactive — you want reactive top-level fields but a raw nested payload.
  • markRaw — the object must never be proxied, wherever it ends up stored.
  • toRaw — you need the original reference back out of a deep ref/reactive (identity checks, passing to a library, structured cloning).

Rule of thumb

Reach for shallowRef when the data is big and replaced wholesale, or when the value is an object that owns its own internals. Everywhere else, ref is correct and micro-optimising it will only cost you a bug where an update silently does not render.

And if you do go shallow: write a comment. Six weeks from now, rows.value[0].done = true will look completely reasonable to whoever reads it — including you.