nicolium: try to improve loading time

Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
nicole mikołajczyk
2026-03-18 22:47:44 +01:00
parent 804dc5aa7f
commit 1343d2888f
2 changed files with 21 additions and 10 deletions

View File

@ -14,16 +14,23 @@ const getHost = () => {
}
};
const fetchInstance = async () => {
try {
const client = getClient();
const instance = await client.instance.getInstance();
const doFetchInstance = async () => {
const client = getClient();
const instance = await client.instance.getInstance();
useInstanceStore.getState().actions.loadInstance(instance);
useComposeStore.getState().actions.importDefaultContentType(instance);
} catch (error) {
useInstanceStore.getState().actions.loadInstance(instance);
useComposeStore.getState().actions.importDefaultContentType(instance);
};
const fetchInstance = async () => {
const { fetched, instanceFetchFailed } = useInstanceStore.getState();
if (fetched || (instanceFetchFailed && !getAuthUserUrl())) return;
const promise = doFetchInstance().catch((error) => {
useInstanceStore.getState().actions.instanceFetchFailed(error);
}
});
if (!fetched) await promise;
};
const checkIfStandalone = () =>
@ -31,9 +38,11 @@ const checkIfStandalone = () =>
.then(({ ok, headers }) => {
const isOk = ok && !!headers.get('content-type')?.includes('application/json');
useInstanceStore.getState().actions.setInstanceFetchFailed(!isOk);
return !isOk;
})
.catch((err) => {
useInstanceStore.getState().actions.setInstanceFetchFailed(!err.response?.ok);
return true;
});
export { getHost, fetchInstance, checkIfStandalone };

View File

@ -42,10 +42,12 @@ const NicoliumLoad: React.FC<INicoliumLoad> = ({ children }) => {
useEffect(() => {
/** Load initial data from the backend */
const loadInitial = async () => {
checkIfStandalone();
const standaloneCheck = checkIfStandalone();
// Await for authenticated fetch
await fetchMe();
// Await for feature detection
// Wait for standalone detection before proceeding
await standaloneCheck;
// Await for feature detection (skipped if already fetched or standalone)
await fetchInstance();
// Await for configuration
await loadFrontendConfig();