Merge pull request 'Fix HTML resource index fallback' (#3552) from fix/theme-index-html-fallback into develop
Reviewed-on: https://git.pleroma.social/pleroma/pleroma-fe/pulls/3552
This commit is contained in:
commit
b9efa01c7a
3 changed files with 42 additions and 2 deletions
1
changelog.d/theme-index-html-fallback.fix
Normal file
1
changelog.d/theme-index-html-fallback.fix
Normal file
|
|
@ -0,0 +1 @@
|
|||
Fix theme lists failing to load when custom resource indexes are unavailable
|
||||
|
|
@ -348,7 +348,11 @@ export const getResourcesIndex = async (url, parser = noop) => {
|
|||
}
|
||||
|
||||
try {
|
||||
const { data: builtinData } = await promisedRequest({ url, cache })
|
||||
const { data: builtinData } = await promisedRequest({
|
||||
url,
|
||||
cache,
|
||||
forceContentType: 'application/json',
|
||||
})
|
||||
builtin = resourceTransform(builtinData)
|
||||
} catch {
|
||||
builtin = []
|
||||
|
|
@ -359,6 +363,7 @@ export const getResourcesIndex = async (url, parser = noop) => {
|
|||
const { data: customData } = await promisedRequest({
|
||||
url: customUrl,
|
||||
cache,
|
||||
forceContentType: 'application/json',
|
||||
})
|
||||
custom = resourceTransform(customData)
|
||||
} catch {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,38 @@
|
|||
import { hasInvalidCachedThemeRules } from 'src/services/style_setter/style_setter.js'
|
||||
import {
|
||||
getResourcesIndex,
|
||||
hasInvalidCachedThemeRules,
|
||||
} from 'src/services/style_setter/style_setter.js'
|
||||
|
||||
describe('resource index', () => {
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
it('ignores an HTML fallback returned for a missing custom index', async () => {
|
||||
vi.spyOn(console, 'warn').mockImplementation(() => undefined)
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce(
|
||||
new Response(JSON.stringify({ builtin: { version: 1 } }), {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
}),
|
||||
)
|
||||
.mockResolvedValueOnce(
|
||||
new Response('<!doctype html><title>Pleroma</title>', {
|
||||
headers: { 'Content-Type': 'text/html' },
|
||||
}),
|
||||
),
|
||||
)
|
||||
|
||||
const resources = await getResourcesIndex('/static/styles.json')
|
||||
|
||||
expect(Object.keys(resources)).to.deep.equal(['builtin'])
|
||||
expect(resources.builtin()).to.deep.equal({ version: 1 })
|
||||
})
|
||||
})
|
||||
|
||||
describe('style setter cache', () => {
|
||||
it('rejects cached rules containing serialized objects', () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue