Repository navigation
fix(metro): compile the native stylesheet from the authored CSS, never its web build - #461
Open
YevheniiKotyrlo wants to merge 1 commit into
Open
YevheniiKotyrlo wants to merge 1 commit into
YevheniiKotyrlo wants to merge 1 commit into
Conversation
Contributor
Author
…r its web build The transformer compiled Expo's web build of the stylesheet, which lightningcss had lowered for the project's browserslist: `:dir()` became `:lang()` lists the compiler cannot read, `oklch()` gained a second `:root`, and the native output moved with the browserslist. It now runs the project's PostCSS and Sass, in the order Expo's web transform runs them, and compiles their output. Closes nativewind#453
YevheniiKotyrlo
force-pushed
the
fix/metro-native-stylesheet-input
branch
from
October 11, 2026 12:35
3337c2d to
35afc36
Compare
This branch has not been deployed
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.


Problem
The Metro transformer compiles the web build of a stylesheet for a device. That build is
@expo/metro-config'stransformCss: PostCSS, Sass, then lightningcss against the project's browserslist, or browserslist'sdefaultswhen the project declares none. So the native compiler receives CSS lowered for browsers. Measured on a Tailwind v4 entry::dir(rtl)becomes:is(:lang(ae), :lang(ar), …)rtl:/ltr:rule is dropped (#453)oklch()becomeslab(), plus a hex-fallback:rootbeside a@supportscopyinlineVariablesinlines none and each colour utility compiles to a runtime lookuptransform-origin: left top 30pxis re-serialised["0%", 30, 0]instead of[0, 0, 30]All of it moves with the browserslist.
Solution
The transformer runs the project's PostCSS and Sass through the modules Expo's web transform calls, in the same order, and compiles their output. No browser build is produced for a native stylesheet.
transformPostCssModuleresolves and caches the project'spostcss.config.*as the web transform does, so a plugin runs for a device exactly when it runs for a browser.@importdependencies, but the transformer already discarded them.compile()'s own lightningcss pass sets no targets and keeps:dir(); it was handed the wrong input.Both helpers are imported from
@expo/metro-config/build/transform-worker/, which is not listed as public API.Tests
src/__tests__/metro/native-stylesheet-input.test.tsdrives the realtransformagainst a stand-in for Expo's worker.chrome: 100, which predates:dir(), so the lowering happens for real.postcss.config.jsonnaming@tailwindcss/postcss, a@themecolour inoklch(), andbg-[#00f] rtl:bg-[#f00] bg-brand.rtl:bg-[#f00]keeps itsdircondition while the worker is never asked for a web build, andbg-brandinlines to a literal.skipCached output, and three requests that must reach the worker untouched (a web build, a non-stylesheet module, a stylesheet requested as an asset).src/__tests__/metro/native-stylesheet-plain-project.test.tsis a project with no PostCSS config, in its own file because Expo resolves a project's pipeline once per process.src/__tests__/metro/native-stylesheet-sass.test.tsauthors.scss. It stands in for Expo's Sass helper, which resolves the optionalsasspackage from the project root, and for the project's PostCSS. It asserts the hand-off:On
main, 7 of the 14 cases fail; all pass here. Three mutations each fail their own cases: skipping PostCSS, skipping Sass, and handing Sass the authored source.Verification
On Windows with Node 26:
yarn lintcleanyarn typecheckcleanyarn test --maxWorkers=2 --coverage: 1345 passed, 4 failed. The 4 are the babel cases that also fail onmainon this machine.yarn buildcleanyarn example expo export --platform webexportedI also measured broken CSS and changed nothing for it. A malformed selector, a stray brace or an unknown at-rule compiles to the same surviving rules Expo's web pass recovered with
errorRecovery, so a device is not stricter about broken CSS than a browser.Device evidence, before and after: #461 (comment)
Related
Closes #453. That report places the lowering inside
compile(); it happens one hop earlier.Base
Re-written on
main(a5002c5). #451 moved Metro to 0.84, which no longer exportsTransformResponseand dropshotfrom the transform options, so the tests derive the response fromtransform's own return type.