Skip to content

Commit a5d72c6

Browse files
authored
fix: patch IE11 compat for URL polyfilling and TLA (#447)
1 parent 7572c4c commit a5d72c6

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

client/ErrorOverlayEntry.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { handleError, handleUnhandledRejection } from './utils/errorEventHandlers.js';
44
import formatWebpackErrors from './utils/formatWebpackErrors.js';
5-
import runWithPatchedUrl from './utils/patchUrl.js';
5+
import runWithPatchedUrl from './utils/patchUrl.cjs';
66
import runWithRetry from './utils/retry.js';
77

88
// Setup error states
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
/* global __react_refresh_polyfill_url__ */
2-
import SafeURL from 'core-js-pure/web/url';
3-
import SafeURLSearchParams from 'core-js-pure/web/url-search-params';
42

53
/**
64
* @typedef {Object} UrlAPIs
@@ -14,23 +12,23 @@ import SafeURLSearchParams from 'core-js-pure/web/url-search-params';
1412
* @returns {void}
1513
*/
1614
function runWithPatchedUrl(callback) {
17-
let __originalURL;
18-
let __originalURLSearchParams;
15+
var __originalURL;
16+
var __originalURLSearchParams;
1917

2018
// Polyfill the DOM URL and URLSearchParams constructors
2119
if (__react_refresh_polyfill_url__ || !window.URL) {
2220
__originalURL = window.URL;
23-
window.URL = SafeURL;
21+
window.URL = require('core-js-pure/web/url');
2422
}
2523
if (__react_refresh_polyfill_url__ || !window.URLSearchParams) {
2624
__originalURLSearchParams = window.URLSearchParams;
27-
window.URLSearchParams = SafeURLSearchParams;
25+
window.URLSearchParams = require('core-js-pure/web/url-search-params');
2826
}
2927

30-
// Pass in polyfilled URL APIs in case they are needed
28+
// Pass in URL APIs in case they are needed
3129
callback({ URL: window.URL, URLSearchParams: window.URLSearchParams });
3230

33-
// Restore polyfills to their original state
31+
// Restore polyfill-ed APIs to their original state
3432
if (__originalURL) {
3533
window.URL = __originalURL;
3634
}
@@ -39,4 +37,4 @@ function runWithPatchedUrl(callback) {
3937
}
4038
}
4139

42-
export default runWithPatchedUrl;
40+
module.exports = runWithPatchedUrl;

lib/utils/makeRefreshRuntimeModule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function makeRefreshRuntimeModule(webpack) {
3737
),
3838
'} finally {',
3939
webpack.Template.indent([
40-
`if (moduleObject.exports instanceof ${webpack.RuntimeGlobals.global}.Promise) {`,
40+
`if (typeof Promise !== 'undefined' && moduleObject.exports instanceof Promise) {`,
4141
webpack.Template.indent([
4242
// Ponyfill `Promise.finally` as it is only part of the spec after ES2018,
4343
// and Webpack's top level await implementation only rely on ES2015 Promises.

test/unit/makeRefreshRuntimeModule.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe.skipIf(WEBPACK_VERSION !== 5, 'makeRefreshRuntimeModule', () => {
4545
try {
4646
originalFactory.call(this, moduleObject, moduleExports, webpackRequire);
4747
} finally {
48-
if (moduleObject.exports instanceof __webpack_require__.g.Promise) {
48+
if (typeof Promise !== 'undefined' && moduleObject.exports instanceof Promise) {
4949
options.module.exports.then(
5050
function(result) {
5151
__webpack_require__.$Refresh$.cleanup(options.id);
@@ -127,7 +127,7 @@ __webpack_require__.$Refresh$ = {
127127
try {
128128
originalFactory.call(this, moduleObject, moduleExports, webpackRequire);
129129
} finally {
130-
if (moduleObject.exports instanceof __webpack_require__.g.Promise) {
130+
if (typeof Promise !== 'undefined' && moduleObject.exports instanceof Promise) {
131131
options.module.exports.then(
132132
(result) => {
133133
__webpack_require__.$Refresh$.cleanup(options.id);

0 commit comments

Comments
 (0)