Quellcode durchsuchen

🐛 fix(polyfill): 修复全局对象判断逻辑

- 在Headers和Response polyfill中添加globalThis存在性检查,避免在不支持globalThis的环境中报错
- 优化全局对象判断条件,确保只有在globalThis存在且对应对象未定义时才注册polyfill
yourname vor 3 Monaten
Ursprung
Commit
29d754b7d0
2 geänderte Dateien mit 2 neuen und 2 gelöschten Zeilen
  1. 1 1
      mini/src/utils/headers-polyfill.js
  2. 1 1
      mini/src/utils/response-polyfill.ts

+ 1 - 1
mini/src/utils/headers-polyfill.js

@@ -72,7 +72,7 @@ class Headers {
   }
   
   // 全局注册(如果需要)
-  if (typeof globalThis.Headers === 'undefined') {
+  if (typeof globalThis !== 'undefined' && typeof globalThis.Headers === 'undefined') {
     globalThis.Headers = Headers;
   }
   

+ 1 - 1
mini/src/utils/response-polyfill.ts

@@ -81,7 +81,7 @@ class ResponsePolyfill {
   }
   
   // 全局注册(如果需要)
-  if (typeof globalThis.Response === 'undefined') {
+  if (typeof globalThis !== 'undefined' && typeof globalThis.Response === 'undefined') {
     globalThis.Response = ResponsePolyfill as any
   }