Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/plugin-rsc/examples/basic/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export default defineConfig({
},
// disable auto css injection to manually test `loadCss` feature.
rscCssTransform: false,
ignoredPackageWarnings: [/@vitejs\/test-dep-/],
copyServerAssetsToClient: (fileName) =>
fileName !== '__server_secret.txt',
}),
Expand Down
41 changes: 15 additions & 26 deletions packages/plugin-rsc/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
} from './vite-utils'
import { cjsModuleRunnerPlugin } from './plugins/cjs'
import { evalValue, parseIdQuery } from './plugins/utils'
import { createDebug } from '@hiogawa/utils'

// state for build orchestration
let serverReferences: Record<string, string> = {}
Expand Down Expand Up @@ -98,6 +99,7 @@ export type RscPluginOptions = {

rscCssTransform?: false | { filter?: (id: string) => boolean }

/** @deprecated use "DEBUG=vite-env:*" to see warnings. */
ignoredPackageWarnings?: (string | RegExp)[]

/**
Expand Down Expand Up @@ -939,7 +941,7 @@ function hashString(v: string) {
function vitePluginUseClient(
useClientPluginOptions: Pick<
RscPluginOptions,
'ignoredPackageWarnings' | 'keepUseCientProxy' | 'environment'
'keepUseCientProxy' | 'environment'
>,
): Plugin[] {
const packageSources = new Map<string, string>()
Expand Down Expand Up @@ -969,6 +971,8 @@ function vitePluginUseClient(
}
}

const debug = createDebug('vite-rsc:use-client')

return [
{
name: 'rsc:use-client',
Expand All @@ -992,18 +996,9 @@ function vitePluginUseClient(
// expectation on dependency optimizer on browser. Directly copying over
// "?v=<hash>" from client optimizer in client reference can make a hashed
// module stale, so we use another virtual module wrapper to delay such process.
// TODO: suggest `optimizeDeps.exclude` and skip warning if that's already the case.
const ignored = useClientPluginOptions.ignoredPackageWarnings?.some(
(pattern) =>
pattern instanceof RegExp
? pattern.test(id)
: id.includes(`/node_modules/${pattern}/`),
debug(
`internal client reference created through a package imported in '${this.environment.name}' environment: ${id}`,
)
if (!ignored) {
this.warn(
`[vite-rsc] detected an internal client boundary created by a package imported on rsc environment`,
)
}
id = cleanUrl(id)
warnInoncistentClientOptimization(this, id)
importId = `/@id/__x00__virtual:vite-rsc/client-in-server-package-proxy/${encodeURIComponent(id)}`
Expand Down Expand Up @@ -1232,13 +1227,15 @@ function vitePluginDefineEncryptionKey(
function vitePluginUseServer(
useServerPluginOptions: Pick<
RscPluginOptions,
'ignoredPackageWarnings' | 'enableActionEncryption' | 'environment'
'enableActionEncryption' | 'environment'
>,
): Plugin[] {
const serverEnvironmentName = useServerPluginOptions.environment?.rsc ?? 'rsc'
const browserEnvironmentName =
useServerPluginOptions.environment?.browser ?? 'client'

const debug = createDebug('vite-rsc:use-server')

return [
{
name: 'rsc:use-server',
Expand All @@ -1253,20 +1250,12 @@ function vitePluginUseServer(
this.environment.mode === 'dev' &&
id.includes('/node_modules/')
) {
const ignored =
useServerPluginOptions.ignoredPackageWarnings?.some(
(pattern) =>
pattern instanceof RegExp
? pattern.test(id)
: id.includes(`/node_modules/${pattern}/`),
)
if (!ignored) {
this.warn(
`[vite-rsc] detected an internal server function created by a package imported on ${this.environment.name} environment`,
)
}
// module runner has additional resolution step and it's not strict about
// similar situation as `use client` (see `virtual:client-in-server-package-proxy`)
// but module runner has additional resolution step and it's not strict about
// module identity of `import(id)` like browser, so we simply strip queries such as `?v=`.
debug(
`internal server reference created through a package imported in ${this.environment.name} environment: ${id}`,
)
id = cleanUrl(id)
}
if (config.command === 'build') {
Expand Down
Loading