From 763b9795b6e01dca0f79c21a33ff3fe464a3ad50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E7=8E=AE=E6=96=87?= Date: Wed, 30 Oct 2019 00:45:52 +0800 Subject: [PATCH] Fix for an error using URLSearchParams with fetch Fix the following error occurred in WeChat Windows client (based on Chrome 53 from UA), when passing an `URLSearchParams` as body not not passing headers. message: "Failed to construct 'Headers': No matching constructor signature." stack: TypeError: Failed to construct 'Headers': No matching constructor signature. at TypeError (native) at fetch (webpack-internal:///./node_modules/core-js/modules/web.url-search-params.js:328:23) at _callee$ (webpack-internal:///./src/api/internal.ts:180:20) at tryCatch (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:45:40) ... --- packages/core-js/modules/web.url-search-params.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core-js/modules/web.url-search-params.js b/packages/core-js/modules/web.url-search-params.js index e09b6fc036ec..5429fe9f4f80 100644 --- a/packages/core-js/modules/web.url-search-params.js +++ b/packages/core-js/modules/web.url-search-params.js @@ -325,7 +325,7 @@ if (!USE_NATIVE_URL && typeof $fetch == 'function' && typeof Headers == 'functio if (isObject(init)) { body = init.body; if (classof(body) === URL_SEARCH_PARAMS) { - headers = new Headers(init.headers); + headers = init.headers ? new Headers(init.headers) : new Headers(); if (!headers.has('content-type')) { headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8'); }