Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(overlay): hook up runtime utils to use customized error overlay
  • Loading branch information
pmmmwh committed Mar 2, 2020
commit 3ceeae21a46b022d9d7ac16b15a25c072fd1286d
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path');
const webpack = require('webpack');
const { createRefreshTemplate, injectRefreshEntry, validateOptions } = require('./helpers');
const { refreshUtils } = require('./runtime/globals');
const { errorOverlay, refreshUtils } = require('./runtime/globals');

class ReactRefreshPlugin {
/**
Expand Down Expand Up @@ -36,6 +36,7 @@ class ReactRefreshPlugin {

// Inject refresh utilities to Webpack's global scope
const providePlugin = new webpack.ProvidePlugin({
[errorOverlay]: this.options.overlay && require.resolve(this.options.overlay.module),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an issue with line. Basically, this is resolving to [errorOverlay]: false so webpack is complaining that there's no module named false

image

If you remove the line, everything works fine (but of course you won't have the overlay)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I noticed this. A fix is on its way.

[refreshUtils]: require.resolve('./runtime/utils'),
});
providePlugin.apply(compiler);
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/globals.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module.exports.errorOverlay = '__react_refresh_error_overlay__';

module.exports.refreshUtils = '__react_refresh_utils__';
10 changes: 7 additions & 3 deletions src/runtime/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global __react_refresh_error_overlay__ */
const Refresh = require('react-refresh/runtime');
const ErrorOverlay = require('../overlay');

/**
* Extracts exports from a webpack module object.
Expand Down Expand Up @@ -73,7 +73,9 @@ function createHotErrorHandler(moduleId) {
* @returns {void}
*/
function hotErrorHandler(error) {
ErrorOverlay.handleRuntimeError(error);
if (__react_refresh_error_overlay__) {
__react_refresh_error_overlay__.handleRuntimeError(error);
}
}

/**
Expand Down Expand Up @@ -109,7 +111,9 @@ function createDebounceUpdate() {
refreshTimeout = setTimeout(function() {
refreshTimeout = undefined;
Refresh.performReactRefresh();
ErrorOverlay.clearRuntimeErrors();
if (__react_refresh_error_overlay__) {
__react_refresh_error_overlay__.clearRuntimeErrors();
}
}, 30);
}
}
Expand Down