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
30 changes: 25 additions & 5 deletions packages/plugin-rsc/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { generateEncryptionKey, toBase64 } from './utils/encryption-utils'
import { createRpcServer } from './utils/rpc'
import {
cleanUrl,
directRequestRE,
evalValue,
normalizeViteImportAnalysisUrl,
prepareError,
Expand Down Expand Up @@ -563,11 +564,7 @@ export default function vitePluginRsc(
async hotUpdate(ctx) {
if (isCSSRequest(ctx.file)) {
if (this.environment.name === 'client') {
// filter out `.css?direct` (injected by SSR) to avoid browser full reload
// when changing non-self accepting css such as `module.css`.
return ctx.modules.filter(
(m) => !(m.id?.includes('?direct') && !m.isSelfAccepting),
)
return
}
}

Expand Down Expand Up @@ -1976,6 +1973,29 @@ function vitePluginRscCss(
}
},
},
{
// force self accepting "?direct" css (injected via SSR `<link />`) to avoid full reload.
// this should only apply to css modules
// https://github.com/vitejs/vite/blob/84079a84ad94de4c1ef4f1bdb2ab448ff2c01196/packages/vite/src/node/plugins/css.ts#L1096
name: 'rsc:rsc-css-self-accept',
apply: 'serve',
transform: {
order: 'post',
handler(_code, id, _options) {
if (
this.environment.name === 'client' &&
this.environment.mode === 'dev' &&
isCSSRequest(id) &&
directRequestRE.test(id)
) {
const mod = this.environment.moduleGraph.getModuleById(id)
if (mod && !mod.isSelfAccepting) {
mod.isSelfAccepting = true
}
}
},
},
},
{
name: 'rsc:css-virtual',
resolveId(source) {
Expand Down
3 changes: 3 additions & 0 deletions packages/plugin-rsc/src/plugins/vite-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,6 @@ export function evalValue<T = any>(rawValue: string): T {
`)
return fn()
}

// https://github.com/vitejs/vite/blob/84079a84ad94de4c1ef4f1bdb2ab448ff2c01196/packages/vite/src/node/utils.ts#L321
export const directRequestRE: RegExp = /(\?|&)direct=?(?:&|$)/
Loading