Skip to content

Conversation

chromium-wpt-export-bot
Copy link
Collaborator

@chromium-wpt-export-bot chromium-wpt-export-bot commented Jun 17, 2021

A CSSStyleSheet imported as a CSS module script has the constructed
flag set
(https://wicg.github.io/construct-stylesheets/#cssstylesheet-constructed-flag).
This is because it is useful to treat imported CSSStyleSheets the same
way as stylesheets created via new. For example we want to be able
to add both to document.adoptedStyleSheets, and we want both to treat
@import rules the same way.

However, we want DevTools to display them differently. Sheets
created with new don't have a source file to show, but imported
sheets do, so we want the latter to be shown more like "normal"
stylesheets.

To enable DevTools to tell these types of constructed stylesheets apart,
start passing an empty sourceURL to DevTools for constructed stylesheets
created by new. The corresponding frontend change
https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2964580
will check for an empty sourceURL to determine whether to try to link
the stylesheet to a source file or not.

Additionally, a CSSStyleSheet for a module import now stores the
URL of the module request as its base URL. This is later passed to
DevTools as the source URL of the stylesheet. This works because the
base URL and source URL for a CSS module script are always the same.

This also happens to fix a bug with resolution of relative URLs in
CSS modules. The previous behavior was to resolve these using the URL
of the importing document. The new, correct, behavior is to resolve
them using the URL of the stylesheet resource.

Bug: 1219441
Change-Id: I48de349e1f7c8e10a329bff016cef68ac9901bb6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2964539
Reviewed-by: Andrey Kosyakov <[email protected]>
Reviewed-by: Kouhei Ueno <[email protected]>
Reviewed-by: Alex Rudenko <[email protected]>
Reviewed-by: Sigurd Schneider <[email protected]>
Commit-Queue: Dan Clark <[email protected]>
Cr-Commit-Position: refs/heads/master@{#894456}

Copy link
Collaborator

@wpt-pr-bot wpt-pr-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The review process for this patch is being conducted in the Chromium project.

@chromium-wpt-export-bot chromium-wpt-export-bot changed the title Pass CSSStyleSheetHeader.isConstructedNonModule to DevTools Pass the correct sourceURLs to DevTools for constructed stylesheets Jun 17, 2021
@chromium-wpt-export-bot chromium-wpt-export-bot force-pushed the chromium-export-cl-2964539 branch 3 times, most recently from f692102 to a80fc71 Compare June 21, 2021 21:18
A CSSStyleSheet imported as a CSS module script has the constructed
flag set
(https://wicg.github.io/construct-stylesheets/#cssstylesheet-constructed-flag).
This is because it is useful to treat imported CSSStyleSheets the same
way as stylesheets created via `new`. For example we want to be able
to add both to document.adoptedStyleSheets, and we want both to treat
@import rules the same way.

However, we want DevTools to display them differently. Sheets
created with `new` don't have a source file to show, but imported
sheets do, so we want the latter to be shown more like "normal"
stylesheets.

To enable DevTools to tell these types of constructed stylesheets apart,
start passing an empty sourceURL to DevTools for constructed stylesheets
created by `new`. The corresponding frontend change
https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2964580
will check for an empty sourceURL to determine whether to try to link
the stylesheet to a source file or not.

Additionally, a CSSStyleSheet for a module import now stores the
URL of the module request as its base URL. This is later passed to
DevTools as the source URL of the stylesheet. This works because the
base URL and source URL for a CSS module script are always the same.

This also happens to fix a bug with resolution of relative URLs in
CSS modules. The previous behavior was to resolve these using the URL
of the importing document. The new, correct, behavior is to resolve
them using the URL of the stylesheet resource.

Bug: 1219441
Change-Id: I48de349e1f7c8e10a329bff016cef68ac9901bb6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2964539
Reviewed-by: Andrey Kosyakov <[email protected]>
Reviewed-by: Kouhei Ueno <[email protected]>
Reviewed-by: Alex Rudenko <[email protected]>
Reviewed-by: Sigurd Schneider <[email protected]>
Commit-Queue: Dan Clark <[email protected]>
Cr-Commit-Position: refs/heads/master@{#894456}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants