Skip to content

Conversation

BobbieGoede
Copy link
Member

@BobbieGoede BobbieGoede commented Sep 24, 2025

🔗 Linked issue

📚 Description

Right now the server build will have style chunks that import and export the same css file as seen in the screenshot below. This also results in extra files being generated.

Screenshot of current output image
Screenshot of output with this PR image

Not sure if this is an ideal solution but it seems to work.

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@BobbieGoede BobbieGoede changed the title fix: duplicate server style imports fix(vite): duplicate server style imports Sep 24, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Sep 24, 2025

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@33308

nuxt

npm i https://pkg.pr.new/nuxt@33308

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@33308

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@33308

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@33308

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@33308

commit: 2da9ba8

@coderabbitai
Copy link

coderabbitai bot commented Sep 24, 2025

Walkthrough

The file packages/vite/src/plugins/ssr-styles.ts was changed to collect CSS imports and export names into sets (cssImports, exportNames, importStatements) to deduplicate entries. Import statements are generated via genImport for each unique CSS file and the default export array is emitted using genArrayFromRaw from the collected export names. The previous per-file inline import/array construction was replaced by this deduplicated, set-based emission; control flow and error handling are otherwise unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title "fix(vite): duplicate server style imports" succinctly and accurately captures the primary change — a Vite-related bugfix that removes duplicate server-side CSS imports; it is concise and follows conventional commit style, so a reviewer scanning history will understand the main intent.
Description Check ✅ Passed The PR description directly describes the observed problem (duplicate server style imports), includes before/after screenshots and a brief note on the proposed solution, so it is clearly related to the changeset and provides useful context for reviewers.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3efc4f7 and 2da9ba8.

📒 Files selected for processing (1)
  • packages/vite/src/plugins/ssr-styles.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/vite/src/plugins/ssr-styles.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build
  • GitHub Check: code

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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 and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/vite/src/plugins/ssr-styles.ts (1)

82-85: Avoid './..' specifiers and shadowing; keep imports clean and stable

  • Prepending './' unconditionally can yield paths like './../x.mjs'. Guard it so we only prepend when needed.
  • Minor: avoid shadowing the outer file variable in the map callback for clarity.

Apply this diff:

-        const uniqueFiles = [...new Set(files.map(css => this.getFileName(css)))]
-        const styleImports = uniqueFiles.map((file, i) => ({ name: `style_${i}`, path: `./${relative(baseDir, file)}` }))
+        const uniqueFiles = [...new Set(files.map(css => this.getFileName(css)))]
+        const styleImports = uniqueFiles.map((chunkPath, i) => {
+          const rel = relative(baseDir, chunkPath)
+          const path = rel.startsWith('.') ? rel : `./${rel}`
+          return { name: `style_${i}`, path }
+        })

Optional follow-up (broader): if duplicates are causing extra emitted chunks (not just duplicate imports), consider caching emitted chunk refs across transforms:

// at plugin top-level
const emittedById = new Map<string, string>() // key: resolvedId+'?inline&used', value: ref

// before emitting a chunk in transform()
const chunkId = (resolved.id ?? file) + '?inline&used'
const ref = emittedById.get(chunkId) ?? this.emitFile({ type: 'chunk', name: `${filename(id)}-styles-${++styleCtr}.mjs`, id: chunkId })
emittedById.set(chunkId, ref)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cb2b9d5 and 3efc4f7.

📒 Files selected for processing (1)
  • packages/vite/src/plugins/ssr-styles.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Follow standard TypeScript conventions and best practices

Files:

  • packages/vite/src/plugins/ssr-styles.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
  • GitHub Check: test-fixtures (windows-latest, built, vite, default, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, dev, vite, async, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, built, rspack, async, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, rspack, async, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, webpack, async, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-off, json, lts/-1)
  • GitHub Check: release-pkg-pr-new
  • GitHub Check: test-size
  • GitHub Check: typecheck (windows-latest, bundler)
  • GitHub Check: typecheck (ubuntu-latest, bundler)
  • GitHub Check: code
🔇 Additional comments (2)
packages/vite/src/plugins/ssr-styles.ts (2)

4-4: LGTM on knitwork helpers import

The added imports are appropriate for the new codegen approach and used correctly below.


89-90: LGTM: deterministic imports and export generation

Using genImport and genArrayFromRaw makes the generated module concise and consistent, and pairs well with the deduped list.

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 24, 2025

CodSpeed Performance Report

Merging #33308 will not alter performance

Comparing BobbieGoede:fix/duplicate-server-style-imports (2da9ba8) with main (cb2b9d5)

Summary

✅ 10 untouched

@danielroe danielroe merged commit d3ce79f into nuxt:main Sep 25, 2025
83 of 84 checks passed
@github-actions github-actions bot mentioned this pull request Sep 25, 2025
@github-actions github-actions bot mentioned this pull request Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants