Skip to content

Commit bd198e7

Browse files
authored
feat(reactivity): unwrap value when using set (#722)
1 parent 2c342d5 commit bd198e7

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/reactivity/set.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ export function set<T>(target: any, key: any, val: T): T {
3434
return val
3535
}
3636
if (!ob) {
37-
target[key] = val
37+
// If we are using `set` we can assume that the unwrapping is intended
38+
defineAccessControl(target, key, val)
3839
return val
3940
}
4041
defineReactive(ob.value, key, val)

test/ssr/ssrReactive.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,16 @@ describe('SSR Reactive', () => {
9090

9191
done()
9292
})
93+
94+
// #721
95+
it('should behave correctly', () => {
96+
const state = ref({ old: ref(false) })
97+
set(state.value, 'new', ref(true))
98+
// console.log(process.server, 'state.value', JSON.stringify(state.value))
99+
100+
expect(state.value).toMatchObject({
101+
old: false,
102+
new: true,
103+
})
104+
})
93105
})

0 commit comments

Comments
 (0)