Skip to content

Commit

Permalink
fix: dialog crash [close #358]
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works committed Nov 5, 2019
1 parent 1949de8 commit 023a3fb
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/utils/jss/ShadowRootPortal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,30 @@ untilDocumentReady().then(() => {
document.body.appendChild(div)
})

globalThis.getComputedStyle = new Proxy(globalThis.getComputedStyle || (() => {}), {
apply(target, thisArg, args) {
if (args[0] === proxy) args[0] = document.body
return Reflect.apply(target, thisArg, args)
},
})

const proxy = new Proxy(document.body, {
get(target, key, receiver) {
const value = Reflect.get(target, key)
if (typeof value === 'function')
return function(...args: any[]) {
console.log(...args)
return Reflect.apply(value, shadow, args)
}
return value
},
set(target, key, value, receiver) {
return Reflect.set(document.body, key, value, document.body)
},
})
export function PortalShadowRoot() {
if (GetContext() === 'options') return document.body
return new Proxy(document.body, {
get(target, key, receiver) {
const value = Reflect.get(target, key)
if (typeof value === 'function')
return function(...args: any[]) {
console.log(...args)
return Reflect.apply(value, shadow, args)
}
return value
},
set(target, key, value, receiver) {
return Reflect.set(document.body, key, value, document.body)
},
})
return proxy
}

Object.defineProperties(ShadowRoot.prototype, {
Expand Down

0 comments on commit 023a3fb

Please sign in to comment.