合并画布关闭时的保存触发
This commit is contained in:
parent
24a3c930c2
commit
d26bec9864
@ -5413,7 +5413,6 @@ export default function CanvasEditorLegacyPage({
|
|||||||
const onVisibilityChange = () => {
|
const onVisibilityChange = () => {
|
||||||
if (!canvasLeaveApprovedRef.current && document.visibilityState === "hidden" && hasUnsavedCanvasChanges()) {
|
if (!canvasLeaveApprovedRef.current && document.visibilityState === "hidden" && hasUnsavedCanvasChanges()) {
|
||||||
writeCanvasDraft(id, { base: savedCanvasSnapshotRef.current!.snapshot, snapshot: JSON.stringify({ canvasData: buildPersistedCanvasData() }) });
|
writeCanvasDraft(id, { base: savedCanvasSnapshotRef.current!.snapshot, snapshot: JSON.stringify({ canvasData: buildPersistedCanvasData() }) });
|
||||||
retrySync();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const retryTimer = window.setInterval(() => {
|
const retryTimer = window.setInterval(() => {
|
||||||
|
|||||||
@ -143,6 +143,21 @@ test("only unsaved content blocks closing and beforeunload does not issue duplic
|
|||||||
expect(errors).toEqual([]);
|
expect(errors).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("pagehide and visibilitychange issue only one closing save", async ({ page }) => {
|
||||||
|
const { state, errors } = await setup(page);
|
||||||
|
state.failSave = true;
|
||||||
|
await moveImage(page);
|
||||||
|
const writes = state.writes.length;
|
||||||
|
await page.evaluate(() => {
|
||||||
|
window.dispatchEvent(new Event("pagehide"));
|
||||||
|
Object.defineProperty(document, "visibilityState", { value: "hidden", configurable: true });
|
||||||
|
document.dispatchEvent(new Event("visibilitychange"));
|
||||||
|
});
|
||||||
|
await expect.poll(() => state.writes.length).toBe(writes + 1);
|
||||||
|
expect(state.submissions).toHaveLength(0);
|
||||||
|
expect(errors).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
test("leaving with pending changes can continue editing or save before navigating", async ({ page }) => {
|
test("leaving with pending changes can continue editing or save before navigating", async ({ page }) => {
|
||||||
const { state, errors } = await setup(page);
|
const { state, errors } = await setup(page);
|
||||||
await page.route(url => url.pathname === "/", route => route.fulfill({ contentType: "text/html; charset=utf-8", body: "<p>已返回首页</p>" }));
|
await page.route(url => url.pathname === "/", route => route.fulfill({ contentType: "text/html; charset=utf-8", body: "<p>已返回首页</p>" }));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user