Skip to content

fix: processVanillaFile fileScopes race #1585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sashank-gogula-glean
Copy link

Problem

processVanillaFile (1) awaits while serializing css for each fileScope. For a file with multiple fileScopes (which happens when one .css.ts file imports another), it will yield to the event loop before calling transformCss on the next fileScope.

If the integration is handling multiple files concurrently, it could yield to another processVanillaFile (2).

Since all processVanillaFile calls share one adapaterStack, (2) could push its adapter onto the stack and then yield back to (1) while (2) is awaiting serialization.

If this happens, currentAdapter will point to the adapter of (2) for the transformCss of the next fileScope in (1).

This causes the markCompositionUsed called by transformCss to update the wrong adapter. unusedCompositions of (1) would then include an identifier that was actually used. The identifier is then stripped and any selectors that referenced it will not work.

The new test in processVanillaFile.test.ts fails without this change.

Solution

Add the scoped adapter to the stack before calling functions that use it (evalCode and transformCss) and remove the adapter before any awaits. This way currentAdapter will always point to the relevant adapter.

Context

Pretty sure this is what's going on here: #654

Copy link

changeset-bot bot commented May 10, 2025

⚠️ No Changeset found

Latest commit: 479dfe8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

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