Open Bug 1631296 Opened 5 years ago Updated 4 years ago

Inline style element sourcemaps not working in Firefox

Categories

(DevTools :: Inspector, defect, P3)

75 Branch
Desktop
macOS
defect

Tracking

(Not tracked)

People

(Reporter: laheen, Unassigned)

References

(Blocks 1 open bug)

Details

Attachments

(3 files)

Attached image Chrome works, Firefox + Safari broken (deleted) —

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:75.0) Gecko/20100101 Firefox/75.0

Steps to reproduce:

https://github.com/atlassian-labs/compiled-css-in-js/pull/153

git clone git@github.com:atlassian-labs/compiled-css-in-js.git
cd compiled-css-in-js
git checkout source-maps
yarn
yarn start

Actual results:

  1. Storybook opens
  2. I inspect a Compiled Component element
  3. Look at source location, note it says "inline" instead of the file name
  4. The link to the file is also broken

This bug (or incorrect setup, hopefully!) also affects emotion.sh/

Expected results:

The sourcemap should have been picked up and the link into Style Editor works.

As note - this works correctly in Chrome. It does not work in Safari either.

Hi laheen!
Please could you add some test cases or more exact steps to test this problem?
Also, you can try to reproduce it on latest Nightly and tell us your input.
You can download from here: https://nightly.mozilla.org/.
Thanks!

Flags: needinfo?(laheen)
Attached file inline-static-sourcemap.html (deleted) —

Please find attached a reduced test case.

This source map works in Chrome. It doesn't work in Firefox.

You can see the module.tsx available in the Style Editor.

Flags: needinfo?(laheen)

I tested on Firefox nightly - the issue still occurs

Bugbug thinks this bug should belong to this component, but please revert this change in case of error.

Component: Untriaged → Inspector
Product: Firefox → DevTools

Thanks for filing!

Priority: -- → P3

(In reply to laheen from comment #2)

Created attachment 9143411 [details]
inline-static-sourcemap.html

Please find attached a reduced test case.

This source map works in Chrome. It doesn't work in Firefox.

You can see the module.tsx available in the Style Editor.

I was able to reproduce it following the steps mentioned above on latest Nightly on MacOS 10.14
I attached a file with evidence and changed flags accordingly.

Severity: normal → minor
Status: UNCONFIRMED → NEW
Ever confirmed: true
OS: Unspecified → macOS
Hardware: Unspecified → Desktop
Severity: minor → normal

The severity field is not set for this bug.
:gl, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(gl)

Hi :) Do you need more information from me or you have enough to go off?

Hello! I was hoping with this release https://hacks.mozilla.org/2020/06/new-in-firefox-77-devtool-improvements-and-web-platform-updates/ this bug would be fixed. It doesn't seem to be the case though.

Any idea if this can be fixed? Would be a big boon for developers writing CSS in JS using Firefox.

Severity: normal → S3
Flags: needinfo?(gl)

While bug 1635701 works, this source map issue is still broken using comment 2 STR (and also for inspecting https://compiledcssinjs.com/). Logan, is this related to the ongoing source-map work?

Flags: needinfo?(loganfsmyth)

There are a few things happening here, but the primary issue is simply that the sourcemap on this page is not very good. The HTML has

    <style>
      .cc-1b1wq3m {
        font-size: 20px;
      }

      /*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm1vZHVsZS50c3giXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBR1EiLCJmaWxlIjoibW9kdWxlLnRzeCIsInNvdXJjZXNDb250ZW50IjpbIlxuICAgICAgICBpbXBvcnQgeyBzdHlsZWQgfSBmcm9tICdAY29tcGlsZWQvY3NzLWluLWpzJztcblxuICAgICAgICBzdHlsZWQuZGl2KHsgZm9udFNpemU6IDIwIH0pO1xuICAgICAgIl19 */
    </style>

To annotate that a bit:

    <style>               // line 1
      .cc-1b1wq3m {       // line 2
        font-size: 20px;  // line 3
      }

and in the case of the sourcemap, line 2 is what we're trying to open in the style inspector, but if you look at the data in the sourcemap itself, that line does not actually have any mappings, only line 1 does.

So in this case, https://github.com/atlassian-labs/compiled-css-in-js/pull/153/files#diff-e35f2a5bd4832627e706aff1725bb86dR33 should be adding a mapping for each line in the generated stylesheet.

The sourcemap spec is vague in details around this, which is why it works in Chrome, but I'd consider the current behavior pretty reasonable in Firefox's side.

@Michael Is that a change you'd be up for making to the library?

Flags: needinfo?(laheen)

No worries! I'll make the changes and report back with the outcome

Thanks for having a look Logan

Flags: needinfo?(laheen)

I guess now that I think about it, the main cause is probably that you're inserting newlines to pretty-print the content of the <style>, but the sourcemap doesn't take that into account. So my main comment would be that sourcemaps are very specific to the text content of the <style> node, so keep that in mind when generating them. Adding a single mapping for every line of the eventual <style> text content seems ideal though.

Flags: needinfo?(loganfsmyth)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: