Bug 204687

Summary: CSS Rules with the same selector from several large stylesheets are applied in the wrong order
Product: WebKit Reporter: Anton Khlynovskiy <subzey>
Component: CSSAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, ews-feeder, kling, koivisto, sabouhallawa, simon.fraser, webkit-bug-importer, ysuzuki, zalan
Priority: P2 Keywords: InRadar
Version: Safari 13   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Error reproduction demo and a screenshot
none
Web Inspector Screenshot
none
patch
none
patch none

Anton Khlynovskiy
Reported 2019-11-28 10:20:43 PST
Created attachment 384463 [details] Error reproduction demo and a screenshot In some cases rules with the same selector from the different stylesheets override each other in the wrong order. It is reproduced with the large stylesheets (> 10000 rules, probably less) and is somehow related to the count of css rules in those stylesheets. Most noticeable the error is when the count of rules is near power of two. The reproduction demo is attached to this issue, or can be accessed https://saf-rule-order.subzey.now.sh/dist/0x7fff/ or GitHub: https://github.com/subzey/saf-rule-order/tree/master/dist There are 20 styleheets on a page. Each features a rule that sets the ::before contents on the body element. Other than these rules each sheet contains lots of other rules, so there are 32767 total (0x7FFF). The contents of these "dummy" rules doesn't matter, it can be even empty. *Expected:* Once all the selectors are the same, the rule from the last stylesheet should "win" and the body::before contents should be "Hello from 20.css". *Actual Behavior:* It says, "Hello from 09.css". The Inspector shows the order of rules application (see the attached screenshot) and it's totally random and does not reflect the DOM order of link elements. This order is changed if the count of "dummy" rules is changed. https://saf-rule-order.subzey.now.sh/dist/0x8000/ 32768 rules yields "Hello from 16.css"
Attachments
Error reproduction demo and a screenshot (220.68 KB, application/zip)
2019-11-28 10:20 PST, Anton Khlynovskiy
no flags
Web Inspector Screenshot (212.64 KB, image/jpeg)
2019-11-28 10:55 PST, Anton Khlynovskiy
no flags
patch (5.00 KB, patch)
2020-02-04 02:00 PST, Antti Koivisto
no flags
patch (5.00 KB, patch)
2020-02-04 02:30 PST, Antti Koivisto
no flags
Anton Khlynovskiy
Comment 1 2019-11-28 10:55:14 PST
Created attachment 384468 [details] Web Inspector Screenshot
Radar WebKit Bug Importer
Comment 2 2019-11-28 11:42:03 PST
Simon Fraser (smfr)
Comment 3 2019-12-02 11:46:29 PST
CSS JIT bug?
Antti Koivisto
Comment 4 2020-02-04 01:08:15 PST
RuleData has unsigned m_position : 18; so if you have > 256k rules it will get confused about the order. The test consists of 32k rule sheets and fails as expected on 9th.
Antti Koivisto
Comment 5 2020-02-04 01:11:36 PST
There are some free bits here so we can increment the limit some.
Antti Koivisto
Comment 6 2020-02-04 02:00:48 PST
Antti Koivisto
Comment 7 2020-02-04 02:30:55 PST
Andreas Kling
Comment 8 2020-02-04 04:14:57 PST
Comment on attachment 389646 [details] patch r=me
EWS
Comment 9 2020-02-04 04:21:10 PST
Comment on attachment 389646 [details] patch Rejecting attachment 389646 [details] from review queue. kling@webkit.org does not have reviewer permissions according to https://trac.webkit.org/browser/trunk/Tools/Scripts/webkitpy/common/config/contributors.json. - If you do not have reviewer rights please read http://webkit.org/coding/contributing.html for instructions on how to use bugzilla flags. - If you have reviewer rights please correct the error in Tools/Scripts/webkitpy/common/config/contributors.json by adding yourself to the file (no review needed). The commit-queue restarts itself every 2 hours. After restart the commit-queue will correctly respect your reviewer rights.
Antti Koivisto
Comment 10 2020-02-04 04:33:42 PST
sad face
Andreas Kling
Comment 11 2020-02-04 05:17:06 PST
(In reply to Antti Koivisto from comment #10) > sad face Sorry about that. I didn’t know I had been demoted. Patch looks good fwiw.
zalan
Comment 12 2020-02-04 06:34:55 PST
Comment on attachment 389646 [details] patch trust kling.
Antti Koivisto
Comment 13 2020-02-04 06:46:53 PST
I did but the bot had doubts.
WebKit Commit Bot
Comment 14 2020-02-04 07:30:58 PST
Comment on attachment 389646 [details] patch Clearing flags on attachment: 389646 Committed r255671: <https://trac.webkit.org/changeset/255671>
WebKit Commit Bot
Comment 15 2020-02-04 07:31:00 PST
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.