Skip to content

Commit

Permalink
fix(content): fix dynamic document.body #150
Browse files Browse the repository at this point in the history
use up-to-date document.doby in case it got replaced by other scripts
  • Loading branch information
crimx committed Jun 27, 2018
1 parent ca0d8a1 commit 27f2787
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/content/components/DictPanelPortal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,16 @@ export default class DictPanelPortal extends React.Component<DictPanelPortalProp
}

mountEL = () => {
// body could be replaced by other scripts
if (!isSaladictPopupPage) { this.root = document.body }
this.root.appendChild(this.el)
this.isMount = true
}

unmountEL = () => {
this.frame = null
// body could be replaced by other scripts
if (!isSaladictPopupPage) { this.root = document.body }
this.root.removeChild(this.el)
this.isMount = false
}
Expand Down
7 changes: 3 additions & 4 deletions src/content/components/SaladBowlPortal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ interface SaladBowlPortalProps {
}

export default class SaladBowlPortal extends React.Component<SaladBowlPortalProps> {
root = document.body
el = document.createElement('div')
bowl: null | HTMLElement = null
isMount = false
Expand Down Expand Up @@ -44,7 +43,7 @@ export default class SaladBowlPortal extends React.Component<SaladBowlPortalProp
}

componentWillUnmount () {
this.root.removeChild(this.el)
document.body.removeChild(this.el)
}

renderBowl = () => {
Expand All @@ -56,12 +55,12 @@ export default class SaladBowlPortal extends React.Component<SaladBowlPortalProp
const { shouldShow, isAnimation } = this.props
if (shouldShow) {
if (!this.isMount) {
this.root.appendChild(this.el)
document.body.appendChild(this.el)
this.isMount = true
}
} else {
if (this.isMount) {
this.root.removeChild(this.el)
document.body.removeChild(this.el)
this.isMount = false
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/content/components/WordEditorPortal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export interface WordEditorPortalProps extends Omit<

export default class WordEditorPortal extends React.Component<WordEditorPortalProps> {
isMount = false
root = document.body
el = document.createElement('div')
frameHead = '<meta name="viewport" content="width=device-width, initial-scale=1">\n' + (
process.env.NODE_ENV === 'production'
Expand Down Expand Up @@ -52,12 +51,12 @@ export default class WordEditorPortal extends React.Component<WordEditorPortalPr
}

mountEL = () => {
this.root.appendChild(this.el)
document.body.appendChild(this.el)
this.isMount = true
}

unmountEL = () => {
this.root.removeChild(this.el)
document.body.removeChild(this.el)
this.isMount = false
}

Expand Down

0 comments on commit 27f2787

Please sign in to comment.