Vue3 Fundamentals · Composition & Reuse

markRaw

markRaw

Reactivity wraps every object it touches in a proxy. That is what makes deep updates work, and it is usually what you want. But some values should never be proxied: a third-party instance, a class with private fields, a large immutable object you only read.

markRaw marks an object so Vue skips it:

<script setup>
import { isReactive, markRaw, reactive } from 'vue';

const item = markRaw({ name: 'Vue' });
const state = reactive({ item });
</script>

Put item inside a reactive object and it stays raw; without markRaw, the same object would be proxied and isReactive(state.item) would be true. The mark travels with the object, so it stays raw wherever it is nested.

Reach for it when a value is not meant to be reactive and the proxy would only cost work or break identity. Marking a plain data object raw is a smell — that is what reactivity is for.

The Test mounts your component and checks that the value inside reactive state is not reactive. The starter omits markRaw, so the value is proxied and the Test fails. Mark it in App.vue.

Challenge

The object inside reactive state is being proxied, but it should stay raw. Export an App component from App.vue that wraps the object with markRaw before putting it in reactive state, and renders whether it is reactive.

The Test mounts your component and checks the rendered flag reads raw. The starter omits markRaw, so the value is proxied and the Test fails. Mark the object before it enters reactive state.

App.vue
<script setup>
import { isReactive, reactive } from 'vue';

const item = { name: 'Vue' };
const state = reactive({ item });
</script>

<template>
  <p>{{ isReactive(state.item) ? 'reactive' : 'raw' }}</p>
</template>

No test run yet

The Test is hidden. Run it to check the Challenge — you only see the result, never the test source.