Skip to content

Commit 514a485

Browse files
committed
refactor: drop Webpack 4 and WDS 3 support
1 parent a943f01 commit 514a485

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+497
-5150
lines changed

.circleci/config.yml

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ anchors:
55
- '18.20'
66
- '20.14'
77
- '22.2'
8-
- &webpack-version-enum
8+
- &wds-version-enum
99
- '4'
1010
- '5'
1111
- &node-version-param
1212
node-version:
1313
default: '20.14'
1414
enum: *node-version-enum
1515
type: enum
16-
- &webpack-version-param
17-
webpack-version:
16+
- &wds-version-param
17+
wds-version:
1818
default: '5'
19-
enum: *webpack-version-enum
19+
enum: *wds-version-enum
2020
type: enum
2121

2222
commands:
@@ -70,26 +70,13 @@ jobs:
7070
node-version: << parameters.node-version >>
7171
parameters:
7272
<<: *node-version-param
73-
<<: *webpack-version-param
73+
<<: *wds-version-param
7474
parallelism: 4
7575
working_directory: ~/project
7676
steps:
7777
- checkout
7878
- install-deps:
7979
node-version: << parameters.node-version >>
80-
- when:
81-
condition:
82-
equal:
83-
- '4'
84-
- << parameters.webpack-version >>
85-
steps:
86-
- run:
87-
name: Use legacy OpenSSL provider if necessary
88-
command: |-
89-
if node scripts/node-version.js; then
90-
echo "export NODE_OPTIONS=--openssl-legacy-provider" >> $BASH_ENV
91-
source $BASH_ENV
92-
fi
9380
- run:
9481
name: Run Tests
9582
command: |
@@ -99,7 +86,7 @@ jobs:
9986
JEST_JUNIT_ADD_FILE_ATTRIBUTE: 'true'
10087
JEST_JUNIT_OUTPUT_DIR: test-results/jest
10188
JEST_JUNIT_OUTPUT_NAME: results.xml
102-
WEBPACK_VERSION: << parameters.webpack-version >>
89+
WDS_VERSION: << parameters.wds-version >>
10390
- store_test_results:
10491
path: test-results
10592
- store_artifacts:
@@ -113,5 +100,5 @@ workflows:
113100
matrix:
114101
parameters:
115102
node-version: *node-version-enum
116-
webpack-version: *webpack-version-enum
117-
name: test/node:<< matrix.node-version >>/webpack:<< matrix.webpack-version >>
103+
wds-version: *wds-version-enum
104+
name: test/node:<< matrix.node-version >>/wds:<< matrix.wds-version >>

.eslintrc.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"globals": {
3333
"__DEBUG__": true,
3434
"WDS_VERSION": true,
35-
"WEBPACK_VERSION": true,
3635
"browser": true,
3736
"window": true
3837
},

client/ErrorOverlayEntry.js

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
/* global __react_refresh_error_overlay__, __react_refresh_socket__, __resourceQuery */
1+
/* global __react_refresh_error_overlay__, __react_refresh_socket__ */
22

33
const events = require('./utils/errorEventHandlers.js');
44
const formatWebpackErrors = require('./utils/formatWebpackErrors.js');
5-
const runWithPatchedUrl = require('./utils/patchUrl.js');
65
const runWithRetry = require('./utils/retry.js');
76

87
// Setup error states
@@ -74,27 +73,29 @@ function compileMessageHandler(message) {
7473

7574
if (process.env.NODE_ENV !== 'production') {
7675
if (typeof window !== 'undefined') {
77-
runWithPatchedUrl(function setupOverlay() {
78-
// Only register if no other overlay have been registered
79-
if (!window.__reactRefreshOverlayInjected && __react_refresh_socket__) {
80-
// Registers handlers for compile errors with retry -
81-
// This is to prevent mismatching injection order causing errors to be thrown
82-
runWithRetry(function initSocket() {
83-
__react_refresh_socket__.init(compileMessageHandler, __resourceQuery);
84-
}, 3);
85-
// Registers handlers for runtime errors
86-
events.handleError(function handleError(error) {
87-
hasRuntimeErrors = true;
88-
__react_refresh_error_overlay__.handleRuntimeError(error);
89-
});
90-
events.handleUnhandledRejection(function handleUnhandledPromiseRejection(error) {
91-
hasRuntimeErrors = true;
92-
__react_refresh_error_overlay__.handleRuntimeError(error);
93-
});
76+
// Only register if no other overlay have been registered
77+
if (!window.__reactRefreshOverlayInjected && __react_refresh_socket__) {
78+
// Registers handlers for compile errors with retry -
79+
// This is to prevent mismatching injection order causing errors to be thrown
80+
runWithRetry(
81+
function initSocket() {
82+
__react_refresh_socket__.init(compileMessageHandler);
83+
},
84+
3,
85+
'Failed to set up the socket connection.'
86+
);
87+
// Registers handlers for runtime errors
88+
events.handleError(function handleError(error) {
89+
hasRuntimeErrors = true;
90+
__react_refresh_error_overlay__.handleRuntimeError(error);
91+
});
92+
events.handleUnhandledRejection(function handleUnhandledPromiseRejection(error) {
93+
hasRuntimeErrors = true;
94+
__react_refresh_error_overlay__.handleRuntimeError(error);
95+
});
9496

95-
// Mark overlay as injected to prevent double-injection
96-
window.__reactRefreshOverlayInjected = true;
97-
}
98-
});
97+
// Mark overlay as injected to prevent double-injection
98+
window.__reactRefreshOverlayInjected = true;
99+
}
99100
}
100101
}

client/utils/patchUrl.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

client/utils/retry.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
function runWithRetry(callback, maxRetries) {
1+
function runWithRetry(callback, maxRetries, message) {
22
function executeWithRetryAndTimeout(currentCount) {
33
try {
44
if (currentCount > maxRetries - 1) {
5-
console.warn('[React Refresh] Failed to set up the socket connection.');
5+
console.warn('[React Refresh]', message);
66
return;
77
}
88

docs/API.md

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,6 @@ interface ErrorOverlayOptions {
150150
entry?: string | false;
151151
module?: string | false;
152152
sockIntegration?: 'wds' | 'whm' | 'wps' | false | string;
153-
sockHost?: string;
154-
sockPath?: string;
155-
sockPort?: number;
156-
sockProtocol?: 'http' | 'https' | 'ws' | 'wss';
157-
useURLPolyfill?: boolean;
158153
}
159154
```
160155

@@ -223,58 +218,3 @@ Common HMR integrations (for Webpack) are support by this plugin out-of-the-box:
223218
If you use any other HMR integrations (e.g. custom ones), or if you want to customise how the connection is being setup,
224219
you will need to implement a message client in the provided file/module.
225220
You can reference implementations inside the [`sockets`](https://github.com/pmmmwh/react-refresh-webpack-plugin/tree/main/sockets) directory.
226-
227-
#### `sockHost`
228-
229-
Default: Parsed from current URL
230-
231-
Type: `string`
232-
233-
**This is relevant for `webpack-dev-server` only.**
234-
235-
Set a custom host for the error overlay to listen to Webpack build messages.
236-
Useful if you set `devServer.sockHost` to something other than `window.location.hostname`.
237-
238-
#### `sockPort`
239-
240-
Default: Parsed from current URL
241-
242-
Type: `number`
243-
244-
**This is relevant for `webpack-dev-server` only.**
245-
246-
Set a custom port for the error overlay to listen to Webpack build messages.
247-
Useful if you set `devServer.sockPort` to something other than `window.location.port`.
248-
249-
#### `sockPath`
250-
251-
Default: `/ws` for WDS v4, `/sockjs-node` for WDS v3
252-
253-
Type: `string`
254-
255-
**This is relevant for `webpack-dev-server` only.**
256-
257-
Set a custom path for the error overlay to listen to Webpack build messages.
258-
Useful if you set `devServer.sockPath` to something other than `/sockjs-node`.
259-
260-
#### `sockProtocol`
261-
262-
Default: Parsed from current URL
263-
264-
Type: `http`, `https`, `ws` or `wss`
265-
266-
**This is relevant for `webpack-dev-server` only.**
267-
268-
Force a protocol for the error overlay to listen for Webpack build messages.
269-
Useful if you want to enforce https communication, or if you're working under a non-HTTP path.
270-
271-
#### `useURLPolyfill`
272-
273-
Default: Detected from availability in the global scope
274-
275-
Type: `boolean`
276-
277-
**This is relevant for `webpack-dev-server` only.**
278-
279-
Uses a polyfill for the DOM URL API to maintain compatibility in IE11.
280-
This is only applied to code from the plugin.

docs/TROUBLESHOOTING.md

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,6 @@ This has to be done because, internally,
1515
`react-hot-loader` intercepts and reconciles the React tree before React can try to re-render it.
1616
That in turn breaks mechanisms the plugin depends on to deliver the experience.
1717

18-
## Compatibility with IE11 (`webpack-dev-server` only)
19-
20-
Our socket implementation depends on the DOM URL API,
21-
and as a consequence, a polyfill is needed when running in IE11.
22-
23-
The plugin by default will detect whether the `URL` and `URLSearchParams` constructors are available on the global scope,
24-
and will fallback to a pony-fill approach (polyfill without global scope pollution) when it is not.
25-
26-
If for some reason you need to force this behaviour,
27-
e.g. working on browsers with a broken URL implementation,
28-
you can use the `overlay.useURLPolyfill` option:
29-
30-
```js
31-
module.exports = {
32-
plugins: [
33-
new ReactRefreshPlugin({
34-
overlay: {
35-
useURLPolyfill: true,
36-
},
37-
}),
38-
],
39-
};
40-
```
41-
4218
## Compatibility with `npm@7`
4319

4420
`npm@7` have brought back the behaviour of auto-installing peer dependencies with new semantics,
@@ -332,21 +308,3 @@ module.exports = {
332308
],
333309
};
334310
```
335-
336-
## Webpack 5 compatibility issues with `webpack-dev-server@3`
337-
338-
In `webpack-dev-server@3`,
339-
there is a bug causing it to mis-judge the runtime environment when the Webpack 5 `browserslist` target is used.
340-
341-
It then fallbacks to thinking a non-browser target is being used,
342-
in turn skipping injection of the HMR runtime,
343-
and thus breaking downstream integrations like this plugin.
344-
345-
To overcome this,
346-
you can conditionally apply the `browserslist` only in production modes in your Webpack configuration:
347-
348-
```js
349-
module.exports = {
350-
target: process.env.NODE_ENV !== 'production' ? 'web' : 'browserslist',
351-
};
352-
```

lib/globals.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,3 @@
66
module.exports.getRefreshGlobalScope = (runtimeGlobals) => {
77
return `${runtimeGlobals.require || '__webpack_require__'}.$Refresh$`;
88
};
9-
10-
/**
11-
* Gets current Webpack version according to features on the compiler instance.
12-
* @param {import('webpack').Compiler} compiler The current Webpack compiler instance.
13-
* @returns {number} The current Webpack version.
14-
*/
15-
module.exports.getWebpackVersion = (compiler) => {
16-
if (!compiler.hooks) {
17-
throw new Error(`[ReactRefreshPlugin] Webpack version is not supported!`);
18-
}
19-
20-
// Webpack v5+ implements compiler caching
21-
return 'cache' in compiler ? 5 : 4;
22-
};

0 commit comments

Comments
 (0)