Skip to content

Commit 295b5ec

Browse files
authored
fix(reactivity): ensure markRaw objects are not reactive (#12824)
close #12807
1 parent 0c8dd94 commit 295b5ec

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

packages/reactivity/__tests__/reactive.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,13 @@ describe('reactivity/reactive', () => {
301301
expect(() => markRaw(obj)).not.toThrowError()
302302
})
303303

304+
test('should not markRaw object as reactive', () => {
305+
const a = reactive({ a: 1 })
306+
const b = reactive({ b: 2 }) as any
307+
b.a = markRaw(toRaw(a))
308+
expect(b.a === a).toBe(false)
309+
})
310+
304311
test('should not observe non-extensible objects', () => {
305312
const obj = reactive({
306313
foo: Object.preventExtensions({ a: 1 }),

packages/reactivity/src/reactive.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,16 +279,16 @@ function createReactiveObject(
279279
) {
280280
return target
281281
}
282-
// target already has corresponding Proxy
283-
const existingProxy = proxyMap.get(target)
284-
if (existingProxy) {
285-
return existingProxy
286-
}
287282
// only specific value types can be observed.
288283
const targetType = getTargetType(target)
289284
if (targetType === TargetType.INVALID) {
290285
return target
291286
}
287+
// target already has corresponding Proxy
288+
const existingProxy = proxyMap.get(target)
289+
if (existingProxy) {
290+
return existingProxy
291+
}
292292
const proxy = new Proxy(
293293
target,
294294
targetType === TargetType.COLLECTION ? collectionHandlers : baseHandlers,

0 commit comments

Comments
 (0)