fix(client): guard phantom-store mutations against unset game and no-op move
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -38,11 +38,13 @@ function makeStore() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function place(sq: Square, type: PieceType) {
|
function place(sq: Square, type: PieceType) {
|
||||||
|
if (!gameId) return;
|
||||||
state.phantoms = { ...state.phantoms, [sq]: { color: oppColor, type } };
|
state.phantoms = { ...state.phantoms, [sq]: { color: oppColor, type } };
|
||||||
persist();
|
persist();
|
||||||
}
|
}
|
||||||
|
|
||||||
function move(from: Square, to: Square) {
|
function move(from: Square, to: Square) {
|
||||||
|
if (!gameId || from === to) return;
|
||||||
const p = state.phantoms[from];
|
const p = state.phantoms[from];
|
||||||
if (!p) return;
|
if (!p) return;
|
||||||
const next = { ...state.phantoms };
|
const next = { ...state.phantoms };
|
||||||
@@ -53,6 +55,7 @@ function makeStore() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function remove(sq: Square) {
|
function remove(sq: Square) {
|
||||||
|
if (!gameId) return;
|
||||||
const next = { ...state.phantoms };
|
const next = { ...state.phantoms };
|
||||||
delete next[sq];
|
delete next[sq];
|
||||||
state.phantoms = next;
|
state.phantoms = next;
|
||||||
|
|||||||
Reference in New Issue
Block a user