@@ -91,6 +91,14 @@ const setCookieValue = (key: string, value: string): boolean => {
91
91
}
92
92
93
93
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
+
94
102
return true
95
103
} catch ( error ) {
96
104
console . error ( `Failed to set cookie for key '${ key } ':` , error )
@@ -229,12 +237,19 @@ export const getRandomUsername = (appConfig: AppConfig) => {
229
237
230
238
export const appStorage = proxy ( { ...defaultStorageData } )
231
239
240
+ // Track if cookies failed in this session
241
+ let cookiesFailedThisSession = false
242
+
232
243
// Check if cookie storage should be used (will be set by options)
233
244
const 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
+
235
250
const isSecureCookiesAvailable = ( ) => {
236
251
// 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' )
238
253
}
239
254
if ( ! isSecureCookiesAvailable ( ) ) {
240
255
return false
@@ -345,8 +360,10 @@ const saveKey = (key: keyof StorageData) => {
345
360
// Remove from localStorage if cookie save was successful
346
361
markLocalStorageAsMigrated ( key )
347
362
} 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
350
367
}
351
368
}
352
369
}
0 commit comments