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

Commit 016ff0a

Browse files
authored
fix: correctly proxify functions within ssrRef (#561)
1 parent 88fcf02 commit 016ff0a

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/runtime/composables/ssr-ref.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ export const ssrRef = <T>(value: T | (() => T), key?: string): Ref<T> => {
107107
track()
108108
if (isProxyable(target[prop]))
109109
return getProxy(track, trigger, target[prop])
110-
return Reflect.get(target, prop)
110+
111+
const value = Reflect.get(target, prop)
112+
113+
return typeof value === 'function' ? value.bind(target) : value
111114
},
112115
set(obj, prop, newVal) {
113116
const result = Reflect.set(obj, prop, newVal)

test/unit/__snapshots__/ssr-ref.spec.ts.snap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ Object {
1111
}
1212
`;
1313

14+
exports[`ssrRef reactivity ssrRefs react to constructors 1`] = `
15+
RefImpl {
16+
"value": bound Object {
17+
"testMap": Map {
18+
"john" => "doe",
19+
},
20+
},
21+
}
22+
`;
23+
1424
exports[`ssrRef reactivity ssrRefs react to deep change in array state 1`] = `
1525
Object {
1626
"nuxt": Object {

test/unit/ssr-ref.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,13 @@ describe('ssrRef reactivity', () => {
5252

5353
expect(ssrContext).toMatchSnapshot()
5454
})
55+
56+
test('ssrRefs react to constructors', async () => {
57+
const testMap = new Map()
58+
testMap.set('john', 'doe')
59+
60+
const obj = ssrRef({ testMap }, 'obj')
61+
62+
expect(obj).toMatchSnapshot()
63+
})
5564
})

0 commit comments

Comments
 (0)