@@ -91,6 +91,14 @@ const setCookieValue = (key: string, value: string): boolean => {
9191 }
9292
9393 document . cookie = cookie
94+
95+ // Verify the cookie was actually saved by reading it back
96+ const savedValue = getCookieValue ( key )
97+ if ( savedValue !== value ) {
98+ console . warn ( `Cookie verification failed for key '${ key } '. Expected: ${ value } , Got: ${ savedValue } ` )
99+ return false
100+ }
101+
94102 return true
95103 } catch ( error ) {
96104 console . error ( `Failed to set cookie for key '${ key } ':` , error )
@@ -229,12 +237,19 @@ export const getRandomUsername = (appConfig: AppConfig) => {
229237
230238export const appStorage = proxy ( { ...defaultStorageData } )
231239
240+ // Track if cookies failed in this session
241+ let cookiesFailedThisSession = false
242+
232243// Check if cookie storage should be used (will be set by options)
233244const shouldUseCookieStorage = ( ) => {
234- const isSafari = / ^ ( (? ! c h r o m e | a n d r o i d ) .) * s a f a r i / i. test ( navigator . userAgent )
245+ // If cookies failed this session, don't try again
246+ if ( cookiesFailedThisSession ) {
247+ return false
248+ }
249+
235250 const isSecureCookiesAvailable = ( ) => {
236251 // either https or localhost
237- return window . location . protocol === 'https:' || ( window . location . hostname === 'localhost' && ! isSafari )
252+ return window . location . protocol === 'https:' || ( window . location . hostname === 'localhost' )
238253 }
239254 if ( ! isSecureCookiesAvailable ( ) ) {
240255 return false
@@ -345,8 +360,10 @@ const saveKey = (key: keyof StorageData) => {
345360 // Remove from localStorage if cookie save was successful
346361 markLocalStorageAsMigrated ( key )
347362 } else {
348- // Disabling for now so no confusing conflicts modal after page reload
349- // useLocalStorage = true
363+ // Cookie save failed, disable cookies for this session and fallback to localStorage
364+ console . warn ( `Cookie save failed for key '${ key } ', disabling cookies for this session` )
365+ cookiesFailedThisSession = true
366+ useLocalStorage = true
350367 }
351368 }
352369 }
0 commit comments