theme: fix issues with autoreload (correctly detect when stylesheet is reloaded)
This commit is contained in:
parent
0e1ef27eb5
commit
0e3119226b
2 changed files with 30 additions and 10 deletions
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
- bug fixes
|
||||
- app address / qr code not updating when network changes
|
||||
- issue after theme auto reload (broken grid, colors not updated)
|
||||
|
||||
- custom module
|
||||
- provide error backtraces in module.exports functions
|
||||
|
|
|
|||
|
|
@ -95,18 +95,37 @@ module.exports = {
|
|||
|
||||
reloadCss: function(){
|
||||
var queryString = '?__OSC_ASSET__=1&reload=' + Date.now()
|
||||
DOM.each(document, 'link[rel="stylesheet"][hot-reload]', (el)=>{
|
||||
el.href = el.href.replace(/\?.*|$/, queryString)
|
||||
})
|
||||
var sheets = DOM.get(document, 'link[rel="stylesheet"][hot-reload]')
|
||||
var loaded = 0
|
||||
|
||||
setTimeout(()=>{
|
||||
var root = widgetManager.getWidgetById('root')[0]
|
||||
if (root) root.onPropChanged('color')
|
||||
GRIDWIDTH_CSS = parseInt(getComputedStyle(document.documentElement).getPropertyValue('--grid-width'))
|
||||
editor.toggleGrid()
|
||||
editor.toggleGrid()
|
||||
},200)
|
||||
for (let stylesheet of sheets) {
|
||||
stylesheet.href = stylesheet.href.replace(/\?.*|$/, queryString)
|
||||
|
||||
// use image hack to catch stylesheet load event
|
||||
let img = document.createElement('img')
|
||||
document.body.appendChild(img)
|
||||
|
||||
img.onerror = img.onload = ()=>{
|
||||
img.onerror = img.onload = null
|
||||
document.body.removeChild(img)
|
||||
|
||||
if (++loaded === sheets.length) {
|
||||
var root = widgetManager.getWidgetById('root')[0]
|
||||
if (root) root.onPropChanged('colorWidget')
|
||||
fastdom.measure(()=>{
|
||||
GRIDWIDTH_CSS = parseInt(getComputedStyle(document.documentElement).getPropertyValue('--grid-width'))
|
||||
fastdom.mutate(()=>{
|
||||
editor.toggleGrid()
|
||||
editor.toggleGrid()
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
img.src = stylesheet.href
|
||||
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue