Ensure websocket polyfill doesn't load if there is already a global.Webocket property set (#5840)

* conditional global variable check

* move conditional to if block

* add changeset

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
Jing Yang Fan 2023-10-16 05:17:46 -04:00 committed by GitHub
parent 1724918f06
commit 4e62b8493d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -0,0 +1,6 @@
---
"@gradio/client": patch
"gradio": patch
---
fix:Ensure websocket polyfill doesn't load if there is already a `global.Webocket` property set

View File

@ -255,7 +255,10 @@ export function api_factory(
};
const transform_files = normalise_files ?? true;
if (typeof window === "undefined" || !("WebSocket" in window)) {
if (
(typeof window === "undefined" || !("WebSocket" in window)) &&
!global.Websocket
) {
const ws = await import("ws");
NodeBlob = (await import("node:buffer")).Blob;
//@ts-ignore