Skip to content

fix(rsc): remove duplicate server css on initial render #702

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Aug 12, 2025

Description

The another PR #681 was removing too early and React ended up injected them on CSR. This PR delays until first useEffect. This is a similar approach as React router https://github.com/remix-run/react-router/blob/166fd940e7d5df9ed005ca68e12de53b1d88324a/packages/react-router/lib/dom-export/hydrated-router.tsx#L245-L274.

TODO

  • test
    • there's no duplicate after CSR
    • there's no duplicate after re-render

@hi-ogawa hi-ogawa requested a review from Copilot August 12, 2025 03:24
@hi-ogawa hi-ogawa added the trigger: preview Trigger pkg.pr.new label Aug 12, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a CSS duplication issue in React Server Components by removing duplicate server-side CSS on initial render in development mode. The fix addresses a specific issue where server-generated CSS links were duplicated in the client.

  • Adds a virtual plugin that creates a client component to remove duplicate CSS links
  • Conditionally includes the CSS removal component only in development mode
  • Integrates the removal component into the Resources function for proper execution

Copy link

pkg-pr-new bot commented Aug 12, 2025

Open in StackBlitz

npm i https://pkg.pr.new/@vitejs/plugin-react@702
npm i https://pkg.pr.new/@vitejs/plugin-react-oxc@702
npm i https://pkg.pr.new/@vitejs/plugin-rsc@702
npm i https://pkg.pr.new/@vitejs/plugin-react-swc@702

commit: ae05b93

@hi-ogawa hi-ogawa marked this pull request as ready for review August 12, 2025 05:39
@hi-ogawa hi-ogawa merged commit 3114e88 into main Aug 12, 2025
21 checks passed
@hi-ogawa hi-ogawa deleted the 08-12-fix_rsc_remove_duplicate_server_css_on_initial_render branch August 12, 2025 05:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
trigger: preview Trigger pkg.pr.new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid duplicate css during dev due to server rendered <link> and client inline <style>
1 participant