stylex icon indicating copy to clipboard operation
stylex copied to clipboard

`data-style-src` does not respect `inputSourceMap`

Open deadalnix opened this issue 4 months ago • 3 comments

Describe the issue

Hi,

When a file that already has been preprocessed is fed to the StyleX babel plugin, the plugin emits data-style-src with the file and line from the already processed file.

Expected behavior

The plugin should look a the source map and provide the file and line from the original source code in data-style-src, not some intermediary state.

Steps to reproduce

Create a file using StyleX and something requiring rewrite of the source code, such as react.

Process the JSX using babel, get a source map out of it.

Call babel a second time, this time to process StyleX, pass the source map generated in the first call as inputSourceMap when calling babel's transformAsync.

Source and line number emitted for data-style-src correspond to the one in the intermediate state of the file, not it's original state.

Test case

No response

Additional comments

No response

deadalnix avatar Aug 08 '25 17:08 deadalnix

While this is a valid feature request, can I ask what your build setup is?

Generally, it should not be necessary to compile StyleX in a separate Babel pass than the rest of your transforms which would make this a non-issue for most use-cases.

And when used as a separate Babel pass, it's usually best practice to run StyleX before other transforms that could simplify the output from the StyleX compiler.

nmn avatar Aug 12 '25 05:08 nmn

I'm using StyleX within a Vite project. Vite does not handle babel directly and won't use it if not necessary. Transforms involving babel are down through rollup plugins.

Note that the rollup example in this very repo has the same issue where it'll emit erroneous line numbers if there is a previous rollup plugin doing another transform.

deadalnix avatar Aug 13 '25 03:08 deadalnix

We’ve also got the same problem :( @nmn would be open to accepting a PR if I can get the team here to fix it?

matclayton avatar Nov 05 '25 12:11 matclayton