The fonts were pulled by @import inside the main CSS bundle; the deferred app bundle waited for that stylesheet, so a slow fonts.googleapis.com kept the page blank for 20-30 s. Fonts now load from index.html as a print stylesheet switched on by onload (text renders with a fallback font meanwhile, display=swap). The Maps API script was defer, so the app bundle (deferred after it) could not run until the Maps API downloaded. It is async now; map code already waits for window.ymaps via whenYmapsReady. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
33 lines
1.3 KiB
JavaScript
33 lines
1.3 KiB
JavaScript
/**
|
||
* public/index.html подключает API Яндекс.Карт через <script async>,
|
||
* поэтому к моменту первого рендера window.ymaps может быть ещё undefined:
|
||
* скрипт не скачался, медленный CDN, блокировщик рекламы, офлайн.
|
||
*
|
||
* Без ожидания карта просто не создаётся — пользователь видит вечный спиннер
|
||
* без единой ошибки. Поэтому ждём появления API, но с таймаутом, и отдаём
|
||
* вызывающему явную ошибку вместо бесконечной загрузки.
|
||
*/
|
||
|
||
const DEFAULT_TIMEOUT_MS = 10000;
|
||
const POLL_INTERVAL_MS = 100;
|
||
|
||
export function whenYmapsReady(timeoutMs = DEFAULT_TIMEOUT_MS) {
|
||
if (window.ymaps?.ready) return Promise.resolve(window.ymaps);
|
||
|
||
return new Promise((resolve, reject) => {
|
||
const startedAt = Date.now();
|
||
|
||
const timer = setInterval(() => {
|
||
if (window.ymaps?.ready) {
|
||
clearInterval(timer);
|
||
resolve(window.ymaps);
|
||
return;
|
||
}
|
||
if (Date.now() - startedAt >= timeoutMs) {
|
||
clearInterval(timer);
|
||
reject(new Error("YMAPS_LOAD_FAILED"));
|
||
}
|
||
}, POLL_INTERVAL_MS);
|
||
});
|
||
}
|