fix(vite): drop duplicate CSS links for fully inlined shared chunks by danielroe · Pull Request #36056 · nuxt/nuxt · GitHub
Skip to content

fix(vite): drop duplicate CSS links for fully inlined shared chunks - #36056

Merged
danielroe merged 6 commits into
mainfrom
fix/css-duplication
Aug 12, 2026
Merged

danielroe merged 6 commits into
mainfrom
fix/css-duplication

Conversation

@danielroe

Copy link
Copy Markdown
Member

🔗 Linked issue

resolves #35255
related #30435, #34950, #34008, #35649

📚 Description

this allows shared chunks to be stripped (issue is that shared rolldown chunks have no facadeModuleId).

@github-actions github-actions Bot added 5.x 🐛 bug Something isn't working as expected labels Aug 12, 2026
@pkg-pr-new

pkg-pr-new Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

@coderabbitai

coderabbitai Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 06d7375b-3f8a-479f-b03a-31ee49281af8

📥 Commits

Reviewing files that changed from the base of the PR and between 0ed45bf and 3c4be45.

📒 Files selected for processing (2)
  • packages/vite/src/plugins/ssr-styles.ts
  • test/inline-styles.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • test/inline-styles.test.ts
  • packages/vite/src/plugins/ssr-styles.ts

Walkthrough

The SSR styles plugin now records client module importers and maps emitted CSS filenames to their source modules. Manifest cleanup tracks CSS consumers and removes stylesheet links only when every importer path inlines the CSS, including shared and source-less chunks. Client bundle processing builds these maps before returning. Tests cover shared CSS retention and inlineStyles predicates for pages that inline or retain linked stylesheets.

Mergeability Score: 🔵 Low · up to 3c4be

The PR removes duplicate CSS links for fully inlined shared chunks. A bounded merge-readiness risk remains because the tests may not detect cases where styles are both inlined and linked; merge is reasonable with explicit follow-up to assert that duplicate links are absent.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main fix for duplicate CSS links in fully inlined shared chunks.
Description check ✅ Passed The description explains the shared-chunk issue and connects the change to linked issue #35255.
Linked Issues check ✅ Passed The implementation and tests address #35255 by removing duplicate CSS links while retaining links when CSS is not fully inlined.
Out of Scope Changes check ✅ Passed The implementation, regression tests, and fixtures are directly related to shared-chunk CSS inlining and link cleanup.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/css-duplication

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/vite/src/plugins/ssr-styles.ts`:
- Around line 136-137: Update the shared-chunk cleanup around cssSources and the
allInlined/inlinedCSSModuleIds logic so inlining state is tracked per manifest
consumer or entry rather than globally. When nuxt.options.features.inlineStyles
is function-valued, conservatively skip this cleanup to prevent one consumer’s
decision from removing CSS needed by another. Add a regression fixture where the
predicate returns different results for consumers.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 86587f04-dce1-448d-82ef-327daa47b001

📥 Commits

Reviewing files that changed from the base of the PR and between 79ef035 and dba68d8.

📒 Files selected for processing (2)
  • packages/vite/src/plugins/ssr-styles.ts
  • test/inline-styles.test.ts

Comment thread packages/vite/src/plugins/ssr-styles.ts Outdated
@codspeed

codspeed Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 21 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing fix/css-duplication (3c4be45) with main (69524fe)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/vite/src/plugins/ssr-styles.ts`:
- Around line 107-113: Update the CSS source aggregation near the mapping logic
at lines 287-290 to merge each chunk’s source IDs into the existing set for a
CSS filename instead of overwriting it. In isDroppableCSSFile, treat a missing
source mapping as non-droppable by returning false, while preserving the
existing all-importers-inlined check for present source sets.

In `@test/inline-styles.test.ts`:
- Around line 54-61: Strengthen the inline-styles tests by separating
inline-style content from linked stylesheet content: in the retain-linked-CSS
test, assert the token is absent from inline styles and cssLinks is non-empty
before checking linked files; in the opted-in predicate test, assert cssLinks is
empty while preserving its inline-token assertion. Reuse the file’s existing
style and link extraction helpers or patterns.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 75354c81-e154-4642-bf5e-650a53c63e2d

📥 Commits

Reviewing files that changed from the base of the PR and between dba68d8 and 0ed45bf.

⛔ Files ignored due to path filters (2)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
  • test/fixtures/inline-styles-predicate/package.json is excluded by !**/package.json
📒 Files selected for processing (13)
  • packages/vite/src/plugins/ssr-styles.ts
  • test/fixtures/inline-styles-predicate/app.vue
  • test/fixtures/inline-styles-predicate/assets/shared.css
  • test/fixtures/inline-styles-predicate/components/SharedBox.vue
  • test/fixtures/inline-styles-predicate/nuxt.config.ts
  • test/fixtures/inline-styles-predicate/pages/inlined.vue
  • test/fixtures/inline-styles-predicate/pages/not-inlined.vue
  • test/fixtures/inline-styles-predicate/tsconfig.json
  • test/fixtures/inline-styles/assets/shared-with-js-module.css
  • test/fixtures/inline-styles/components/shared-css-module.js
  • test/fixtures/inline-styles/pages/shared-css-direct.vue
  • test/fixtures/inline-styles/pages/shared-css-via-js.vue
  • test/inline-styles.test.ts

Comment thread packages/vite/src/plugins/ssr-styles.ts
Comment on lines +54 to +61

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Strengthen the stylesheet-link assertions.

At Lines 54-61, the test searches the document HTML and linked files as one string. It passes when the CSS is inlined and cssLinks is empty. It also passes when the CSS is both inlined and linked.

At Lines 138-142, the opted-in predicate test only checks for the token in inline styles. It does not verify that the stylesheet link was removed.

When the page must retain linked CSS, assert that the token is absent from inline styles and that cssLinks is non-empty before checking the linked files. When the page must fully inline CSS, assert that cssLinks is empty.

Suggested assertion changes
-    expect([html, ...linked].join('\n')).toContain('--inline-shared-with-js-module-token:shared-with-js-module')
+    expect(inlinedStyles).not.toContain('--inline-shared-with-js-module-token:shared-with-js-module')
+    expect(cssLinks.length).toBeGreaterThan(0)
+    expect(linked.join('\n')).toContain('--inline-shared-with-js-module-token:shared-with-js-module')

     expect(inlinedStyles).toContain('--inline-predicate-shared-token:predicate-shared')
+    expect(cssLinks).toEqual([])

Reuse the existing style and link extraction patterns in this file.

Also applies to: 138-142

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/inline-styles.test.ts` around lines 54 - 61, Strengthen the
inline-styles tests by separating inline-style content from linked stylesheet
content: in the retain-linked-CSS test, assert the token is absent from inline
styles and cssLinks is non-empty before checking linked files; in the opted-in
predicate test, assert cssLinks is empty while preserving its inline-token
assertion. Reuse the file’s existing style and link extraction helpers or
patterns.

@danielroe
danielroe added this pull request to the merge queue Aug 12, 2026
Merged via the queue into main with commit 060d9c3 Aug 12, 2026
35 checks passed
@danielroe
danielroe deleted the fix/css-duplication branch August 12, 2026 23:01
@github-actions github-actions Bot mentioned this pull request Aug 12, 2026
2 of 5 tasks
@github-actions github-actions Bot mentioned this pull request Aug 12, 2026
This was referenced Aug 25, 2026
@github-actions github-actions Bot mentioned this pull request Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5.x 🐛 bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CSS is duplicated between <link> and <style>

1 participant