Skip to content

Commit 3d42878

Browse files
Merge remote-tracking branch 'upstream/main' into chore-rsc-nightly
2 parents d5793ca + a39d837 commit 3d42878

File tree

2 files changed

+52
-35
lines changed

2 files changed

+52
-35
lines changed

packages/plugin-react/src/index.ts

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -340,43 +340,43 @@ export default function viteReact(opts: Options = {}): Plugin[] {
340340
},
341341
}
342342

343+
// for rolldown-vite
343344
const viteRefreshWrapper: Plugin = {
344345
name: 'vite:react:refresh-wrapper',
345346
apply: 'serve',
346-
transform: isRolldownVite
347-
? {
348-
filter: {
349-
id: {
350-
include: makeIdFiltersToMatchWithQuery(include),
351-
exclude: makeIdFiltersToMatchWithQuery(exclude),
352-
},
353-
},
354-
handler(code, id, options) {
355-
const ssr = options?.ssr === true
356-
357-
const [filepath] = id.split('?')
358-
const isJSX = filepath.endsWith('x')
359-
const useFastRefresh =
360-
!skipFastRefresh &&
361-
!ssr &&
362-
(isJSX ||
363-
code.includes(jsxImportDevRuntime) ||
364-
code.includes(jsxImportRuntime))
365-
if (!useFastRefresh) return
366-
367-
const { code: newCode } = addRefreshWrapper(
368-
code,
369-
avoidSourceMapOption,
370-
'@vitejs/plugin-react',
371-
id,
372-
opts.reactRefreshHost,
373-
)
374-
return { code: newCode, map: null }
375-
},
376-
}
377-
: undefined,
347+
transform: {
348+
filter: {
349+
id: {
350+
include: makeIdFiltersToMatchWithQuery(include),
351+
exclude: makeIdFiltersToMatchWithQuery(exclude),
352+
},
353+
},
354+
handler(code, id, options) {
355+
const ssr = options?.ssr === true
356+
357+
const [filepath] = id.split('?')
358+
const isJSX = filepath.endsWith('x')
359+
const useFastRefresh =
360+
!skipFastRefresh &&
361+
!ssr &&
362+
(isJSX ||
363+
code.includes(jsxImportDevRuntime) ||
364+
code.includes(jsxImportRuntime))
365+
if (!useFastRefresh) return
366+
367+
const { code: newCode } = addRefreshWrapper(
368+
code,
369+
avoidSourceMapOption,
370+
'@vitejs/plugin-react',
371+
id,
372+
opts.reactRefreshHost,
373+
)
374+
return { code: newCode, map: null }
375+
},
376+
},
378377
}
379378

379+
// for rolldown-vite
380380
const viteConfigPost: Plugin = {
381381
name: 'vite:react:config-post',
382382
enforce: 'post',
@@ -449,7 +449,11 @@ export default function viteReact(opts: Options = {}): Plugin[] {
449449
},
450450
}
451451

452-
return [viteBabel, viteRefreshWrapper, viteConfigPost, viteReactRefresh]
452+
return [
453+
viteBabel,
454+
...(isRolldownVite ? [viteRefreshWrapper, viteConfigPost] : []),
455+
viteReactRefresh,
456+
]
453457
}
454458

455459
viteReact.preambleCode = preambleCode

packages/plugin-rsc/src/transforms/wrap-export.test.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ export const a = 0;
227227
export const b = function() {}
228228
export const c = () => {}
229229
export default function d() {}
230-
export default () => {}
231230
`
232231
const result = await testTransform(input, {
233232
filter: (_name, meta) => !!(meta.isFunction && meta.declName),
@@ -238,7 +237,6 @@ export default () => {}
238237
let b = function() {}
239238
let c = () => {}
240239
function d() {}
241-
const $$default = () => {}
242240
export { a };
243241
b = /* #__PURE__ */ $$wrap(b, "<id>", "b");
244242
export { b };
@@ -247,6 +245,21 @@ export default () => {}
247245
;
248246
const $$wrap_d = /* #__PURE__ */ $$wrap(d, "<id>", "default");
249247
export { $$wrap_d as default };
248+
"
249+
`)
250+
})
251+
252+
test('filter meta 2', async () => {
253+
const input = `
254+
export default () => {}
255+
`
256+
const result = await testTransform(input, {
257+
filter: (_name, meta) => !!(meta.isFunction && meta.declName),
258+
})
259+
expect(result).toMatchInlineSnapshot(`
260+
"
261+
const $$default = () => {}
262+
;
250263
export { $$default as default };
251264
"
252265
`)

0 commit comments

Comments
 (0)