Skip to content

Commit

Permalink
fix: patch IE11 compat for URL polyfilling and TLA
Browse files Browse the repository at this point in the history
  • Loading branch information
pmmmwh committed Jul 11, 2021
1 parent e82428c commit 07e88c8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion client/ErrorOverlayEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { handleError, handleUnhandledRejection } from './utils/errorEventHandlers.js';
import formatWebpackErrors from './utils/formatWebpackErrors.js';
import runWithPatchedUrl from './utils/patchUrl.js';
import runWithPatchedUrl from './utils/patchUrl.cjs';

// Setup error states
let isHotReload = false;
Expand Down
16 changes: 7 additions & 9 deletions client/utils/patchUrl.js → client/utils/patchUrl.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* global __react_refresh_polyfill_url__ */
import SafeURL from 'core-js-pure/web/url';
import SafeURLSearchParams from 'core-js-pure/web/url-search-params';

/**
* @typedef {Object} UrlAPIs
Expand All @@ -14,23 +12,23 @@ import SafeURLSearchParams from 'core-js-pure/web/url-search-params';
* @returns {void}
*/
function runWithPatchedUrl(callback) {
let __originalURL;
let __originalURLSearchParams;
var __originalURL;
var __originalURLSearchParams;

// Polyfill the DOM URL and URLSearchParams constructors
if (__react_refresh_polyfill_url__ || !window.URL) {
__originalURL = window.URL;
window.URL = SafeURL;
window.URL = require('core-js-pure/web/url');
}
if (__react_refresh_polyfill_url__ || !window.URLSearchParams) {
__originalURLSearchParams = window.URLSearchParams;
window.URLSearchParams = SafeURLSearchParams;
window.URLSearchParams = require('core-js-pure/web/url-search-params');
}

// Pass in polyfilled URL APIs in case they are needed
// Pass in URL APIs in case they are needed
callback({ URL: window.URL, URLSearchParams: window.URLSearchParams });

// Restore polyfills to their original state
// Restore polyfill-ed APIs to their original state
if (__originalURL) {
window.URL = __originalURL;
}
Expand All @@ -39,4 +37,4 @@ function runWithPatchedUrl(callback) {
}
}

export default runWithPatchedUrl;
module.exports = runWithPatchedUrl;
2 changes: 1 addition & 1 deletion lib/utils/makeRefreshRuntimeModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function makeRefreshRuntimeModule(webpack) {
),
'} finally {',
webpack.Template.indent([
`if (moduleObject.exports instanceof ${webpack.RuntimeGlobals.global}.Promise) {`,
`if (typeof Promise !== 'undefined' && moduleObject.exports instanceof Promise) {`,
webpack.Template.indent([
// Ponyfill `Promise.finally` as it is only part of the spec after ES2018,
// and Webpack's top level await implementation only rely on ES2015 Promises.
Expand Down

0 comments on commit 07e88c8

Please sign in to comment.