From bd198e775136a468f6b6494fa0dc2d40e8bf550c Mon Sep 17 00:00:00 2001 From: Carlos Rodrigues Date: Fri, 4 Jun 2021 23:01:49 +0100 Subject: [PATCH] feat(reactivity): unwrap value when using `set` (#722) --- src/reactivity/set.ts | 3 ++- test/ssr/ssrReactive.spec.ts | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/reactivity/set.ts b/src/reactivity/set.ts index f2a733cd..f33032d2 100644 --- a/src/reactivity/set.ts +++ b/src/reactivity/set.ts @@ -34,7 +34,8 @@ export function set(target: any, key: any, val: T): T { return val } if (!ob) { - target[key] = val + // If we are using `set` we can assume that the unwrapping is intended + defineAccessControl(target, key, val) return val } defineReactive(ob.value, key, val) diff --git a/test/ssr/ssrReactive.spec.ts b/test/ssr/ssrReactive.spec.ts index 5c8510ca..b4325fa3 100644 --- a/test/ssr/ssrReactive.spec.ts +++ b/test/ssr/ssrReactive.spec.ts @@ -90,4 +90,16 @@ describe('SSR Reactive', () => { done() }) + + // #721 + it('should behave correctly', () => { + const state = ref({ old: ref(false) }) + set(state.value, 'new', ref(true)) + // console.log(process.server, 'state.value', JSON.stringify(state.value)) + + expect(state.value).toMatchObject({ + old: false, + new: true, + }) + }) })