Skip to content

Commit 13ef8e1

Browse files
committed
docs(policies): cut the uploadableFile comments back to what the code cannot say
The docblock restated the WebKit mechanism at a level of detail the bug report already holds, and the call-site and test comments repeated it a third and fourth time. Keep the contract, the reason, the bug link, and the fact that the wrapper references rather than copies the bytes; the function name carries the rest.
1 parent baab43b commit 13ef8e1

4 files changed

Lines changed: 7 additions & 17 deletions

File tree

frontend/editor/src/core/utils/uploadableFile.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, expect, it } from "vitest";
22
import { uploadableFile } from "@app/utils/uploadableFile";
33

4-
/** jsdom's Blob has no text(); FileReader is the one byte read it implements. */
4+
/** jsdom's Blob has no text(). */
55
const textOf = (file: File) =>
66
new Promise<string>((resolve, reject) => {
77
const reader = new FileReader();

frontend/editor/src/core/utils/uploadableFile.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,12 @@
22
* The File to put in a multipart body when the caller's File may have come back
33
* from IndexedDB.
44
*
5-
* WebKit stamps a File restored from IndexedDB with a disk path into its own
6-
* storage folder, and its form serialiser reads any File with a path from disk.
7-
* Since Safari 26.5 the process doing the upload may not read that folder, so
8-
* the request goes out with Content-Length 0 and no error, while the same File
9-
* reads its bytes fine in JavaScript (https://bugs.webkit.org/show_bug.cgi?id=319985).
10-
* The server sees a multipart request with no boundary and rejects it before
11-
* any controller runs.
12-
*
5+
* WebKit serialises such a File by reading the disk path it stamped on it, which
6+
* since Safari 26.5 the uploading process may not read: the request goes out with
7+
* Content-Length 0 and no error (https://bugs.webkit.org/show_bug.cgi?id=319985).
138
* A File built over another File has no path, so every engine serialises it
14-
* through the blob route, which is also the route WebKit takes for a File it
15-
* never gave a path. That makes this wrapper correct on every browser today and
16-
* after the upstream fix lands, whichever shape that fix takes. It references
17-
* the bytes rather than copying them, so it is safe for arbitrarily large files,
18-
* and it stays uploadable after the record it came from is rewritten or deleted.
9+
* through the blob route instead. It references the bytes rather than copying
10+
* them, so it is safe for arbitrarily large files.
1911
*/
2012
export function uploadableFile(file: File): File {
2113
return new File([file], file.name, {

frontend/editor/src/proprietary/services/policyApi.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function sentForm(): FormData {
1818
return post.mock.calls.at(-1)?.[1] as FormData;
1919
}
2020

21-
/** jsdom's Blob has no text(); FileReader is the one byte read it implements. */
21+
/** jsdom's Blob has no text(). */
2222
const textOf = (file: File) =>
2323
new Promise<string>((resolve, reject) => {
2424
const reader = new FileReader();
@@ -56,7 +56,6 @@ describe("runStoredPolicy", () => {
5656
});
5757

5858
it("uploads a fresh File over the caller's bytes, never the caller's File object", async () => {
59-
// A File restored from IndexedDB serialises as an empty body in WebKit; a wrapper does not.
6059
const source = document();
6160
await runStoredPolicy("policy-1", [source], "editor-file-1");
6261

frontend/editor/src/proprietary/services/policyApi.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export async function runStoredPolicy(
3838
fileId?: string,
3939
): Promise<string> {
4040
const form = new FormData();
41-
// Wrapped: WebKit uploads a File restored from IndexedDB as an empty body.
4241
for (const file of files) form.append("fileInput", uploadableFile(file));
4342
if (fileId) form.append("fileId", fileId);
4443
// Don't set Content-Type: the HTTP client must generate multipart/form-data

0 commit comments

Comments
 (0)