after_store cleanup

This commit is contained in:
Henry Jameson 2026-08-04 00:54:29 +03:00
commit 62e8bc58c6

View file

@ -70,7 +70,7 @@ const decodeUTF8Base64 = (data) => {
const preloadFetch = async (request) => { const preloadFetch = async (request) => {
const data = parsedInitialResults() const data = parsedInitialResults()
if (!data || !data[request]) { if (data?.[request]) {
return window.fetch(request) return window.fetch(request)
} }
const decoded = decodeUTF8Base64(data[request]) const decoded = decodeUTF8Base64(data[request])
@ -170,9 +170,9 @@ const setSettings = async ({ apiConfig, staticConfig, store }) => {
let config = {} let config = {}
if (overrides.staticConfigPreference && env === 'development') { if (overrides.staticConfigPreference && env === 'development') {
console.warn('OVERRIDING API CONFIG WITH STATIC CONFIG') console.warn('OVERRIDING API CONFIG WITH STATIC CONFIG')
config = Object.assign({}, apiConfig, staticConfig) config = { ...apiConfig, ...staticConfig }
} else { } else {
config = Object.assign({}, staticConfig, apiConfig) config = { ...staticConfig, ...apiConfig }
} }
Object.keys(INSTANCE_IDENTITY_DEFAULT_DEFINITIONS).forEach((source) => { Object.keys(INSTANCE_IDENTITY_DEFAULT_DEFINITIONS).forEach((source) => {
@ -443,7 +443,7 @@ const getNodeInfo = async ({ store }) => {
const setConfig = async ({ store }) => { const setConfig = async ({ store }) => {
// apiConfig, staticConfig // apiConfig, staticConfig
const configInfos = await Promise.all([ const configInfos = await Promise.all([
getBackendProvidedConfig({ store }), getBackendProvidedConfig(),
getStaticConfig(), getStaticConfig(),
]) ])
const apiConfig = configInfos[0] const apiConfig = configInfos[0]
@ -457,7 +457,7 @@ const checkOAuthToken = async ({ store }) => {
if (oauth.userToken) { if (oauth.userToken) {
return store.dispatch('loginUser', oauth.userToken) return store.dispatch('loginUser', oauth.userToken)
} }
return Promise.resolve() return
} }
const afterStoreSetup = async ({ pinia, store, storageError, i18n }) => { const afterStoreSetup = async ({ pinia, store, storageError, i18n }) => {
@ -485,7 +485,7 @@ const afterStoreSetup = async ({ pinia, store, storageError, i18n }) => {
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
// do some checks to avoid common errors // do some checks to avoid common errors
if (!Object.keys(allStores).length) { if (!Object.keys(allStores).length) {
throw new Error( throw new TypeError(
'No stores are available. Check the code in src/boot/after_store.js', 'No stores are available. Check the code in src/boot/after_store.js',
) )
} }
@ -495,7 +495,7 @@ const afterStoreSetup = async ({ pinia, store, storageError, i18n }) => {
const isStoreName = (name) => name.startsWith('use') const isStoreName = (name) => name.startsWith('use')
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
if (Object.keys(mod).filter(isStoreName).length !== 1) { if (Object.keys(mod).filter(isStoreName).length !== 1) {
throw new Error( throw new TypeError(
'Each store file must export exactly one store as a named export. Check your code in src/stores/', 'Each store file must export exactly one store as a named export. Check your code in src/stores/',
) )
} }
@ -504,13 +504,13 @@ const afterStoreSetup = async ({ pinia, store, storageError, i18n }) => {
if (storeFuncName && typeof mod[storeFuncName] === 'function') { if (storeFuncName && typeof mod[storeFuncName] === 'function') {
const p = mod[storeFuncName]().$persistLoaded const p = mod[storeFuncName]().$persistLoaded
if (!(p instanceof Promise)) { if (!(p instanceof Promise)) {
throw new Error( throw new TypeError(
`${name} store's $persistLoaded is not a Promise. The persist plugin is not applied.`, `${name} store's $persistLoaded is not a Promise. The persist plugin is not applied.`,
) )
} }
await p await p
} else { } else {
throw new Error( throw new TypeError(
`Store module ${name} does not export a 'use...' function`, `Store module ${name} does not export a 'use...' function`,
) )
} }
@ -518,14 +518,15 @@ const afterStoreSetup = async ({ pinia, store, storageError, i18n }) => {
) )
} }
let newStorageError
try { try {
await waitForAllStoresToLoad() await waitForAllStoresToLoad()
} catch (e) { } catch (e) {
console.error('Cannot load stores:', e) console.error('Cannot load stores:', e)
storageError = e newStorageError = e
} }
if (storageError) { if (storageError || newStorageError) {
useInterfaceStore().pushGlobalNotice({ useInterfaceStore().pushGlobalNotice({
messageKey: 'errors.storage_unavailable', messageKey: 'errors.storage_unavailable',
level: 'error', level: 'error',
@ -561,7 +562,7 @@ const afterStoreSetup = async ({ pinia, store, storageError, i18n }) => {
}) })
} catch (e) { } catch (e) {
window.splashError(e) window.splashError(e)
return Promise.reject(e) throw e
} }
applyStyleConfig(useMergedConfigStore().mergedConfig, i18n.global) applyStyleConfig(useMergedConfigStore().mergedConfig, i18n.global)
@ -573,7 +574,7 @@ const afterStoreSetup = async ({ pinia, store, storageError, i18n }) => {
getInstancePanel({ store }), getInstancePanel({ store }),
getNodeInfo({ store }), getNodeInfo({ store }),
getInstanceConfig({ store }), getInstanceConfig({ store }),
]).catch((e) => Promise.reject(e)) ])
getTOS({ store }) getTOS({ store })
getStickers({ store }) getStickers({ store })
@ -583,7 +584,7 @@ const afterStoreSetup = async ({ pinia, store, storageError, i18n }) => {
routes: routes(store), routes: routes(store),
scrollBehavior: (to, _from, savedPosition) => { scrollBehavior: (to, _from, savedPosition) => {
if (to.matched.some((m) => m.meta.dontScroll)) { if (to.matched.some((m) => m.meta.dontScroll)) {
return false return {}
} }
return savedPosition || { left: 0, top: 0 } return savedPosition || { left: 0, top: 0 }
}, },