fix: snapshot proxy before save — fixes 422 Unprocessable Entity
All checks were successful
CI/CD — Build & Deploy / Build & Deploy (push) Successful in 22s
All checks were successful
CI/CD — Build & Deploy / Build & Deploy (push) Successful in 22s
This commit is contained in:
@@ -26,12 +26,17 @@ let lastSave: string | null = null;
|
||||
let loaded = false;
|
||||
let saveInterval: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
// Snapshot the $state proxy into a plain object for serialization
|
||||
function snapshotState(): Record<string, unknown> {
|
||||
return JSON.parse(JSON.stringify(game.state));
|
||||
}
|
||||
|
||||
export async function saveToServer() {
|
||||
if (!authStore.user || !game.ready) return;
|
||||
const result = await apiRequest('/save', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
gameState: game.state,
|
||||
gameState: snapshotState(),
|
||||
playTimeSeconds: game.playSeconds,
|
||||
}),
|
||||
});
|
||||
@@ -103,7 +108,7 @@ export function setupVisibilitySync() {
|
||||
window.addEventListener('beforeunload', () => {
|
||||
if (!authStore.user || !game.ready) return;
|
||||
const payload = JSON.stringify({
|
||||
gameState: game.state,
|
||||
gameState: snapshotState(),
|
||||
playTimeSeconds: game.playSeconds,
|
||||
});
|
||||
fetch(`${BACKEND_URL}/api/save`, {
|
||||
|
||||
Reference in New Issue
Block a user