Skip to content
Closed
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
16 changes: 15 additions & 1 deletion packages/plugin-rsc/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ window.__vite_plugin_react_preamble_installed__ = true;
const ssrCss = document.querySelectorAll("link[rel='stylesheet']");
import.meta.hot.on("vite:beforeUpdate", () => {
ssrCss.forEach(node => {
if (node.dataset.precedence?.startsWith("vite-rsc/")) {
if (node.dataset.precedence === "vite-rsc/client-reference") {
node.remove();
}
});
Expand Down Expand Up @@ -1888,6 +1888,20 @@ export function vitePluginRscCss(
// ensure hmr boundary at this virtual since otherwise non-self accepting css
// (e.g. css module) causes full reload
code += `if (import.meta.hot) { import.meta.hot.accept() }\n`
// remove server rendered <link> after inline <style> is injected on client
// to avoid duplicate styles
function removeFn(hrefs: string[]) {
for (const href of hrefs) {
const el = document.querySelector(
`link[rel="stylesheet"][href="${href}"]`,
)
console.log({ href, el })
if (el) {
el.remove()
}
}
}
code += `(${removeFn.toString()})(${JSON.stringify(result.hrefs)});\n`
return code
}
},
Expand Down
Loading