don't compress theme cache as it takes ~1secon on mobile
This commit is contained in:
parent
f659c9c123
commit
9187c1d31c
1 changed files with 18 additions and 22 deletions
|
@ -93,32 +93,28 @@ export const generateTheme = (inputRuleset, callbacks, debug) => {
|
||||||
|
|
||||||
export const tryLoadCache = async () => {
|
export const tryLoadCache = async () => {
|
||||||
console.info('Trying to load compiled theme data from cache')
|
console.info('Trying to load compiled theme data from cache')
|
||||||
const data = await localforage.getItem('pleromafe-theme-cache')
|
const cache = await localforage.getItem('pleromafe-theme-cache')
|
||||||
if (!data) return null
|
if (!cache) return null
|
||||||
let cache
|
|
||||||
try {
|
try {
|
||||||
const inflated = pako.inflate(data)
|
if (cache.engineChecksum === getEngineChecksum()) {
|
||||||
const decoded = new TextDecoder().decode(inflated)
|
const eagerStyles = createStyleSheet(EAGER_STYLE_ID)
|
||||||
cache = JSON.parse(decoded)
|
const lazyStyles = createStyleSheet(LAZY_STYLE_ID)
|
||||||
console.info(`Loaded theme from cache, compressed=${Math.ceil(data.length / 1024)}kiB size=${Math.ceil(inflated.length / 1024)}kiB`)
|
|
||||||
|
cache.data[0].forEach(rule => eagerStyles.sheet.insertRule(rule, 'index-max'))
|
||||||
|
cache.data[1].forEach(rule => lazyStyles.sheet.insertRule(rule, 'index-max'))
|
||||||
|
|
||||||
|
adoptStyleSheets([eagerStyles, lazyStyles])
|
||||||
|
|
||||||
|
console.info(`Loaded theme from cache`)
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
console.warn('Engine checksum doesn\'t match, cache not usable, clearing')
|
||||||
|
localStorage.removeItem('pleroma-fe-theme-cache')
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Failed to decode theme cache:', e)
|
console.error('Failed to load theme cache:', e)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (cache.engineChecksum === getEngineChecksum()) {
|
|
||||||
const eagerStyles = createStyleSheet(EAGER_STYLE_ID)
|
|
||||||
const lazyStyles = createStyleSheet(LAZY_STYLE_ID)
|
|
||||||
|
|
||||||
cache.data[0].forEach(rule => eagerStyles.sheet.insertRule(rule, 'index-max'))
|
|
||||||
cache.data[1].forEach(rule => lazyStyles.sheet.insertRule(rule, 'index-max'))
|
|
||||||
|
|
||||||
adoptStyleSheets([eagerStyles, lazyStyles])
|
|
||||||
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
console.warn('Engine checksum doesn\'t match, cache not usable, clearing')
|
|
||||||
localStorage.removeItem('pleroma-fe-theme-cache')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const applyTheme = (
|
export const applyTheme = (
|
||||||
|
|
Loading…
Add table
Reference in a new issue