logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git
commit: 1c23a16bac6eef604159da8e3043b2dd21c70fb0
parent 9806eea12ea4cde8b78741cfb1ddfe1d3e64ba9b
Author: Henry Jameson <me@hjkos.com>
Date:   Wed,  3 Apr 2024 22:57:44 +0300

try to apply lazy part in one go while still having chunked processing

Diffstat:

Msrc/services/style_setter/style_setter.js26++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/services/style_setter/style_setter.js b/src/services/style_setter/style_setter.js @@ -8,7 +8,7 @@ import { chunk } from 'lodash' export const generateTheme = async (input, callbacks) => { const { - onNewRule = (rule) => {}, + onNewRule = (rule, isLazy) => {}, onLazyFinished = () => {}, onEagerFinished = () => {} } = callbacks @@ -38,9 +38,9 @@ export const generateTheme = async (input, callbacks) => { parts[1], '}' ].join('') - onNewRule(newRule) + onNewRule(newRule, false) } else { - onNewRule(rule) + onNewRule(rule, false) } }) onEagerFinished() @@ -67,9 +67,9 @@ export const generateTheme = async (input, callbacks) => { parts[1], '}' ].join('') - onNewRule(newRule) + onNewRule(newRule, true) } else { - onNewRule(rule) + onNewRule(rule, true) } }) // const t1 = performance.now() @@ -89,13 +89,23 @@ export const generateTheme = async (input, callbacks) => { export const applyTheme = async (input) => { const styleSheet = new CSSStyleSheet() - document.adoptedStyleSheets = [styleSheet] + const lazyStyleSheet = new CSSStyleSheet() const { lazyProcessFunc } = await generateTheme( input, { - onNewRule (rule) { - styleSheet.insertRule(rule, 'index-max') + onNewRule (rule, isLazy) { + if (isLazy) { + lazyStyleSheet.insertRule(rule, 'index-max') + } else { + styleSheet.insertRule(rule, 'index-max') + } + }, + onEagerFinished () { + document.adoptedStyleSheets = [styleSheet] + }, + onLazyFinished () { + document.adoptedStyleSheets = [styleSheet, lazyStyleSheet] } } )