Experimental preload icons

This commit is contained in:
Lim Chee Aun 2023-08-13 17:15:49 +08:00
parent 2ba2696e9e
commit d237fb8320
2 changed files with 15 additions and 2 deletions

View file

@ -21,7 +21,7 @@ import { useSnapshot } from 'valtio';
import AccountSheet from './components/account-sheet'; import AccountSheet from './components/account-sheet';
import Compose from './components/compose'; import Compose from './components/compose';
import Drafts from './components/drafts'; import Drafts from './components/drafts';
import Icon from './components/icon'; import Icon, { ICONS } from './components/icon';
import Loader from './components/loader'; import Loader from './components/loader';
import MediaModal from './components/media-modal'; import MediaModal from './components/media-modal';
import Modal from './components/modal'; import Modal from './components/modal';
@ -66,6 +66,19 @@ import usePageVisibility from './utils/usePageVisibility';
window.__STATES__ = states; window.__STATES__ = states;
// Preload icons
// There's probably a better way to do this
// Related: https://github.com/vitejs/vite/issues/10600
setTimeout(() => {
for (const icon in ICONS) {
if (Array.isArray(ICONS[icon])) {
ICONS[icon][0]?.();
} else {
ICONS[icon]?.();
}
}
}, 5000);
function App() { function App() {
const snapStates = useSnapshot(states); const snapStates = useSnapshot(states);
const [isLoggedIn, setIsLoggedIn] = useState(false); const [isLoggedIn, setIsLoggedIn] = useState(false);

View file

@ -8,7 +8,7 @@ const SIZES = {
xxl: 32, xxl: 32,
}; };
const ICONS = { export const ICONS = {
x: () => import('@iconify-icons/mingcute/close-line'), x: () => import('@iconify-icons/mingcute/close-line'),
heart: () => import('@iconify-icons/mingcute/heart-line'), heart: () => import('@iconify-icons/mingcute/heart-line'),
bookmark: () => import('@iconify-icons/mingcute/bookmark-line'), bookmark: () => import('@iconify-icons/mingcute/bookmark-line'),