example of rslib issues in React Spectrum#9728
Draft
davidferguson wants to merge 1 commit intoadobe:mainfrom
Draft
example of rslib issues in React Spectrum#9728davidferguson wants to merge 1 commit intoadobe:mainfrom
davidferguson wants to merge 1 commit intoadobe:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We are seeing issues in React Spectrum / unplugin-parcel-macros when used in Rslib.
There seems to be a race condition so that the more macros that are used (and the more complex the macros that are used are), the more likely a rslib failure is, resulting in a CSS file not being generated in the virtual filesystem in time, and the build failing as it cannot find it.
Reproduction steps
Success case
cd examples/s2-rslib-semiworking/yarn installyarn buildFailure case
cd examples/s2-rslib-notworking/yarn installyarn buildDebugging notes from AI
TL;DR: It's a race condition in
unplugin-parcel-macros+unplugin's virtual module system within rspack. No config-level fix found yet — likely needs an upstream fix or inlining styles.🔍 The Problem
pnpm nx build out-package-namefails ~50% of the time with:🕵️ Root Cause
The S2
style()macro generates CSS at build time. That CSS lives in:• A module-level
assetsMap insideunplugin-parcel-macros(shared across plugin instances)• Empty placeholder files in
node_modules/.virtual/written by unplugin'sFakeVirtualModulesPluginThe
transformhook generates CSS → adds toassetsMap → appendsimport "macro-<hash>.css"to the source. ThenresolveIdmaps it to a.virtual/file, and theloadhook serves the real CSS from the Map.The race happens within rspack's internal concurrent module processing. Even with a single lib entry and a single rspack compiler, the async
transform → resolveId → loadpipeline has a timing window where virtual CSS module resolution fails.🧪 What I Tested
assets.delete()cleanup.virtual/dir deletion on shutdownassetsMap.virtual/before every buildcssModules: { namedExport: false }💡 Key Takeaways
• Not caused by parallel ESM+CJS — fails with a single lib entry too
• Not caused by stale
.virtual/files — cleaning doesn't help• Not caused by the asset cleanup code — removing it doesn't fix it
• The working repo (
pandora-tooling-demo) has fewer macro files and simpler inlinestyle()calls — smaller race window• Importing style files
with { type: 'macro' }doesn't work — S2 throws an error since the exports are already-expanded values, not macro functions