Skip to content

Commit 1310109

Browse files
committed
fix: username was not saved after properly after resolving the storage conflict
1 parent dc2c5a2 commit 1310109

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

rsbuild.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ const appConfig = defineConfig({
157157
'process.env.DISABLE_SERVICE_WORKER': JSON.stringify(disableServiceWorker),
158158
'process.env.INLINED_APP_CONFIG': JSON.stringify(configSource === 'BUNDLED' ? configJson : null),
159159
'process.env.ENABLE_COOKIE_STORAGE': JSON.stringify(process.env.ENABLE_COOKIE_STORAGE || true),
160+
'process.env.COOKIE_STORAGE_PREFIX': JSON.stringify(process.env.COOKIE_STORAGE_PREFIX || ''),
160161
},
161162
},
162163
server: {

src/react/appStorageProvider.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { BaseServerInfo } from './AddServerOrConnect'
88

99
// when opening html file locally in browser, localStorage is shared between all ever opened html files, so we try to avoid conflicts
1010
const localStoragePrefix = process.env?.SINGLE_FILE_BUILD ? 'minecraft-web-client:' : ''
11-
const cookiePrefix = ''
11+
const cookiePrefix = process.env.COOKIE_STORAGE_PREFIX || ''
1212
const { localStorage } = window
1313
const migrateRemoveLocalStorage = false
1414

@@ -146,7 +146,7 @@ const detectStorageConflicts = (): StorageConflict[] => {
146146
key,
147147
localStorageValue: localData,
148148
localStorageTimestamp: localTimestamp,
149-
cookieValue: cookieData,
149+
cookieValue: (typeof cookieData === 'object' && cookieData !== null && 'data' in cookieData) ? cookieData.data : cookieData,
150150
cookieTimestamp
151151
})
152152
}
@@ -231,9 +231,10 @@ export const appStorage = proxy({ ...defaultStorageData })
231231

232232
// Check if cookie storage should be used (will be set by options)
233233
const shouldUseCookieStorage = () => {
234+
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent)
234235
const isSecureCookiesAvailable = () => {
235236
// either https or localhost
236-
return window.location.protocol === 'https:' || window.location.hostname === 'localhost'
237+
return window.location.protocol === 'https:' || (window.location.hostname === 'localhost' && !isSafari)
237238
}
238239
if (!isSecureCookiesAvailable()) {
239240
return false
@@ -402,6 +403,12 @@ export const resolveStorageConflicts = (useLocalStorage: boolean) => {
402403
}
403404
}
404405

406+
// forcefully set data again
407+
for (const conflict of storageConflicts) {
408+
appStorage[conflict.key] = useLocalStorage ? conflict.localStorageValue : conflict.cookieValue
409+
saveKey(conflict.key as keyof StorageData)
410+
}
411+
405412
// Clear conflicts and restore data
406413
storageConflicts = []
407414
restoreStorageData()

0 commit comments

Comments
 (0)