GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(rsc): keep CSS wrappers out of a trailing comment when a module has no final newline (fix #1495) by Mheaus · Pull Request #1494 · vitejs/vite-plugin-react

Conversation

@Mheaus

@Mheaus Mheaus commented Oct 9, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Description

Fixes #1495. The issue has a minimal reproduction: https://github.com/Mheaus/vite-plugin-rsc-final-newline-repro

transformWrapExport moves each rewritten export declaration to the end of the module (output.move(start, end, input.length)). The moved code starts with X = __vite_rsc_wrap_css__(...) and no leading newline. When the module has no final newline, that code joins the module's last line.

Compiled packages often end with //# sourceMappingURL=index.js.map and no final newline. The CSS wrapper then becomes part of the comment:

import './index.css';
let MinimalTemplate = props => { /* ... */ };
//# sourceMappingURL=index.js.mapMinimalTemplate = /* #__PURE__ */ __vite_rsc_wrap_css__(MinimalTemplate, "MinimalTemplate");
export { MinimalTemplate };

The wrapper never runs, so loadCss() is never rendered for that component. In a production build, the CSS of that server component is emitted and listed in the assets manifest, but no <link> reaches the page. vite dev is not affected, because it collects CSS from the module graph.

We hit this with Payload CMS 4 (@payloadcms/ui dist files end that way) under React Router RSC mode: the login page, the nav and other server-rendered admin views lost their styles in production builds only.

The fix adds a newline before the first block that is moved to the end, only when the input does not end with one. Modules that end with a newline produce the same output as before. transformModuleExportEffect (used for "use server" modules) already wraps moved code in newlines (\n${code}\n), so it does not have this problem.

The new test module without a final newline fails without the change:

Expected: "//# sourceMappingURL=index.js.map"
Received: "//# sourceMappingURL=index.js.mapArrow = /* #__PURE__ */ $$wrap(Arrow, "<id>", "Arrow");"

All 520 tests in src/transforms pass with it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Mheaus
fix(rsc): keep CSS wrappers out of a trailing comment when a module h…
027d10c
…as no final newline
@Mheaus Mheaus mentioned this pull request Oct 9, 2026
plugin-rsc: a server component's CSS is not linked in production when its module has no final newline #1495
Closed
6 tasks done
@Mheaus Mheaus changed the title fix(rsc): keep CSS wrappers out of a trailing comment when a module has no final newline fix(rsc): keep CSS wrappers out of a trailing comment when a module has no final newline (fix #1495) Oct 9, 2026
hi-ogawa and others added 5 commits October 13, 2026 17:28
@hi-ogawa @claude
refactor(rsc): normalize final newline before wrapping exports
84b964a
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@hi-ogawa @claude
chore(rsc): simplify final newline comment
f81dab6
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@hi-ogawa @claude
refactor(rsc): drop leading semicolon from appended wrapper code
488bec3
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@hi-ogawa @claude
test(rsc): cover moved and appended code without a final newline
b4d9991
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@hi-ogawa @claude
revert(rsc): keep leading semicolon in appended wrapper code
713db30
Co-Authored-By: Claude Opus 5.5 <[email protected]>
hi-ogawa
hi-ogawa approved these changes Oct 13, 2026
View reviewed changes

@hi-ogawa hi-ogawa left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks! I've simplified approach to align with

vite-plugin-react/packages/plugin-rsc/src/transforms/hoist.ts

Lines 134 to 138 in e77496b

// MagicString needs an existing boundary at the move destination. The newline
// also keeps the first appended declaration separate from the original source.
if (!input.endsWith('\n')) {
input += '\n'
}

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Mheaus reacted with thumbs up emoji Mheaus reacted with heart emoji
All reactions
  • 👍 1 reaction
  • ❤️ 1 reaction
@hi-ogawa
Merge branch 'main' into fix/rsc-wrap-export-final-newline
7e58e2d
@Mheaus

Mheaus commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks! I've simplified approach to align with

vite-plugin-react/packages/plugin-rsc/src/transforms/hoist.ts

Lines 134 to 138 in e77496b

// MagicString needs an existing boundary at the move destination. The newline
// also keeps the first appended declaration separate from the original source.
if (!input.endsWith('\n')) {
input += '\n'
}

Of course 👌
I would be glad to help on other subjects if you need help.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hi-ogawa
hi-ogawa merged commit 9a68f29 into vitejs:main Oct 13, 2026
19 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@vite-release-bot vite-release-bot Bot mentioned this pull request Oct 13, 2026
release: [email protected] #1504
Merged
@hi-ogawa hi-ogawa mentioned this pull request Oct 26, 2026
plugin-rsc: rsc-css-export-transform drops the CSS wrapper when a module ends in a line comment with no trailing newline #1532
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@hi-ogawa hi-ogawa hi-ogawa approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

plugin-rsc: a server component's CSS is not linked in production when its module has no final newline

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@Mheaus @hi-ogawa
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.