Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: markRaw in watch (#903)
  • Loading branch information
yaquawa committed Feb 24, 2022
1 parent 7e31235 commit 192f4c1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/apis/watch.ts
Expand Up @@ -20,6 +20,7 @@ import {
WatcherPostFlushQueueKey,
} from '../utils/symbols'
import { getCurrentScopeVM } from './effectScope'
import { rawSet } from '../utils/sets'

export type WatchEffect = (onInvalidate: InvalidateCbRegistrator) => void

Expand Down Expand Up @@ -475,7 +476,7 @@ export function watch<T = any>(
}

function traverse(value: unknown, seen: Set<unknown> = new Set()) {
if (!isObject(value) || seen.has(value)) {
if (!isObject(value) || seen.has(value) || rawSet.has(value)) {
return value
}
seen.add(value)
Expand Down
29 changes: 29 additions & 0 deletions test/apis/watch.spec.js
Expand Up @@ -7,6 +7,7 @@ const {
set,
computed,
nextTick,
markRaw,
} = require('../../src')
const { mockWarn } = require('../helpers')

Expand Down Expand Up @@ -177,6 +178,34 @@ describe('api/watch', () => {
.then(done)
})

it('markRaw', (done) => {
const nestedState = ref(100)

const state = ref({
rawValue: markRaw({
nestedState,
}),
})

watch(
state,
() => {
spy()
},
{ deep: true }
)

function changeRawValue() {
nestedState.value = Math.random()
}

changeRawValue()

waitForUpdate(() => {
expect(spy).not.toBeCalled()
}).then(done)
})

it('should flush after render (immediate=false)', (done) => {
let rerenderedText
const vm = new Vue({
Expand Down

0 comments on commit 192f4c1

Please sign in to comment.