Skip to content

Commit 49b60f2

Browse files
authored
fix: patch around loader crashes when global fetch polyfills are used (#193)
1 parent ea5c355 commit 49b60f2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

loader/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
// This is a patch for mozilla/source-map#349 -
2+
// internally, it uses the existence of the `fetch` global to toggle browser behaviours.
3+
// That check, however, will break when `fetch` polyfills are used for SSR setups.
4+
// We "reset" the polyfill here to ensure it won't interfere with source-map generation.
5+
const originalFetch = global.fetch;
6+
delete global.fetch;
7+
18
const { SourceMapConsumer, SourceMapGenerator, SourceNode } = require('source-map');
29
const { Template } = require('webpack');
310

@@ -92,3 +99,8 @@ function ReactRefreshLoader(source, inputSourceMap, meta) {
9299
}
93100

94101
module.exports = ReactRefreshLoader;
102+
103+
// Restore the original value of the `fetch` global, if it exists
104+
if (originalFetch) {
105+
global.fetch = originalFetch;
106+
}

0 commit comments

Comments
 (0)