Skip to content

Commit d9f3062

Browse files
committed
fix
1 parent b27075f commit d9f3062

File tree

3 files changed

+56
-10
lines changed

3 files changed

+56
-10
lines changed

index.html

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,25 @@
2020
<meta name="twitter:image" content="https://cssville.xyz" />
2121
<meta name="twitter:card" content="summary_large_image">
2222
<meta name="keywords" content="CSS utility-first framework" />
23+
<style>
24+
/* Hide the root element until everything is loaded and metadata is set */
25+
#root {
26+
visibility: hidden;
27+
}
28+
/* Add a loading indicator that will be shown until the page is ready */
29+
.loading-indicator {
30+
position: fixed;
31+
top: 0;
32+
left: 0;
33+
width: 100%;
34+
height: 100%;
35+
display: flex;
36+
justify-content: center;
37+
align-items: center;
38+
background-color: #f5f5f5;
39+
z-index: 9999;
40+
}
41+
</style>
2342
<link rel="stylesheet" type="text/css" href="/web.bundle.css">
2443
<link rel="stylesheet" href="/github-dark-dimmed.min.css">
2544
<link rel="preconnect" href="https://fonts.googleapis.com">
@@ -49,8 +68,12 @@
4968
});
5069
myCookieBanner.init();
5170
</script>
71+
<!-- Loading indicator that will be shown until the page is ready -->
72+
<div id="loading-indicator" class="loading-indicator">
73+
<div>Loading...</div>
74+
</div>
5275
<div class="dis-flex min-hei-100vh fle-dir-column wid-full" id="root"></div>
5376
<script src="/web.bundle.js"></script>
5477
</body>
5578

56-
</html>
79+
</html>

index.tsx

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,47 @@ function initializeMetadata() {
6363
const router = createBrowserRouter(Routes);
6464

6565
function docReady(fn: () => void) {
66-
// see if DOM is already available
67-
if (document.readyState === "complete" || document.readyState === "interactive") {
68-
// Initialize metadata before rendering React app
69-
initializeMetadata();
70-
// call on next available tick
71-
setTimeout(fn, 1);
66+
// Initialize metadata as early as possible
67+
initializeMetadata();
68+
69+
// Only render when document is fully loaded (all resources including images, stylesheets, etc.)
70+
if (document.readyState === "complete") {
71+
// Document is already fully loaded, call function immediately
72+
fn();
7273
} else {
73-
document.addEventListener("DOMContentLoaded", () => {
74-
initializeMetadata();
74+
// Wait for window.onload which ensures all resources are loaded
75+
window.addEventListener("load", () => {
7576
fn();
7677
});
7778
}
7879
}
7980

81+
// Function to show the page content and hide the loading indicator
82+
function showPageContent() {
83+
// Show the root element
84+
const rootElement = document.getElementById('root');
85+
if (rootElement) {
86+
rootElement.style.visibility = 'visible';
87+
}
88+
89+
// Hide the loading indicator
90+
const loadingIndicator = document.getElementById('loading-indicator');
91+
if (loadingIndicator) {
92+
loadingIndicator.style.display = 'none';
93+
}
94+
}
95+
8096
docReady(function () {
97+
// Initialize React app
8198
const root = ReactDOM.createRoot(document.getElementById('root'));
8299
root.render(
83100
<RouterProvider router={router} />
84101
);
102+
103+
// Initialize syntax highlighting
85104
hljs.highlightAll();
105+
106+
// Show the page content after a small delay to ensure React has rendered
107+
// and all metadata has been applied
108+
setTimeout(showPageContent, 50);
86109
});

web.bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)