Skip to content

Commit ccead39

Browse files
committed
fix read/write files on safari (workaround bug in safari missing async iterator support for streams)
1 parent 17209b7 commit ccead39

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/packages/frontend/client/project.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,3 +683,31 @@ const touchComputeServer = throttle(
683683
},
684684
30000,
685685
);
686+
687+
// Polyfill for Safari: Add async iterator support to ReadableStream if missing.
688+
// E.g., this is missing in all versions of Safari as of May 2025 according to
689+
// https://caniuse.com/?search=ReadableStream%20async
690+
// This breaks reading and writing files to projects, which is why this
691+
// is here (e.g., the writeFile and readFile functions above).
692+
// This might also matter for Jupyter.
693+
// https://chatgpt.com/share/6827a476-dbe8-800e-9156-3326eb41baae
694+
if (
695+
typeof ReadableStream !== "undefined" &&
696+
!ReadableStream.prototype[Symbol.asyncIterator]
697+
) {
698+
ReadableStream.prototype[Symbol.asyncIterator] = function () {
699+
const reader = this.getReader();
700+
return {
701+
async next() {
702+
return reader.read();
703+
},
704+
async return() {
705+
reader.releaseLock();
706+
return { done: true };
707+
},
708+
[Symbol.asyncIterator]() {
709+
return this;
710+
},
711+
};
712+
};
713+
}

0 commit comments

Comments
 (0)