Skip to content

Commit

Permalink
fix: revert data sanitisation
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed May 10, 2020
1 parent 2234b3f commit 1a4bbed
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/ssr-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export function setSSRContext(ssrContext: any) {
const isProxyable = (val: unknown): val is object =>
val && typeof val === 'object'

const sanitise = (val: unknown) => val

/**
* Creates a Ref that is in sync with the client.
*/
Expand All @@ -32,7 +34,7 @@ export const ssrRef = <T>(value: T | (() => T), key?: string): Ref<T> => {
const val = getValue(value)
const _ref = ref(val)

if (value instanceof Function) data[key] = val
if (value instanceof Function) data[key] = sanitise(val)

const getProxy = <T extends Record<string | number, any>>(observable: T): T =>
new Proxy(observable, {
Expand All @@ -41,15 +43,15 @@ export const ssrRef = <T>(value: T | (() => T), key?: string): Ref<T> => {
return Reflect.get(target, prop)
},
set(obj, prop, val) {
data[key] = JSON.parse(JSON.stringify(_ref.value))
data[key] = sanitise(_ref.value)
return Reflect.set(obj, prop, val)
},
})

const proxy = computed({
get: () => (isProxyable(_ref.value) ? getProxy(_ref.value) : _ref.value),
set: v => {
data[key] = JSON.parse(JSON.stringify(v))
data[key] = sanitise(v)
_ref.value = v
},
})
Expand Down

1 comment on commit 1a4bbed

@vercel
Copy link

@vercel vercel bot commented on 1a4bbed May 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.