-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from pmmmwh/feat/customize-overlay
feat(overlay): allow full customization of the error overlay integration
- Loading branch information
Showing
8 changed files
with
141 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
const createRefreshTemplate = require('./createRefreshTemplate'); | ||
const injectRefreshEntry = require('./injectRefreshEntry'); | ||
const validateOptions = require('./validateOptions'); | ||
|
||
module.exports = { | ||
createRefreshTemplate, | ||
injectRefreshEntry, | ||
validateOptions, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** @type {import('../types').ReactRefreshPluginOptions} */ | ||
const defaultOptions = { | ||
disableRefreshCheck: false, | ||
forceEnable: false, | ||
useLegacyWDSSockets: false, | ||
}; | ||
|
||
/** @type {import('../types').ErrorOverlayOptions} */ | ||
const defaultOverlayOptions = { | ||
entry: require.resolve('../runtime/ErrorOverlayEntry'), | ||
module: require.resolve('../overlay'), | ||
}; | ||
|
||
/** | ||
* Validates the options for the plugin. | ||
* @param {import('../types').ReactRefreshPluginOptions} options Non-validated plugin options object. | ||
* @returns {import('../types').ReactRefreshPluginOptions} Validated plugin options. | ||
*/ | ||
module.exports = function validateOptions(options) { | ||
const validatedOptions = Object.assign(defaultOptions, options); | ||
|
||
if ( | ||
typeof validatedOptions.overlay !== 'undefined' && | ||
typeof validatedOptions.overlay !== 'boolean' | ||
) { | ||
if (typeof validatedOptions.overlay.module !== 'string') { | ||
throw new Error( | ||
`To use the "overlay" option, a string must be provided in the "module" property. Instead, the provided value has type: "${typeof options | ||
.overlay.module}".` | ||
); | ||
} | ||
|
||
validatedOptions.overlay = { | ||
entry: options.overlay.entry || defaultOverlayOptions.entry, | ||
module: options.overlay.module, | ||
}; | ||
} else { | ||
validatedOptions.overlay = | ||
(typeof validatedOptions.overlay === 'undefined' || validatedOptions.overlay) && | ||
defaultOverlayOptions; | ||
} | ||
|
||
return validatedOptions; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* @typedef {Object} ErrorOverlayOptions | ||
* @property {string} [entry] Path to a JS file that sets up the error overlay integration. | ||
* @property {string} module The error overlay module to use. | ||
*/ | ||
|
||
/** | ||
* @typedef {Object} ReactRefreshPluginOptions | ||
* @property {boolean} [disableRefreshCheck] Disables detection of react-refresh's Babel plugin. | ||
* @property {boolean} [forceEnable] Enables the plugin forcefully. | ||
* @property {boolean | ErrorOverlayOptions} [overlay] Modifies how the error overlay integration works in the plugin. | ||
* @property {boolean} [useLegacyWDSSockets] Uses a custom SocketJS implementation for older versions of webpack-dev-server. | ||
*/ |