Skip to content

Commit 192f4c1

Browse files
authored
fix: markRaw in watch (#903)
1 parent 7e31235 commit 192f4c1

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/apis/watch.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
WatcherPostFlushQueueKey,
2121
} from '../utils/symbols'
2222
import { getCurrentScopeVM } from './effectScope'
23+
import { rawSet } from '../utils/sets'
2324

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

@@ -475,7 +476,7 @@ export function watch<T = any>(
475476
}
476477

477478
function traverse(value: unknown, seen: Set<unknown> = new Set()) {
478-
if (!isObject(value) || seen.has(value)) {
479+
if (!isObject(value) || seen.has(value) || rawSet.has(value)) {
479480
return value
480481
}
481482
seen.add(value)

test/apis/watch.spec.js

+29
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const {
77
set,
88
computed,
99
nextTick,
10+
markRaw,
1011
} = require('../../src')
1112
const { mockWarn } = require('../helpers')
1213

@@ -177,6 +178,34 @@ describe('api/watch', () => {
177178
.then(done)
178179
})
179180

181+
it('markRaw', (done) => {
182+
const nestedState = ref(100)
183+
184+
const state = ref({
185+
rawValue: markRaw({
186+
nestedState,
187+
}),
188+
})
189+
190+
watch(
191+
state,
192+
() => {
193+
spy()
194+
},
195+
{ deep: true }
196+
)
197+
198+
function changeRawValue() {
199+
nestedState.value = Math.random()
200+
}
201+
202+
changeRawValue()
203+
204+
waitForUpdate(() => {
205+
expect(spy).not.toBeCalled()
206+
}).then(done)
207+
})
208+
180209
it('should flush after render (immediate=false)', (done) => {
181210
let rerenderedText
182211
const vm = new Vue({

0 commit comments

Comments
 (0)