@@ -63,24 +63,47 @@ function initializeMetadata() {
6363const router = createBrowserRouter ( Routes ) ;
6464
6565function 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+
8096docReady ( 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} ) ;
0 commit comments