Fix flicker of undefined

page-actions
bat 3 years ago
parent 4782c72726
commit 911f90714d

@ -57,6 +57,8 @@ export class FileGroupPage extends HTMLElement {
super() super()
this.attachShadow({mode: 'open'}) this.attachShadow({mode: 'open'})
this.csp = "default-src 'self' 'unsafe-inline' 'unsafe-eval'" this.csp = "default-src 'self' 'unsafe-inline' 'unsafe-eval'"
this.viewLoaded = false
this.onceOnLoaded = undefined
} }
connectedCallback() { connectedCallback() {
@ -136,7 +138,11 @@ export class FileGroupPage extends HTMLElement {
frame.srcdoc = frameHtml frame.srcdoc = frameHtml
} }
frame.addEventListener('load', () => { frame.addEventListener('load', () => {
this.displayView() this.viewLoaded = true
if (this.onceOnLoaded) {
this.onceOnLoaded()
this.onceOnLoaded = undefined
}
}) })
this.viewFrame = frame this.viewFrame = frame
this.shadowRoot.append(frame) this.shadowRoot.append(frame)
@ -144,9 +150,17 @@ export class FileGroupPage extends HTMLElement {
displayView(doc) { displayView(doc) {
const msg = ['srcdoc', doc] const msg = ['srcdoc', doc]
this.viewFrame.contentWindow.postMessage( if (this.viewLoaded) {
msg, '*' this.viewFrame.contentWindow.postMessage(
) msg, '*'
)
} else {
this.onceOnLoaded = () => {
this.viewFrame.contentWindow.postMessage(
msg, '*'
)
}
}
} }
async displayEdit() { async displayEdit() {

Loading…
Cancel
Save