瀏覽代碼

fix(reactivity): add `__v_skip` flag to `Dep` to prevent reactive conversion (#12804)

close #12803
SerKo 10 月之前
父節點
當前提交
e8d8f5f604
共有 2 個文件被更改,包括 21 次插入0 次删除
  1. 15 0
      packages/reactivity/__tests__/readonly.spec.ts
  2. 6 0
      packages/reactivity/src/dep.ts

+ 15 - 0
packages/reactivity/__tests__/readonly.spec.ts

@@ -8,7 +8,9 @@ import {
   reactive,
   readonly,
   ref,
+  shallowRef,
   toRaw,
+  triggerRef,
 } from '../src'
 
 /**
@@ -520,3 +522,16 @@ describe('reactivity/readonly', () => {
     expect(r.value).toBe(ro)
   })
 })
+
+test('should be able to trigger with triggerRef', () => {
+  const r = shallowRef({ a: 1 })
+  const ror = readonly(r)
+  let dummy
+  effect(() => {
+    dummy = ror.value.a
+  })
+  r.value.a = 2
+  expect(dummy).toBe(1)
+  triggerRef(ror)
+  expect(dummy).toBe(2)
+})

+ 6 - 0
packages/reactivity/src/dep.ts

@@ -93,6 +93,12 @@ export class Dep {
    */
   sc: number = 0
 
+  /**
+   * @internal
+   */
+  readonly __v_skip = true
+  // TODO isolatedDeclarations ReactiveFlags.SKIP
+
   constructor(public computed?: ComputedRefImpl | undefined) {
     if (__DEV__) {
       this.subsHead = undefined