From 192f4c1f91a417b771319d16f0bf77673972708e Mon Sep 17 00:00:00 2001 From: wang Date: Fri, 25 Feb 2022 02:25:47 +0900 Subject: [PATCH] fix: markRaw in watch (#903) --- src/apis/watch.ts | 3 ++- test/apis/watch.spec.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/apis/watch.ts b/src/apis/watch.ts index 29d2ebef..517e78cf 100644 --- a/src/apis/watch.ts +++ b/src/apis/watch.ts @@ -20,6 +20,7 @@ import { WatcherPostFlushQueueKey, } from '../utils/symbols' import { getCurrentScopeVM } from './effectScope' +import { rawSet } from '../utils/sets' export type WatchEffect = (onInvalidate: InvalidateCbRegistrator) => void @@ -475,7 +476,7 @@ export function watch( } function traverse(value: unknown, seen: Set = new Set()) { - if (!isObject(value) || seen.has(value)) { + if (!isObject(value) || seen.has(value) || rawSet.has(value)) { return value } seen.add(value) diff --git a/test/apis/watch.spec.js b/test/apis/watch.spec.js index e01b3c3d..3462a7fc 100644 --- a/test/apis/watch.spec.js +++ b/test/apis/watch.spec.js @@ -7,6 +7,7 @@ const { set, computed, nextTick, + markRaw, } = require('../../src') const { mockWarn } = require('../helpers') @@ -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({