diff --git a/src/api/helpers.js b/src/api/helpers.js index f965750c5..40b879232 100644 --- a/src/api/helpers.js +++ b/src/api/helpers.js @@ -71,7 +71,6 @@ export const promisedRequest = async ({ url, payload, formData, - cache, credentials, headers = {}, }) => { @@ -88,10 +87,6 @@ export const promisedRequest = async ({ options.headers['Content-Type'] = 'application/json' } - if (cache) { - options.cache = cache - } - if (formData || payload) { options.body = formData || JSON.stringify(payload) } diff --git a/src/services/style_setter/style_setter.js b/src/services/style_setter/style_setter.js index dfb52f50d..2a695f4db 100644 --- a/src/services/style_setter/style_setter.js +++ b/src/services/style_setter/style_setter.js @@ -2,8 +2,6 @@ import sum from 'hash-sum' import localforage from 'localforage' import { chunk, throttle } from 'lodash' -import { promisedRequest } from 'src/api/helpers.js' - import { getCssRules } from '../theme_data/css_utils.js' import { getEngineChecksum, init } from '../theme_data/theme_data_3.service.js' @@ -302,7 +300,7 @@ export const applyStyleConfig = (input) => { adoptStyleSheets() } -export const getResourcesIndex = async (url, parser = x => x) => { +export const getResourcesIndex = async (url, parser = JSON.parse) => { const cache = 'no-store' const customUrl = url.replace(/\.(\w+)$/, '.custom.$1') let builtin @@ -316,15 +314,14 @@ export const getResourcesIndex = async (url, parser = x => x) => { return [ k, () => - promisedRequest({ - url: v, - cache, - }) - .then(({ data: text }) => parser(text)) - .catch((e) => { - console.error(e) - return null - }), + window + .fetch(v, { cache }) + .then((data) => data.text()) + .then((text) => parser(text)) + .catch((e) => { + console.error(e) + return null + }), ] } else { console.error(`Unknown resource format - ${k} is a ${typeof v}`) @@ -334,16 +331,18 @@ export const getResourcesIndex = async (url, parser = x => x) => { } try { - const { data: builtinData } = await promisedRequest({ url, cache }) - builtin = resourceTransform(builtinData) + const builtinData = await window.fetch(url, { cache }) + const builtinResources = await builtinData.json() + builtin = resourceTransform(builtinResources) } catch { builtin = [] console.warn(`Builtin resources at ${url} unavailable`) } try { - const { data: customData } = await promisedRequest({ url: customUrl, cache }) - custom = resourceTransform(customData) + const customData = await window.fetch(customUrl, { cache }) + const customResources = await customData.json() + custom = resourceTransform(customResources) } catch { custom = [] console.warn(`Custom resources at ${customUrl} unavailable`)