Create polished demo videos without editing skills. Mac/Windows/Linux
Ignore stale sharing work after account changes
webadderall0ac18cb6d801
diff --git a/src/components/video-editor/cloud/CloudShareButton.tsx b/src/components/video-editor/cloud/CloudShareButton.tsxindex 16d9827f..7fe163d9 100644--- a/src/components/video-editor/cloud/CloudShareButton.tsx+++ b/src/components/video-editor/cloud/CloudShareButton.tsx@@ -3,7 +3,7 @@ import { SharedRecordings } from "./SharedRecordings";import { saveProjectShareLink } from "./projectShareLinks";import { useI18n } from "@/contexts/I18nContext";import { Check } from "@/components/ui/icons";-import { useCallback, useEffect, useRef, useState } from "react";+import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";import { toast } from "@/components/ui/toast";import { Button } from "@/components/ui/button";import {@@ -94,9 +94,11 @@ export function CloudShareButton({const [shareUrl, setShareUrl] = useState<string>();const [copied, setCopied] = useState(false);const previousAccountId = useRef(accountId);- useEffect(() => {+ const accountVersion = useRef(0);+ useLayoutEffect(() => {if (previousAccountId.current === accountId) return;previousAccountId.current = accountId;+ accountVersion.current++;setError(undefined);setShareUrl(undefined);setCopied(false);@@ -149,6 +151,9 @@ export function CloudShareButton({);const handleUpload = useCallback(async () => {+ // A generation also catches switching away and back to the same account.+ const uploadAccountVersion = accountVersion.current;+ const isCurrentAccount = () => uploadAccountVersion === accountVersion.current;setUploading(true);setProgress(0);setPhase("idle");@@ -160,6 +165,7 @@ export function CloudShareButton({throw new Error("Cloud sharing is not available in this build yet.");if (!authToken) throw new Error(t("editor.cloud.signInRequired"));const available = await checkShareCapacity(DEFAULT_CLOUD_ENDPOINT, authToken);+ if (!isCurrentAccount()) return;setCapacityAvailable(available);if (!available) throw new Error(RECORDING_LIMIT_MESSAGE);if (cancelRequestedRef.current) return;@@ -167,7 +173,7 @@ export function CloudShareButton({let resolvedFilePath = filePath ?? preparedFileRef.current;if (!resolvedFilePath) {resolvedFilePath = await prepareFile?.();- if (cancelRequestedRef.current) {+ if (cancelRequestedRef.current || !isCurrentAccount()) {if (resolvedFilePath)void window.electronAPI.discardExportedTemp(resolvedFilePath);return;@@ -188,6 +194,7 @@ export function CloudShareButton({notes: notes.trim() || undefined,uploadId: nextUploadId,});+ if (!isCurrentAccount()) return;if (!result.success || !result.shareUrl) {if (!result.canceled) setError(result.error || t("editor.cloud.uploadFailed"));return;@@ -203,6 +210,7 @@ export function CloudShareButton({}toast.success(t("editor.cloud.linkCreated"));} catch (cause) {+ if (!isCurrentAccount()) return;setError(cause instanceof Error ? cause.message : String(cause));} finally {setUploading(false);diff --git a/tests/ui/publish-cloud.spec.ts b/tests/ui/publish-cloud.spec.tsindex 1bfe1a16..13686d7d 100644--- a/tests/ui/publish-cloud.spec.ts+++ b/tests/ui/publish-cloud.spec.ts@@ -92,3 +92,25 @@ test("switching accounts clears the previous account's cloud quota", async ({ pa.evaluate((button: HTMLButtonElement) => button.click());await expect(page.getByRole("button", { name: "Share", exact: true })).toBeEnabled();});++for (const fails of [false, true]) {+ test(`ignores an old account's late upload ${fails ? "error" : "success"}`, async ({+ page,+ }) => {+ await page.goto(`/tests/ui/publish.html?switch&controlled${fails ? "&fail" : ""}`);+ await page.getByRole("button", { name: "Publish", exact: true }).click();+ await page.getByRole("button", { name: "Share", exact: true }).click();+ await expect(page.getByText("Uploading · 85%", { exact: true })).toBeVisible();+ await page+ .getByRole("button", { name: "Fixture switch account", exact: true })+ .evaluate((button: HTMLButtonElement) => button.click());+ await page+ .getByRole("button", { name: "Fixture finish upload", exact: true })+ .evaluate((button: HTMLButtonElement) => button.click());+ await expect(page.getByRole("button", { name: "Share", exact: true })).toBeEnabled();+ await expect(page.getByRole("button", { name: "Copy link", exact: true })).toHaveCount(0);+ await expect(+ page.getByText("Fixture old-account upload failed", { exact: true }),+ ).toHaveCount(0);+ });+}diff --git a/tests/ui/publish.tsx b/tests/ui/publish.tsxindex 01e289c4..9c4bed49 100644--- a/tests/ui/publish.tsx+++ b/tests/ui/publish.tsx@@ -6,6 +6,7 @@ import "@/index.css";import { loadEditorPreferences } from "@/components/video-editor/editorPreferences";import { useExportSettings } from "@/components/video-editor/export/useExportSettings";const noop = () => undefined;+let finishUpload: (() => void) | undefined;let reportUpload:| ((event: { uploadId: string; uploadedBytes: number; totalBytes: number }) => void)| undefined;@@ -27,7 +28,15 @@ window.electronAPI = {cloudShareUpload: async ({ uploadId }: { uploadId: string }) => {await new Promise((resolve) => setTimeout(resolve, 800));reportUpload?.({ uploadId, uploadedBytes: 50, totalBytes: 100 });- await new Promise((resolve) => setTimeout(resolve, 12000));+ if (new URLSearchParams(location.search).has("controlled")) {+ await new Promise<void>((resolve) => {+ finishUpload = resolve;+ });+ } else {+ await new Promise((resolve) => setTimeout(resolve, 12000));+ }+ if (new URLSearchParams(location.search).has("fail"))+ throw new Error("Fixture old-account upload failed");return { success: true, shareUrl: "https://example.test/s/preview" };},cloudShareCancel: async () => ({ success: true }),@@ -72,6 +81,9 @@ function Preview() {<div className="flex justify-end p-12">{new URLSearchParams(location.search).has("switch") && (<div>+ <button type="button" onClick={() => finishUpload?.()}>+ Fixture finish upload+ </button><button type="button" onClick={() => setAuthToken("refreshed-fixture")}>Fixture refresh token</button>