Skip to content

Commit 991b015

Browse files
committed
fix(rsc): fix false detecting import.meta.viteRsc API inside comment
1 parent 4b2768f commit 991b015

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

packages/plugin-rsc/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"estree-walker": "^3.0.3",
4545
"magic-string": "^0.30.19",
4646
"periscopic": "^4.0.2",
47+
"strip-literal": "^3.1.0",
4748
"turbo-stream": "^3.1.0",
4849
"vitefu": "^1.1.1"
4950
},

packages/plugin-rsc/src/plugin.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import { scanBuildStripPlugin } from './plugins/scan'
5555
import { validateImportPlugin } from './plugins/validate-import'
5656
import { vitePluginFindSourceMapURL } from './plugins/find-source-map-url'
5757
import { parseCssVirtual, toCssVirtual, parseIdQuery } from './plugins/shared'
58+
import { stripLiteral } from 'strip-literal'
5859

5960
const isRolldownVite = 'rolldownVersion' in vite
6061

@@ -702,7 +703,7 @@ export default function vitePluginRsc(
702703
if (!code.includes('import.meta.viteRsc.loadModule')) return
703704
const { server } = manager
704705
const s = new MagicString(code)
705-
for (const match of code.matchAll(
706+
for (const match of stripLiteral(code).matchAll(
706707
/import\.meta\.viteRsc\.loadModule\(([\s\S]*?)\)/dg,
707708
)) {
708709
const argCode = match[1]!.trim()
@@ -973,7 +974,7 @@ export default assetsManifest.bootstrapScriptContent;
973974
assert(this.environment.name !== 'client')
974975
const output = new MagicString(code)
975976

976-
for (const match of code.matchAll(
977+
for (const match of stripLiteral(code).matchAll(
977978
/import\s*\.\s*meta\s*\.\s*viteRsc\s*\.\s*loadBootstrapScriptContent\(([\s\S]*?)\)/dg,
978979
)) {
979980
const argCode = match[1]!.trim()
@@ -2087,7 +2088,7 @@ function vitePluginRscCss(
20872088
const output = new MagicString(code)
20882089
let importAdded = false
20892090

2090-
for (const match of code.matchAll(
2091+
for (const match of stripLiteral(code).matchAll(
20912092
/import\.meta\.viteRsc\.loadCss\(([\s\S]*?)\)/dg,
20922093
)) {
20932094
const [start, end] = match.indices![0]!

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)