Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(reactivity): unwrap value when using set #722

Merged
merged 1 commit into from Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/reactivity/set.ts
Expand Up @@ -34,7 +34,8 @@ export function set<T>(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)
Expand Down
12 changes: 12 additions & 0 deletions test/ssr/ssrReactive.spec.ts
Expand Up @@ -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,
})
})
})