Skip to content

fix(processor): validate external composes references - #1168

Open
NiedziolkaMichal wants to merge 1 commit into
tivac:mainfrom
NiedziolkaMichal:fix/validate-external-composes
Open

NiedziolkaMichal wants to merge 1 commit into
tivac:mainfrom
NiedziolkaMichal:fix/validate-external-composes

Conversation

@NiedziolkaMichal

@NiedziolkaMichal NiedziolkaMichal commented Sep 25, 2026 •

Copy link
Copy Markdown

Description

composes: x from "file.css" now fails with the same error that local composes references already use:

Invalid composes reference, .x does not exist in file.css

The check goes in the external-reference branch of plugins/composition.js, next to the existing check for local references. files[source] is always populated at that point: the dependency is processed before the file that composes from it, and a file that can't be found is already rejected earlier ("Unable to locate …").

Motivation and Context

Fixes #1167. Previously a missing class in another file wasn't detected until compositions were generated, which crashed with TypeError: composition is not iterable (cannot read property undefined). That error doesn't name the file or the class. Integrations that generate output late, like a webpack processAssets hook, hit it after the build has already succeeded. In webpack watch mode that error is fatal and stops rebuilds until a restart.

How Has This Been Tested?

  • Added a test in packages/processor/test/composition.test.js. It fails without the change and passes with it.
  • node --test packages/processor/test/*.test.js: 148 passing.
  • npm run lint: clean.
  • Checked with the repro from composition is not iterable #1167: processor.file() now rejects with Invalid composes reference and points at the line in b.css.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have added a changeset for my change.

The issue, commit & PR were generated with claude. This is a real problem though, affecting our users. I hope you don't mind and we will be able to merge this quickly.

`composes: x from "file.css"` didn't check that `x` exists in `file.css`.
The missing class was only detected when generating compositions, which
crashed with `TypeError: composition is not iterable`. Fail early with
the same `Invalid composes reference` error as local references.

Fixes tivac#1167

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Sep 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2fe0ed6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@modular-css/processor Patch
@modular-css/cli Patch
@modular-css/css-to-js Patch
@modular-css/glob Patch
@modular-css/rollup Patch
@modular-css/svelte Patch
@modular-css/vite Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify

netlify Bot commented Sep 25, 2026

Copy link
Copy Markdown

✅ Deploy Preview for m-css ready!

Name Link
🔨 Latest commit 2fe0ed6
🔍 Latest deploy log https://app.netlify.com/projects/m-css/deploys/6ab63f9b43500b0008158ccb
😎 Deploy Preview https://deploy-preview-1168--m-css.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

This branch has not been deployed

No deployments
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.

composition is not iterable

1 participant