Stop orphan game links from blocking global imports
All checks were successful
Validate and deploy Sokko G / validate (push) Successful in 20m13s
Validate and deploy Sokko G / deploy (push) Successful in 11s

A game link could outlive its toolbox when one tab linked a game while
another tab, unaware of that link, deleted the toolbox. Auto-backups and
manual exports then copied the orphan link, and the global import
rejected the whole file.

- Drop links to missing toolboxes inside the IndexedDB transaction.
- Remove orphan links already stored when the page loads.
- Ignore a link request to a toolbox that no longer exists.
- Leave orphan links out of exports and skip them on global import, so
  older backups import again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Shinuwa 2026-11-11 15:12:34 +01:00
parent 98c442a9cd
commit d030c3f59f
9 changed files with 137 additions and 9 deletions

View file

@ -7,6 +7,7 @@ import {
globalModuleKey,
labelFromFileName,
normalizeToolbox,
pruneGameLinks,
remapMemosPlannerLink,
remapModuleOrderIds,
uid
@ -198,6 +199,7 @@ export function useToolboxActions({ store, notify, creationTemplate, importConte
function linkToolboxToGame(gameId, toolboxId) {
const updatedAt = new Date().toISOString();
return store.persistToolboxSnapshot((current) => {
if (toolboxId && !current.toolboxes.some((toolbox) => toolbox.id === toolboxId)) return current;
const links = { ...current.links };
const touched = new Set([links[gameId], toolboxId].filter(Boolean));
if (toolboxId) links[gameId] = toolboxId;
@ -431,7 +433,8 @@ export function useToolboxActions({ store, notify, creationTemplate, importConte
importAllToolboxes: async (file) => {
if (!store.ready) return false;
try {
const payload = validateToolboxImportPayload(JSON.parse(await file.text()), "global");
const validated = validateToolboxImportPayload(JSON.parse(await file.text()), "global");
const payload = { ...validated, links: pruneGameLinks(validated.links, validated.toolboxes) };
const reassignedLinks = Object.keys(payload.links || {}).filter((gameId) => store.links?.[gameId]);
const runImport = () => importAllToolboxesPayload(payload).then(() => true);
const imported = reassignedLinks.length