-
Notifications
You must be signed in to change notification settings - Fork 198
feat(overlay): allow full customization of the error overlay integration #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
002a514
refactor: extract types into common file
pmmmwh c27403f
refactor: update type references within the project
pmmmwh a0de3b5
feat: add options validator
pmmmwh 3f0e2c5
feat(overlay): only inject overlay entry when user uses the integration
pmmmwh dc4c660
feat(overlay): fix typos in options validator to correctly inject def…
pmmmwh 3ceeae2
feat(overlay): hook up runtime utils to use customized error overlay
pmmmwh c42cd5b
docs(overlay): refactor docs and document overlay options usage
pmmmwh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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. | ||
*/ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 falseIf you remove the line, everything works fine (but of course you won't have the overlay)
There was a problem hiding this comment.
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.