Skip to content

Commit 3ec58a1

Browse files
committed
feat(overlay): hook up runtime utils to use customized error overlay
1 parent d4548e1 commit 3ec58a1

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const path = require('path');
22
const webpack = require('webpack');
33
const { createRefreshTemplate, injectRefreshEntry, validateOptions } = require('./helpers');
4-
const { refreshUtils } = require('./runtime/globals');
4+
const { errorOverlay, refreshUtils } = require('./runtime/globals');
55

66
class ReactRefreshPlugin {
77
/**
@@ -36,6 +36,7 @@ class ReactRefreshPlugin {
3636

3737
// Inject refresh utilities to Webpack's global scope
3838
const providePlugin = new webpack.ProvidePlugin({
39+
[errorOverlay]: this.options.overlay && require.resolve(this.options.overlay.module),
3940
[refreshUtils]: require.resolve('./runtime/utils'),
4041
});
4142
providePlugin.apply(compiler);

src/runtime/globals.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
module.exports.errorOverlay = '__react_refresh_error_overlay__';
2+
13
module.exports.refreshUtils = '__react_refresh_utils__';

src/runtime/utils.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
/* global __react_refresh_error_overlay__ */
12
const Refresh = require('react-refresh/runtime');
2-
const ErrorOverlay = require('../overlay');
33

44
/**
55
* Extracts exports from a webpack module object.
@@ -73,7 +73,9 @@ function createHotErrorHandler(moduleId) {
7373
* @returns {void}
7474
*/
7575
function hotErrorHandler(error) {
76-
ErrorOverlay.handleRuntimeError(error);
76+
if (__react_refresh_error_overlay__) {
77+
__react_refresh_error_overlay__.handleRuntimeError(error);
78+
}
7779
}
7880

7981
/**
@@ -109,7 +111,9 @@ function createDebounceUpdate() {
109111
refreshTimeout = setTimeout(function() {
110112
refreshTimeout = undefined;
111113
Refresh.performReactRefresh();
112-
ErrorOverlay.clearRuntimeErrors();
114+
if (__react_refresh_error_overlay__) {
115+
__react_refresh_error_overlay__.clearRuntimeErrors();
116+
}
113117
}, 30);
114118
}
115119
}

0 commit comments

Comments
 (0)