Skip to content

Commit 35967c0

Browse files
committed
chore: add comments
1 parent 779eb11 commit 35967c0

File tree

5 files changed

+27
-21
lines changed

5 files changed

+27
-21
lines changed

packages/common/refresh-runtime.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,11 @@ function predicateOnExport(ignoredExports, moduleExports, predicate) {
632632
for (const key in moduleExports) {
633633
if (key === '__esModule') continue
634634
if (ignoredExports.includes(key)) continue
635-
// TODO: Not sure why need this. The esm module live binding always is getter, look like the browser is not.
635+
// NOTE: this condition was added in https://github.com/vitejs/vite/pull/10239
636+
// this is needed to avoid triggering side effects in getters
637+
// but this is not needed when `moduleExports` is an ESM module namespace
638+
// also this is problematic for full-bundle mode because rolldown converts
639+
// exports to getters for live bindings
636640
// const desc = Object.getOwnPropertyDescriptor(moduleExports, key)
637641
// if (desc && desc.get) return key
638642
if (!predicate(key, moduleExports[key])) return key

packages/common/refresh-utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof
8181
newCode = `${sharedHead}${newCode}
8282
8383
if (import.meta.hot && !inWebWorker) {
84-
import.meta.hot.getExports(import.meta.url).then((currentExports) => {
84+
// NOTE: import(import.meta.url) does not work in full-bundle mode
85+
import.meta.hot.getExports().then((currentExports) => {
8586
RefreshRuntime.registerExportsForReactRefresh(${JSON.stringify(
8687
id,
8788
)}, currentExports);

packages/plugin-react-oxc/src/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,15 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
103103
}
104104

105105
let skipFastRefresh = false
106-
let base: string | undefined
106+
let base: string
107+
107108
const viteRefreshWrapper: Plugin = {
108109
name: 'vite:react-oxc:refresh-wrapper',
109110
apply: 'serve',
110111
configResolved(config) {
111112
base = config.base
112113
skipFastRefresh = config.isProduction || config.server.hmr === false
114+
base = config.base
113115
},
114116
transform: {
115117
filter: {
@@ -138,20 +140,19 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
138140
},
139141
},
140142
transformIndexHtml: {
143+
// TODO: maybe we can inject this to entrypoints instead of index.html?
141144
handler() {
142145
if (!skipFastRefresh)
143146
return [
144147
{
145148
tag: 'script',
146149
attrs: { type: 'module' },
147-
// !!! Rolldown vite full bunlde module break changes, config.server is invalid
148-
// children: getPreambleCode(config.server!.config.base),
149-
children: getPreambleCode(base!),
150+
children: getPreambleCode(base),
150151
},
151152
]
152153
},
153-
// Rolldown vite full bunlde module break changes.
154-
// Changed it to make sure the inject module could be bundled
154+
// In unbundled mode, Vite transforms any requests.
155+
// But in full bundled mode, Vite only transforms / bundles the scripts injected in `order: 'pre'`.
155156
order: 'pre',
156157
},
157158
}

packages/plugin-react-swc/src/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ type Options = {
8585

8686
const react = (_options?: Options): PluginOption[] => {
8787
let hmrDisabled = false
88+
let base: string
8889
const options = {
8990
jsxImportSource: _options?.jsxImportSource ?? 'react',
9091
tsDecorators: _options?.tsDecorators,
@@ -99,7 +100,6 @@ const react = (_options?: Options): PluginOption[] => {
99100
disableOxcRecommendation: _options?.disableOxcRecommendation,
100101
}
101102

102-
let base: string | undefined
103103
return [
104104
{
105105
name: 'vite:react-swc:resolve-runtime',
@@ -140,6 +140,8 @@ const react = (_options?: Options): PluginOption[] => {
140140
configResolved(config) {
141141
base = config.base
142142
if (config.server.hmr === false) hmrDisabled = true
143+
base = config.base
144+
143145
const mdxIndex = config.plugins.findIndex(
144146
(p) => p.name === '@mdx-js/rollup',
145147
)
@@ -165,21 +167,19 @@ const react = (_options?: Options): PluginOption[] => {
165167
}
166168
},
167169
transformIndexHtml: {
170+
// TODO: maybe we can inject this to entrypoints instead of index.html?
168171
handler() {
169-
if (!hmrDisabled) {
172+
if (!hmrDisabled)
170173
return [
171174
{
172175
tag: 'script',
173176
attrs: { type: 'module' },
174-
// !!! Rolldown vite full bunlde module break changes, config.server is invalid
175-
// children: getPreambleCode(config.server!.config.base),
176-
children: getPreambleCode(base!),
177+
children: getPreambleCode(base),
177178
},
178179
]
179-
}
180180
},
181-
// Rolldown vite full bunlde module break changes.
182-
// Changed it to make sure the inject module could be bundled
181+
// In unbundled mode, Vite transforms any requests.
182+
// But in full bundled mode, Vite only transforms / bundles the scripts injected in `order: 'pre'`.
183183
order: 'pre',
184184
},
185185
async transform(code, _id, transformOptions) {

packages/plugin-react/src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
121121
let isProduction = true
122122
let projectRoot = process.cwd()
123123
let skipFastRefresh = false
124+
let base: string
124125
let runPluginOverrides:
125126
| ((options: ReactBabelOptions, context: ReactBabelHookContext) => void)
126127
| undefined
@@ -382,20 +383,19 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
382383
},
383384
},
384385
transformIndexHtml: {
386+
// TODO: maybe we can inject this to entrypoints instead of index.html?
385387
handler() {
386388
if (!skipFastRefresh)
387389
return [
388390
{
389391
tag: 'script',
390392
attrs: { type: 'module' },
391-
// !!! Rolldown vite full bunlde module break changes, config.server is invalid
392-
// children: getPreambleCode(config.server!.config.base),
393-
children: getPreambleCode(base!),
393+
children: getPreambleCode(base),
394394
},
395395
]
396396
},
397-
// Rolldown vite full bunlde module break changes.
398-
// Changed it to make sure the inject module could be bundled
397+
// In unbundled mode, Vite transforms any requests.
398+
// But in full bundled mode, Vite only transforms / bundles the scripts injected in `order: 'pre'`.
399399
order: 'pre',
400400
},
401401
}

0 commit comments

Comments
 (0)