Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Remove the navy gray-800 loading screen from the main page (a blue flash before the color scheme), hide pages from <html> at first paint instead of by a timer on <body> (content flashed in Firefox), and check readiness on the next frame instead of after 300 ms

Murtaza Nasir61743e0447d0
diff --git a/static/js/loading.js b/static/js/loading.js
index 7aa21d4f..cbd3169b 100644
--- a/static/js/loading.js
+++ b/static/js/loading.js
@@ -17,6 +17,7 @@ window.AppLoader = {
this.initTime = Date.now();
// Add loading class to body
+ document.documentElement.classList.add('app-loading');
document.body.classList.add('app-loading');
// Create loading overlay if it doesn't exist
@@ -108,6 +109,7 @@ window.AppLoader = {
window.__appLoaderHidden = true;
try {
// Remove app-loading class immediately to show content
+ document.documentElement.classList.remove('app-loading');
document.body.classList.remove('app-loading');
// Find all loading overlays (might be multiple)
@@ -134,6 +136,7 @@ window.AppLoader = {
} catch (error) {
console.error('Error hiding loader:', error);
// Force hide everything as last resort
+ document.documentElement.classList.remove('app-loading');
document.body.classList.remove('app-loading');
const overlays = document.querySelectorAll('.app-loading-overlay');
overlays.forEach(o => {
@@ -160,6 +163,7 @@ window.AppLoader = {
// Force hide even if error occurs
const overlay = document.querySelector('.app-loading-overlay');
if (overlay) overlay.remove();
+ document.documentElement.classList.remove('app-loading');
document.body.classList.remove('app-loading');
}
}
@@ -191,8 +195,9 @@ window.AppLoader = {
}
}, 10000);
- // Start checking after a minimum display time
- setTimeout(checkReady, 300);
+ // Check from the next frame. The overlay itself is shown only after
+ // 400 ms, so a minimum display time here only delayed the page.
+ requestAnimationFrame(checkReady);
}
};
diff --git a/templates/includes/loading_overlay.html b/templates/includes/loading_overlay.html
index a1d14775..e2a21b40 100644
--- a/templates/includes/loading_overlay.html
+++ b/templates/includes/loading_overlay.html
@@ -50,12 +50,19 @@
@keyframes spin {
to { transform: rotate(360deg); }
}
- body.app-loading { overflow: hidden; }
+ /* The class is set on <html> at once, in <head>, so the page is hidden
+ from the first paint. Set on <body> only, it was added by a timer once
+ <body> existed, and Firefox could paint the mounted page before that:
+ the content appeared for a frame, then disappeared until the page was
+ ready. */
+ html.app-loading body, body.app-loading { overflow: hidden; }
+ html.app-loading body > *:not(.app-loading-overlay),
body.app-loading > *:not(.app-loading-overlay) { opacity: 0; }
</style>
<script>
// Immediate loading overlay initialization
(function() {
+ if (!window.__appLoaderHidden) document.documentElement.classList.add('app-loading');
function initLoadingOverlay() {
// If the page already finished initialising and hid the loader,
// adding the overlay now would cover the page for good. This
diff --git a/templates/index.html b/templates/index.html
index bf2e4c9f..bf0f5caf 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -85,9 +85,6 @@
<script src="{{ url_for('static', filename='vendor/js/easymde.min.js') }}"></script>
</head>
<body class="h-full bg-[var(--bg-primary)] text-[var(--text-primary)] transition-colors duration-300">
- <div id="loader" class="fixed inset-0 bg-gray-800 flex items-center justify-center z-50">
- <div class="text-white text-lg">Loading...</div>
- </div>
<div id="app" v-cloak
data-use-asr-endpoint="{{ use_asr_endpoint }}"
data-connector-supports-diarization="{{ connector_supports_diarization }}"
diff --git a/tests/test_page_assets.py b/tests/test_page_assets.py
index fa7b5c17..8ffd3f8b 100644
--- a/tests/test_page_assets.py
+++ b/tests/test_page_assets.py
@@ -196,3 +196,24 @@ def test_scripts_follow_the_stylesheets(page):
early = [m.group(0) for m in re.finditer(r"<script src=[^>]*>|\{% include '[^']*' %\}", head)
if m.start() < last_css and "theme_bootstrap" not in m.group(0)]
assert not early, f"{page}: before the last stylesheet: {early}"
+
+
+def test_main_page_has_no_fixed_color_loading_screen():
+ """The main page had a second loading screen in Tailwind gray-800 (navy).
+
+ It was shown on every load until the app mounted, which showed as a blue
+ flash with any other color scheme. The theme-colored overlay in
+ includes/loading_overlay.html is the only loading screen.
+ """
+ html = _read("index.html")
+ assert 'id="loader"' not in html
+ assert "includes/loading_overlay.html" in html
+
+
+def test_loading_overlay_hides_the_page_from_the_first_paint():
+ """The hiding class is set on <html> in <head>, not by a timer on <body>."""
+ overlay = _read("includes/loading_overlay.html")
+ assert "document.documentElement.classList.add('app-loading')" in overlay
+ assert "html.app-loading body > *:not(.app-loading-overlay)" in overlay
+ loader_js = open(os.path.join(ROOT, "static", "js", "loading.js"), encoding="utf-8").read()
+ assert "document.documentElement.classList.remove('app-loading')" in loader_js