Open
Bug 1355683
Opened 8 years ago
Updated 2 years ago
Consider removing getDefaultComputedStyle
Categories
(Core :: CSS Parsing and Computation, task, P3)
Core
CSS Parsing and Computation
Tracking
()
NEW
People
(Reporter: xidorn, Unassigned)
References
(Depends on 1 open bug)
Details
(Keywords: dev-doc-needed, site-compat)
Attachments
(1 file)
It was added in bug 800983, and it was added, renamed, and eventually removed from the spec.
It seems that this API is only used by jQuery. jQuery used this for getting original "display" value of a given kind of element. jQuery uses feature detection rather than UA-detection for it since it added the usage, and it has a reasonable fallback path which calls getComputedStyle with a newly inserted element. And jQuery caches the result rather than calling it every time.
I did some investigation on BigQuery with github_repos.sample_contents table, and in that table, only two kinds of things show up, one is jQuery, the other is that shadowDOM adds kind of polyfill for this API unconditionally.
Given this, I think we may want to unship this API rather than implementing it in stylo.
Reporter | ||
Comment 1•8 years ago
|
||
FWIW, this is the query I used on BigQuery:
SELECT
id,
sample_repo_name,
sample_path
FROM
`bigquery-public-data.github_repos.sample_contents`
WHERE
content LIKE '%getDefaultComputedStyle%'
AND NOT REGEXP_CONTAINS(content, r',\s*[a-zA-Z]\s*=\s*[a-zA-Z]\.getDefaultComputedStyle\s*(&&|\?\s*[a-zA-Z]\.getDefaultComputedStyle)')
AND NOT REGEXP_CONTAINS(content, r'\.getDefaultComputedStyle\s*=\s*function\(')
AND NOT REGEXP_CONTAINS(content, r'\.prototype\.getDefaultComputedStyle\s*=\s*function\s*\(')
AND NOT REGEXP_CONTAINS(content, r'display\s*=\s*window\.getDefaultComputedStyle\s*(&&|\?)')
AND NOT REGEXP_CONTAINS(content, r'[a-zA-Z]%3D[a-zA-Z]%2EgetDefaultComputedStyle(%26%26|%3F[a-zA-Z]%2E)')
AND NOT content LIKE '%Remove use of getDefaultComputedStyle%'
AND NOT content LIKE '{"version":%'
LIMIT
1000
Keywords: dev-doc-needed
Updated•8 years ago
|
Keywords: site-compat
Version: 53 Branch → Trunk
Comment 2•8 years ago
|
||
The fallback has different semantics if the document has a type selector setting display for that element...
But it's probably OK to remove this and take the same codepath as other UAs anyway. Epecially since it's been removed from jQuery starting with version 2.2.0 (and 1.12.0), as far as I can tell. It was added in 2.1.0 and 1.11.0 respectively.
Comment 3•8 years ago
|
||
Comment hidden (mozreview-request) |
Comment 5•8 years ago
|
||
mozreview-review |
Comment on attachment 8857857 [details]
Bug 1355683 - Remove Window.getDefaultComputedStyle.
https://reviewboard.mozilla.org/r/129886/#review132614
::: dom/base/nsGlobalWindow.h:1728
(Diff revision 1)
> public:
> // Outer windows only.
> nsDOMWindowList* GetWindowList();
>
> protected:
> - // Helper for getComputedStyle and getDefaultComputedStyle
> + // Helper for getComputedStyle
This should just be called GetComputedStyleOuter, if that's all it's doing.
Attachment #8857857 -
Flags: review?(bzbarsky) → review+
Reporter | ||
Updated•8 years ago
|
Assignee: nobody → xidorn+moz
Comment hidden (mozreview-request) |
Pushed by xquan@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/94b5ea8bed5c
Remove Window.getDefaultComputedStyle. r=bz
Comment 8•8 years ago
|
||
bugherder |
Status: NEW → RESOLVED
Closed: 8 years ago
status-firefox55:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla55
Comment 9•8 years ago
|
||
Posted the site compatibility note: https://www.fxsitecompat.com/en-CA/docs/2017/getdefaultcomputedstyle-has-been-removed/
Updated•8 years ago
|
Should bug 548397 comment 38 make us reconsider the compatibility risk here?
Flags: needinfo?(xidorn+moz)
Flags: needinfo?(bzbarsky)
Reporter | ||
Comment 11•8 years ago
|
||
I don't quite understand the risk there.
So this is the code in jQuery 1.11: https://github.com/jquery/jquery/blob/1.11.0/src/css/defaultDisplay.js
It seems that it first tries to getDefaultComputedStyle, or it calls into jQuery.css, and if they both returns null, it tries create an invisible (via width=0 height=0) iframe and get info from that.
If the window is inside a display:none iframe, both getComputedStyle and getDefaultComputedStyle returns null, so there shouldn't be anything different. And the iframe it creates isn't display:none, so how can removing getDefaultComputedStyle itself cause problem?
Flags: needinfo?(xidorn+moz)
Comment 12•8 years ago
|
||
I've updated the webcompat issue with a reduced test-case to show the problem. Basically the issue is that the getComputedStyles fails on the iframe, because the overall document has this CSS at the time: html { display:none; }
When that CSS isn't applied, things work out just fine. I'm not sure how many sites would run into this combination, since they seem to be doing this to fade in the page content with jquery animations.
Comment 13•8 years ago
|
||
(In reply to Xidorn Quan [:xidorn] UTC+10 from comment #11)
> I don't quite understand the risk there.
>
> So this is the code in jQuery 1.11:
> https://github.com/jquery/jquery/blob/1.11.0/src/css/defaultDisplay.js
>
> It seems that it first tries to getDefaultComputedStyle, or it calls into
> jQuery.css, and if they both returns null, it tries create an invisible (via
> width=0 height=0) iframe and get info from that.
>
> If the window is inside a display:none iframe, both getComputedStyle and
> getDefaultComputedStyle returns null, so there shouldn't be anything
> different. And the iframe it creates isn't display:none, so how can removing
> getDefaultComputedStyle itself cause problem?
The key part (AIUI) is that getDefaultComputedStyle doesn't get called on the iframe, but on the parent window, which presumably does have a presshell.
Flags: needinfo?(xidorn+moz)
Reporter | ||
Comment 14•8 years ago
|
||
OK I understand the problem now...
That only happens if the <html> has display:none or there is a rule in the page says "iframe { display: none }" or something like that. It is not clear how widely it could be, but it certainly reveals some compat risk that we didn't think about.
I guess there are three options:
1. assuming this is rare and do nothing
2. prioritize bug 548397 given it's orthogonal to stylo and itself has caused lots of compat issues
3. back out this and try implementing getDefaultComputedStyle in Stylo
The last one probably has the lowest risk. I guess implementing getDefaultComputedStyle for Stylo may not be terribly hard, although I'm not sure.
The second one would be the best for long term, since I don't think we want to keep getDefaultComputedStyle anyway in long term given the lack of users, spec, and interests from other browsers.
hmmm...
Comment 15•8 years ago
|
||
My two cents are that if we deem that fixing bug 548397 is beyond our means anytime soon, then I would strongly consider standardizing getDefaultComputedStyle instead. After all, if libraries like jQuery are using obscure, unreliable iframe hacks simply to show/hide elements, then it might be best to make a well-specced option instead.
Comment 16•8 years ago
|
||
In terms of timeframes, fixing bug 548397 is not something that will happen in the next 1-2 months, is my guess.
If there's an actual site where we're hitting compat problems, we should just restore getDefaultComputedStyle for now. I guess we removed it because it's hard to implement with servo?
Flags: needinfo?(bzbarsky)
Reporter | ||
Comment 17•8 years ago
|
||
(In reply to twisniewski from comment #15)
> My two cents are that if we deem that fixing bug 548397 is beyond our means
> anytime soon, then I would strongly consider standardizing
> getDefaultComputedStyle instead. After all, if libraries like jQuery are
> using obscure, unreliable iframe hacks simply to show/hide elements, then it
> might be best to make a well-specced option instead.
I think CSSWG wants to address this use case by adding a new property to CSS Display which can suppress box generation but doesn't affect the display value. And if getDefaultComputedStyle only has this scene, it really isn't worth standardizing.
(In reply to Boris Zbarsky [:bz] (still a bit busy) (if a patch has no decent message, automatic r-) from comment #16)
> In terms of timeframes, fixing bug 548397 is not something that will happen
> in the next 1-2 months, is my guess.
>
> If there's an actual site where we're hitting compat problems, we should
> just restore getDefaultComputedStyle for now. I guess we removed it because
> it's hard to implement with servo?
It was not because it's hard to implement, but because I thought it is easier to remove it than doing the other way. But I guess I was wrong.
Flags: needinfo?(xidorn+moz)
Reporter | ||
Comment 18•8 years ago
|
||
OK, I'll handle backing it out and open another bug against stylo to track implementing it.
Reporter | ||
Comment 19•8 years ago
|
||
Reporter | ||
Comment 20•8 years ago
|
||
No longer blocks: stylo-style-mochitest
Status: RESOLVED → REOPENED
Depends on: 548397
Resolution: FIXED → ---
Reporter | ||
Updated•8 years ago
|
Assignee: xidorn+moz → nobody
Reporter | ||
Comment 21•8 years ago
|
||
Also opened bug 1366157 for stylo to implement this.
We probably want to remove it eventually, but not now.
Comment 22•8 years ago
|
||
Merge of backout:
https://hg.mozilla.org/mozilla-central/rev/d48f5e67773d
Assignee: nobody → xidorn+moz
Status: REOPENED → NEW
status-firefox55:
fixed → ---
Target Milestone: mozilla55 → ---
Updated•8 years ago
|
Assignee: xidorn+moz → nobody
Updated•7 years ago
|
Priority: -- → P3
Reporter | ||
Comment 23•7 years ago
|
||
Untrack from stylo. This has been implemented for Stylo.
Whiteboard: [stylo]
Updated•5 years ago
|
Type: enhancement → task
Updated•3 years ago
|
Webcompat Priority: --- → ?
Updated•3 years ago
|
Webcompat Priority: ? → ---
Comment 24•3 years ago
|
||
Maybe this should be closed as WONTFIX if there is dependency.
Or add it to the compat spec.
Maybe, we should add telemetry.
Updated•2 years ago
|
Severity: normal → S3
You need to log in
before you can comment on or make changes to this bug.
Description
•