fix: restore Theme 2 font families
This commit is contained in:
parent
9e4592df59
commit
341b1c1c3e
5 changed files with 75 additions and 2 deletions
1
changelog.d/theme2-font-cache.fix
Normal file
1
changelog.d/theme2-font-cache.fix
Normal file
|
|
@ -0,0 +1 @@
|
|||
Fix Theme 2 fonts falling back to serif after upgrade
|
||||
|
|
@ -92,6 +92,11 @@ export const adoptStyleSheets = throttle(() => {
|
|||
const EAGER_STYLE_ID = 'pleroma-eager-styles'
|
||||
const LAZY_STYLE_ID = 'pleroma-lazy-styles'
|
||||
|
||||
export const hasInvalidCachedThemeRules = (data) =>
|
||||
data
|
||||
.flat()
|
||||
.some((rule) => /--(?:mono)?font:\s*\[object Object\](?:;|$)/i.test(rule))
|
||||
|
||||
const generateTheme = (inputRuleset, callbacks, debug) => {
|
||||
const {
|
||||
onNewRule = () => {
|
||||
|
|
@ -151,7 +156,8 @@ export const tryLoadCache = async () => {
|
|||
if (
|
||||
cache.engineChecksum === getEngineChecksum() &&
|
||||
cache.checksum !== undefined &&
|
||||
cache.checksum === useMergedConfigStore().mergedConfig.themeChecksum
|
||||
cache.checksum === useMergedConfigStore().mergedConfig.themeChecksum &&
|
||||
!hasInvalidCachedThemeRules(cache.data)
|
||||
) {
|
||||
const eagerStyles = createStyleSheet(EAGER_STYLE_ID, 10)
|
||||
const lazyStyles = createStyleSheet(LAZY_STYLE_ID, 20)
|
||||
|
|
|
|||
|
|
@ -266,7 +266,7 @@ export const convertTheme2To3 = (data) => {
|
|||
Object.keys(data.fonts || {}).forEach((key) => {
|
||||
if (!fontsKeys.has(key)) return
|
||||
if (!data.fonts[key]) return
|
||||
const originalFont = data.fonts[key]
|
||||
const originalFont = data.fonts[key].family
|
||||
const rule = { source: '2to3' }
|
||||
|
||||
switch (key) {
|
||||
|
|
|
|||
24
test/unit/specs/services/style_setter/style_setter.spec.js
Normal file
24
test/unit/specs/services/style_setter/style_setter.spec.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import { hasInvalidCachedThemeRules } from 'src/services/style_setter/style_setter.js'
|
||||
|
||||
describe('style setter cache', () => {
|
||||
it('rejects cached rules containing serialized objects', () => {
|
||||
expect(
|
||||
hasInvalidCachedThemeRules([
|
||||
['html { --font: [object Object]; }'],
|
||||
['.post { --font: sans-serif; }'],
|
||||
]),
|
||||
).to.equal(true)
|
||||
})
|
||||
|
||||
it('accepts cached rules containing valid font families', () => {
|
||||
expect(
|
||||
hasInvalidCachedThemeRules([
|
||||
['html { --font: sans-serif; }'],
|
||||
[
|
||||
'.post { --font: "Atkinson Hyperlegible"; }',
|
||||
'.post::after { content: "[object Object]"; }',
|
||||
],
|
||||
]),
|
||||
).to.equal(false)
|
||||
})
|
||||
})
|
||||
42
test/unit/specs/services/theme_data/theme2_to_theme3.spec.js
Normal file
42
test/unit/specs/services/theme_data/theme2_to_theme3.spec.js
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import {
|
||||
basePaletteKeys,
|
||||
convertTheme2To3,
|
||||
} from 'src/services/theme_data/theme2_to_theme3.js'
|
||||
|
||||
describe('Theme 2 to Theme 3 conversion', () => {
|
||||
it('converts font descriptors to CSS font families', () => {
|
||||
const colors = Object.fromEntries(
|
||||
[...basePaletteKeys].map((key) => [key, '#000000']),
|
||||
)
|
||||
const rules = convertTheme2To3({
|
||||
colors,
|
||||
fonts: {
|
||||
interface: { family: 'sans-serif' },
|
||||
input: { family: 'Open Sans' },
|
||||
post: { family: 'Atkinson Hyperlegible' },
|
||||
postCode: { family: 'monospace' },
|
||||
},
|
||||
})
|
||||
|
||||
expect(rules).to.deep.include({
|
||||
source: '2to3',
|
||||
component: 'Root',
|
||||
directives: { '--font': 'generic | sans-serif' },
|
||||
})
|
||||
expect(rules).to.deep.include({
|
||||
source: '2to3',
|
||||
component: 'Root',
|
||||
directives: { '--monoFont': 'generic | monospace' },
|
||||
})
|
||||
expect(rules).to.deep.include({
|
||||
source: '2to3',
|
||||
component: 'Input',
|
||||
directives: { '--font': 'generic | Open Sans' },
|
||||
})
|
||||
expect(rules).to.deep.include({
|
||||
source: '2to3',
|
||||
component: 'RichContent',
|
||||
directives: { '--font': 'generic | Atkinson Hyperlegible' },
|
||||
})
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue