fix: snapshot proxy before save — fixes 422 Unprocessable Entity
All checks were successful
CI/CD — Build & Deploy / Build & Deploy (push) Successful in 22s

This commit is contained in:
2026-03-28 21:26:43 +01:00
parent 7a8f4f325c
commit d9c9ed1187

View File

@@ -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`, {