Skip to content

fix(bundle): include custom collection aliases in the client bundle - #536

Open
giaBaoJS wants to merge 1 commit into
nuxt:mainfrom
giaBaoJS:fix/client-bundle-custom-collection-aliases
Open

fix(bundle): include custom collection aliases in the client bundle#536
giaBaoJS wants to merge 1 commit into
nuxt:mainfrom
giaBaoJS:fix/client-bundle-custom-collection-aliases

Conversation

@giaBaoJS

@giaBaoJS giaBaoJS commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Bug

An alias declared in a custom IconifyJSON collection is missing from the client bundle when clientBundle.includeCustomCollections is on (its default when provider is not server). Rendering <Icon name="paid-icons:house" /> then falls back to runtime loading, and with provider: 'none' it never renders at all.

Reproduction

// nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@nuxt/icon'],
  icon: {
    provider: 'none',
    customCollections: [
      {
        prefix: 'paid-icons',
        icons: { home: { body: '<path d="M0 0h24v24H0z"/>' } },
        aliases: { house: { parent: 'home' } },
        width: 24,
        height: 24,
      },
    ],
  },
})

.nuxt/nuxt-icon-client-bundle.mjs contains paid-icons:home but not paid-icons:house.

Root cause

resolveBundleIcons walks only Object.keys(collection.icons) when bundling a whole custom collection, and an IconifyJSON keeps aliases in a separate aliases map. The two sibling paths already handle them: the server bundle serializes the entire collection JSON and getIcons resolves the alias at request time, and an alias listed explicitly in clientBundle.icons goes through getIconData, which follows the alias tree. Only the whole-collection path skipped them.

The fix walks collection.aliases as well and resolves each name through the same getIconData call, so an alias lands in the bundle as a normal icon with its parent body and its own transforms.

Test

test/bundle.test.ts gains bundles the aliases of a custom collection: a collection with one icon and two aliases (a plain one and an hFlip one) must produce all three names, the alias must carry the parent body, and the flipped alias must keep hFlip: true. Without the change it fails with expected [ 'home' ] to deeply equal [ 'home', 'home-flip', 'house' ].

`includeCustomCollections` walked only `collection.icons`, so an alias
declared in a custom `IconifyJSON` collection never reached the client
bundle, while the server bundle (which ships the whole collection JSON)
and an explicitly listed `clientBundle.icons` entry both resolve it.
@pkg-pr-new

pkg-pr-new Bot commented Sep 6, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/@nuxt/icon@536

commit: 323a167

@coderabbitai

coderabbitai Bot commented Sep 6, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: eb6ab6a6-00b7-4a26-8bc2-65711f989efd

📥 Commits

Reviewing files that changed from the base of the PR and between b878f5b and 323a167.

📒 Files selected for processing (2)
  • src/core/bundle.ts
  • test/bundle.test.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

When includeCustomCollections is enabled, custom collection bundling now resolves both icon names and alias names. The test verifies that aliases are included, inherit the parent icon body, preserve hFlip, and contribute to the bundle count.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 323a1

Custom client bundles now include aliases declared by enabled custom icon collections, including inherited icon data and flip transforms. The targeted behavior is covered, with no remaining current-head merge risk identified.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: including aliases from custom collections in the client bundle.
Description check ✅ Passed The description directly explains the bug, root cause, fix, reproduction, and test coverage for custom collection aliases in the client bundle.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/core/bundle.ts

Parsing error: Unexpected token {

test/bundle.test.ts

Parsing error: Unexpected token {


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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant