perf: tree-shake dependencies from server (#1647)
This commit is contained in:
parent
357dff2140
commit
6dc38c7d8e
12 changed files with 90 additions and 19 deletions
|
@ -19,7 +19,7 @@ import { useAsyncIDBKeyval } from '~/composables/idb'
|
|||
|
||||
const mock = process.mock
|
||||
|
||||
const initializeUsers = async (): Promise<Ref<UserLogin[]> | RemovableRef<UserLogin[]>> => {
|
||||
const initializeUsers = (): Promise<Ref<UserLogin[]> | RemovableRef<UserLogin[]>> | Ref<UserLogin[]> | RemovableRef<UserLogin[]> => {
|
||||
let defaultUsers = mock ? [mock.user] : []
|
||||
|
||||
// Backward compatibility with localStorage
|
||||
|
@ -34,7 +34,7 @@ const initializeUsers = async (): Promise<Ref<UserLogin[]> | RemovableRef<UserLo
|
|||
|
||||
const users = process.server
|
||||
? ref<UserLogin[]>(defaultUsers)
|
||||
: await useAsyncIDBKeyval<UserLogin[]>(STORAGE_KEY_USERS, defaultUsers, { deep: true })
|
||||
: useAsyncIDBKeyval<UserLogin[]>(STORAGE_KEY_USERS, defaultUsers, { deep: true })
|
||||
|
||||
if (removeUsersOnLocalStorage)
|
||||
globalThis.localStorage.removeItem(STORAGE_KEY_USERS)
|
||||
|
@ -42,7 +42,7 @@ const initializeUsers = async (): Promise<Ref<UserLogin[]> | RemovableRef<UserLo
|
|||
return users
|
||||
}
|
||||
|
||||
const users = await initializeUsers()
|
||||
const users = process.server ? initializeUsers() as Ref<UserLogin[]> | RemovableRef<UserLogin[]> : await initializeUsers()
|
||||
const nodes = useLocalStorage<Record<string, any>>(STORAGE_KEY_NODES, {}, { deep: true })
|
||||
const currentUserHandle = useLocalStorage<string>(STORAGE_KEY_CURRENT_USER_HANDLE, mock ? mock.user.account.id : '')
|
||||
export const instanceStorage = useLocalStorage<Record<string, mastodon.v1.Instance>>(STORAGE_KEY_SERVERS, mock ? mock.server : {}, { deep: true })
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue