@vitejs/plugin-react 4.3.1 → 4.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +12 -5
- package/dist/index.mjs +12 -5
- package/dist/refreshUtils.js +31 -9
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
@@ -62,22 +62,26 @@ if (import.meta.hot && !inWebWorker) {
|
|
62
62
|
window.$RefreshReg$ = prevRefreshReg;
|
63
63
|
window.$RefreshSig$ = prevRefreshSig;
|
64
64
|
}`;
|
65
|
-
const sharedFooter = `
|
65
|
+
const sharedFooter = (id) => `
|
66
66
|
if (import.meta.hot && !inWebWorker) {
|
67
67
|
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
68
|
-
RefreshRuntime.registerExportsForReactRefresh(
|
68
|
+
RefreshRuntime.registerExportsForReactRefresh(${JSON.stringify(
|
69
|
+
id
|
70
|
+
)}, currentExports);
|
69
71
|
import.meta.hot.accept((nextExports) => {
|
70
72
|
if (!nextExports) return;
|
71
|
-
const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(
|
73
|
+
const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(${JSON.stringify(
|
74
|
+
id
|
75
|
+
)}, currentExports, nextExports);
|
72
76
|
if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
|
73
77
|
});
|
74
78
|
});
|
75
79
|
}`;
|
76
80
|
function addRefreshWrapper(code, id) {
|
77
|
-
return sharedHeader + functionHeader.replace("__SOURCE__", JSON.stringify(id)) + code + functionFooter + sharedFooter
|
81
|
+
return sharedHeader + functionHeader.replace("__SOURCE__", JSON.stringify(id)) + code + functionFooter + sharedFooter(id);
|
78
82
|
}
|
79
83
|
function addClassComponentRefreshWrapper(code, id) {
|
80
|
-
return sharedHeader + code + sharedFooter
|
84
|
+
return sharedHeader + code + sharedFooter(id);
|
81
85
|
}
|
82
86
|
|
83
87
|
let babel;
|
@@ -268,6 +272,9 @@ const silenceUseClientWarning = (userConfig) => ({
|
|
268
272
|
if (warning.code === "MODULE_LEVEL_DIRECTIVE" && warning.message.includes("use client")) {
|
269
273
|
return;
|
270
274
|
}
|
275
|
+
if (warning.code === "SOURCEMAP_ERROR" && warning.message.includes("resolve original location") && warning.pos === 0) {
|
276
|
+
return;
|
277
|
+
}
|
271
278
|
if (userConfig.build?.rollupOptions?.onwarn) {
|
272
279
|
userConfig.build.rollupOptions.onwarn(warning, defaultHandler);
|
273
280
|
} else {
|
package/dist/index.mjs
CHANGED
@@ -54,22 +54,26 @@ if (import.meta.hot && !inWebWorker) {
|
|
54
54
|
window.$RefreshReg$ = prevRefreshReg;
|
55
55
|
window.$RefreshSig$ = prevRefreshSig;
|
56
56
|
}`;
|
57
|
-
const sharedFooter = `
|
57
|
+
const sharedFooter = (id) => `
|
58
58
|
if (import.meta.hot && !inWebWorker) {
|
59
59
|
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
60
|
-
RefreshRuntime.registerExportsForReactRefresh(
|
60
|
+
RefreshRuntime.registerExportsForReactRefresh(${JSON.stringify(
|
61
|
+
id
|
62
|
+
)}, currentExports);
|
61
63
|
import.meta.hot.accept((nextExports) => {
|
62
64
|
if (!nextExports) return;
|
63
|
-
const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(
|
65
|
+
const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(${JSON.stringify(
|
66
|
+
id
|
67
|
+
)}, currentExports, nextExports);
|
64
68
|
if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
|
65
69
|
});
|
66
70
|
});
|
67
71
|
}`;
|
68
72
|
function addRefreshWrapper(code, id) {
|
69
|
-
return sharedHeader + functionHeader.replace("__SOURCE__", JSON.stringify(id)) + code + functionFooter + sharedFooter
|
73
|
+
return sharedHeader + functionHeader.replace("__SOURCE__", JSON.stringify(id)) + code + functionFooter + sharedFooter(id);
|
70
74
|
}
|
71
75
|
function addClassComponentRefreshWrapper(code, id) {
|
72
|
-
return sharedHeader + code + sharedFooter
|
76
|
+
return sharedHeader + code + sharedFooter(id);
|
73
77
|
}
|
74
78
|
|
75
79
|
let babel;
|
@@ -260,6 +264,9 @@ const silenceUseClientWarning = (userConfig) => ({
|
|
260
264
|
if (warning.code === "MODULE_LEVEL_DIRECTIVE" && warning.message.includes("use client")) {
|
261
265
|
return;
|
262
266
|
}
|
267
|
+
if (warning.code === "SOURCEMAP_ERROR" && warning.message.includes("resolve original location") && warning.pos === 0) {
|
268
|
+
return;
|
269
|
+
}
|
263
270
|
if (userConfig.build?.rollupOptions?.onwarn) {
|
264
271
|
userConfig.build.rollupOptions.onwarn(warning, defaultHandler);
|
265
272
|
} else {
|
package/dist/refreshUtils.js
CHANGED
@@ -7,7 +7,14 @@ function debounce(fn, delay) {
|
|
7
7
|
}
|
8
8
|
|
9
9
|
/* eslint-disable no-undef */
|
10
|
-
const
|
10
|
+
const hooks = []
|
11
|
+
window.__registerBeforePerformReactRefresh = (cb) => {
|
12
|
+
hooks.push(cb)
|
13
|
+
}
|
14
|
+
const enqueueUpdate = debounce(async () => {
|
15
|
+
if (hooks.length) await Promise.all(hooks.map((cb) => cb()))
|
16
|
+
exports.performReactRefresh()
|
17
|
+
}, 16)
|
11
18
|
|
12
19
|
// Taken from https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/lib/runtime/RefreshUtils.js#L141
|
13
20
|
// This allows to resister components not detected by SWC like styled component
|
@@ -25,16 +32,30 @@ function registerExportsForReactRefresh(filename, moduleExports) {
|
|
25
32
|
}
|
26
33
|
}
|
27
34
|
|
28
|
-
function validateRefreshBoundaryAndEnqueueUpdate(prevExports, nextExports) {
|
29
|
-
|
35
|
+
function validateRefreshBoundaryAndEnqueueUpdate(id, prevExports, nextExports) {
|
36
|
+
const ignoredExports = window.__getReactRefreshIgnoredExports?.({ id }) ?? []
|
37
|
+
if (
|
38
|
+
predicateOnExport(
|
39
|
+
ignoredExports,
|
40
|
+
prevExports,
|
41
|
+
(key) => key in nextExports,
|
42
|
+
) !== true
|
43
|
+
) {
|
30
44
|
return 'Could not Fast Refresh (export removed)'
|
31
45
|
}
|
32
|
-
if (
|
46
|
+
if (
|
47
|
+
predicateOnExport(
|
48
|
+
ignoredExports,
|
49
|
+
nextExports,
|
50
|
+
(key) => key in prevExports,
|
51
|
+
) !== true
|
52
|
+
) {
|
33
53
|
return 'Could not Fast Refresh (new export)'
|
34
54
|
}
|
35
55
|
|
36
56
|
let hasExports = false
|
37
57
|
const allExportsAreComponentsOrUnchanged = predicateOnExport(
|
58
|
+
ignoredExports,
|
38
59
|
nextExports,
|
39
60
|
(key, value) => {
|
40
61
|
hasExports = true
|
@@ -42,19 +63,20 @@ function validateRefreshBoundaryAndEnqueueUpdate(prevExports, nextExports) {
|
|
42
63
|
return prevExports[key] === nextExports[key]
|
43
64
|
},
|
44
65
|
)
|
45
|
-
if (hasExports && allExportsAreComponentsOrUnchanged) {
|
66
|
+
if (hasExports && allExportsAreComponentsOrUnchanged === true) {
|
46
67
|
enqueueUpdate()
|
47
68
|
} else {
|
48
|
-
return
|
69
|
+
return `Could not Fast Refresh ("${allExportsAreComponentsOrUnchanged}" export is incompatible). Learn more at https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react#consistent-components-exports`
|
49
70
|
}
|
50
71
|
}
|
51
72
|
|
52
|
-
function predicateOnExport(moduleExports, predicate) {
|
73
|
+
function predicateOnExport(ignoredExports, moduleExports, predicate) {
|
53
74
|
for (const key in moduleExports) {
|
54
75
|
if (key === '__esModule') continue
|
76
|
+
if (ignoredExports.includes(key)) continue
|
55
77
|
const desc = Object.getOwnPropertyDescriptor(moduleExports, key)
|
56
|
-
if (desc && desc.get) return
|
57
|
-
if (!predicate(key, moduleExports[key])) return
|
78
|
+
if (desc && desc.get) return key
|
79
|
+
if (!predicate(key, moduleExports[key])) return key
|
58
80
|
}
|
59
81
|
return true
|
60
82
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitejs/plugin-react",
|
3
|
-
"version": "4.3.
|
3
|
+
"version": "4.3.2",
|
4
4
|
"license": "MIT",
|
5
5
|
"author": "Evan You",
|
6
6
|
"contributors": [
|
@@ -38,9 +38,9 @@
|
|
38
38
|
},
|
39
39
|
"homepage": "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react#readme",
|
40
40
|
"dependencies": {
|
41
|
-
"@babel/core": "^7.
|
42
|
-
"@babel/plugin-transform-react-jsx-self": "^7.24.
|
43
|
-
"@babel/plugin-transform-react-jsx-source": "^7.24.
|
41
|
+
"@babel/core": "^7.25.2",
|
42
|
+
"@babel/plugin-transform-react-jsx-self": "^7.24.7",
|
43
|
+
"@babel/plugin-transform-react-jsx-source": "^7.24.7",
|
44
44
|
"@types/babel__core": "^7.20.5",
|
45
45
|
"react-refresh": "^0.14.2"
|
46
46
|
},
|