@@ -11,6 +11,7 @@ import { useCollaborationManager } from "./composables/useCollaborationManager.j
1111import { useNotesManager } from "./core/useNotesManager.js" ;
1212import { CollaborationManager } from "./writerTypes.js" ;
1313import { useSecretsManager } from "./core/useSecretsManager.js" ;
14+ import { RECONNECT_DELAY_MS , MAX_RETRIES } from "@/constants/retry" ;
1415
1516const wf = generateCore ( ) ;
1617
@@ -83,17 +84,54 @@ async function enableCollaboration(collaborationManager: CollaborationManager) {
8384 } ) ;
8485}
8586
87+ async function initialise ( ) {
88+ for ( let attempt = 0 ; attempt < MAX_RETRIES ; attempt ++ ) {
89+ try {
90+ await load ( ) ;
91+ return ;
92+ } catch ( reason ) {
93+ if ( attempt < MAX_RETRIES - 1 ) {
94+ logger . warn (
95+ `Core initialization failed (attempt ${ attempt + 1 } /${ MAX_RETRIES } ). Retrying...` ,
96+ reason ,
97+ ) ;
98+ const loaderEl = document . getElementById ( "loading_L1" ) ;
99+ if ( loaderEl && ! document . getElementById ( "loading_message" ) && attempt >= 2 ) {
100+ const message = document . createElement ( "div" ) ;
101+ message . id = "loading_message" ;
102+ message . textContent =
103+ "We're getting things ready.\nHang tight while we connect..." ;
104+ message . style . cssText =
105+ "position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);margin-top:120px;text-align:center;font-family: 'Poppins','Helvetica Neue','Lucida Grande',sans-serif;color:#666;font-size:14px;line-height:1.4;max-width:400px;padding:0 20px;z-index:1000;white-space:pre-line;opacity:0;transition:opacity 0.5s ease-in;" ;
106+ document . body . appendChild ( message ) ;
107+ // Trigger fade-in animation
108+ setTimeout ( ( ) => {
109+ message . style . opacity = "1" ;
110+ } , 50 ) ;
111+ }
112+ await new Promise ( ( r ) =>
113+ setTimeout ( r , RECONNECT_DELAY_MS * ( attempt + 1 ) ) ,
114+ ) ;
115+ continue ;
116+ }
117+ throw reason ;
118+ }
119+ }
120+ }
121+
86122logger . log ( "Initialising core..." ) ;
87- load ( )
123+ initialise ( )
88124 . then ( async ( ) => {
89125 logger . log ( "Core initialised." ) ;
90126 } )
91127 . catch ( ( reason ) => {
92128 logger . error ( "Core initialisation failed." , reason ) ;
129+
93130 const errorDiv = document . createElement ( "div" ) ;
94131 errorDiv . className = "error-message" ;
95132 errorDiv . setAttribute ( "role" , "alert" ) ;
96- errorDiv . style . cssText = "padding: 20px; color: #d32f2f; background: #ffebee; border: 1px solid #e57373; border-radius: 4px; margin: 20px; font-family: \"Poppins\", \"Helvetica Neue\", \"Lucida Grande\", sans-serif;" ;
133+ errorDiv . style . cssText =
134+ 'padding: 20px; color: #d32f2f; background: #ffebee; border: 1px solid #e57373; border-radius: 4px; margin: 20px; font-family: "Poppins", "Helvetica Neue", "Lucida Grande", sans-serif;' ;
97135
98136 const message = document . createElement ( "div" ) ;
99137 message . textContent =
@@ -107,7 +145,8 @@ load()
107145
108146 const reloadButton = document . createElement ( "button" ) ;
109147 reloadButton . textContent = "Reload page" ;
110- reloadButton . className = "WdsButton WdsButton--small WdsButton--tertiary" ;
148+ reloadButton . className =
149+ "WdsButton WdsButton--small WdsButton--tertiary" ;
111150 reloadButton . style . cssText =
112151 "margin-top: 16px; font-size: .875rem; font-weight: 600; border-radius: 300px; padding: 4px 16px; height: 32px; background: var(--wdsColorWhite); color: var(--wdsColorBlack); border-color: var(--wdsColorGray2); border-width: 1px; border-style: solid; box-shadow: var(--buttonShadow); cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; outline: none; position: relative; overflow: hidden; max-width: 100%; width: fit-content;" ;
113152 reloadButton . onclick = ( ) => window . location . reload ( ) ;
@@ -118,5 +157,10 @@ load()
118157
119158 const loadingSpinner = document . getElementById ( "loading_L1" ) ;
120159 loadingSpinner ?. remove ( ) ;
160+ // Remove loading message if it exists
161+ const loadingMessage = document . getElementById ( "loading_message" ) ;
162+ if ( loadingMessage ) {
163+ loadingMessage . remove ( ) ;
164+ }
121165 document . body . appendChild ( errorDiv ) ;
122166 } ) ;
0 commit comments