Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

fix: correctly proxify functions within ssrRef #561

Merged
merged 1 commit into from
Oct 11, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/runtime/composables/ssr-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ export const ssrRef = <T>(value: T | (() => T), key?: string): Ref<T> => {
track()
if (isProxyable(target[prop]))
return getProxy(track, trigger, target[prop])
return Reflect.get(target, prop)

const value = Reflect.get(target, prop)

return typeof value === 'function' ? value.bind(target) : value
},
set(obj, prop, newVal) {
const result = Reflect.set(obj, prop, newVal)
Expand Down
10 changes: 10 additions & 0 deletions test/unit/__snapshots__/ssr-ref.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ Object {
}
`;

exports[`ssrRef reactivity ssrRefs react to constructors 1`] = `
RefImpl {
"value": bound Object {
"testMap": Map {
"john" => "doe",
},
},
}
`;

exports[`ssrRef reactivity ssrRefs react to deep change in array state 1`] = `
Object {
"nuxt": Object {
Expand Down
9 changes: 9 additions & 0 deletions test/unit/ssr-ref.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,13 @@ describe('ssrRef reactivity', () => {

expect(ssrContext).toMatchSnapshot()
})

test('ssrRefs react to constructors', async () => {
const testMap = new Map()
testMap.set('john', 'doe')

const obj = ssrRef({ testMap }, 'obj')

expect(obj).toMatchSnapshot()
})
})