feat(editor): adopt backend final-fix contract (client_id, warnings, limits, head parity)
client_id per editor load (memory only), already_saved, save warnings via notices, upload_max_bytes enforced client-side with the server error text on 413, project_max_bytes warning, headCode in the Preview font scan, pinned backend heads. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eb401cd979
commit
9d425afa29
17 files changed
+581
-38
No files matched your search
@@ -52,6 +52,19 @@ interface SaveGuardContextValue {
|
||||
/** True while the server has no copy of this site (load reported rev null) and no save
|
||||
* has gone through since. Drives the "Not saved yet" pill. */
|
||||
neverSaved: boolean;
|
||||
/** Identifies this editor load to the server (save `client_id`). In memory only: a
|
||||
* duplicated tab copies sessionStorage, and two tabs must never share an id. */
|
||||
clientId: string;
|
||||
}
|
||||
|
||||
/** 8-64 chars of [A-Za-z0-9_-], the shape the backend accepts. */
|
||||
export function newClientId(): string {
|
||||
const c = (globalThis as { crypto?: Crypto }).crypto;
|
||||
if (c?.randomUUID) return c.randomUUID();
|
||||
const bytes = new Uint8Array(16);
|
||||
if (c?.getRandomValues) c.getRandomValues(bytes);
|
||||
else for (let i = 0; i < bytes.length; i++) bytes[i] = Math.floor(Math.random() * 256);
|
||||
return Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('');
|
||||
}
|
||||
|
||||
/** Identifies the editor state a save was built from. */
|
||||
@@ -86,6 +99,7 @@ const defaultValue: SaveGuardContextValue = {
|
||||
reloadLatest: () => {},
|
||||
saveInFlight: { current: null },
|
||||
neverSaved: false,
|
||||
clientId: newClientId(),
|
||||
};
|
||||
|
||||
const SaveGuardContext = createContext<SaveGuardContextValue>(defaultValue);
|
||||
@@ -102,6 +116,7 @@ export const SaveGuardProvider: React.FC<{ children: ReactNode; /** Injectable f
|
||||
const revRef = useRef<string | null | undefined>(undefined);
|
||||
const [neverSaved, setNeverSaved] = useState(false);
|
||||
const saveInFlight = useRef<Promise<unknown> | null>(null);
|
||||
const [clientId] = useState(newClientId);
|
||||
const getRev = useCallback(() => revRef.current, []);
|
||||
const setRev = useCallback((rev: string | null) => {
|
||||
revRef.current = rev;
|
||||
@@ -191,7 +206,8 @@ export const SaveGuardProvider: React.FC<{ children: ReactNode; /** Injectable f
|
||||
reloadLatest,
|
||||
saveInFlight,
|
||||
neverSaved,
|
||||
}), [loadState, emptyRefusal, dirty, saving, isDirty, getVersion, markDirty, beginSave, endSave, suppressBeforeUnload, getRev, setRev, conflict, reloadLatest, neverSaved]);
|
||||
clientId,
|
||||
}), [loadState, emptyRefusal, dirty, saving, isDirty, getVersion, markDirty, beginSave, endSave, suppressBeforeUnload, getRev, setRev, conflict, reloadLatest, neverSaved, clientId]);
|
||||
|
||||
return <SaveGuardContext.Provider value={value}>{children}</SaveGuardContext.Provider>;
|
||||
};
|
||||
Reference in new issue
Block a user