Bug 243172 - :has(:lang(~)) doesn't get invalidated
Summary: :has(:lang(~)) doesn't get invalidated
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ryosuke Niwa
URL:
Keywords: InRadar
Depends on:
Blocks: 243093 244075 244484
  Show dependency treegraph
 
Reported: 2022-07-25 12:17 PDT by Ryosuke Niwa
Modified: 2022-10-12 12:03 PDT (History)
4 users (show)

See Also:


Attachments
test case (1.39 KB, text/html)
2022-07-25 12:17 PDT, Ryosuke Niwa
no flags Details
Test case (1.43 KB, text/html)
2022-07-25 22:45 PDT, Ryosuke Niwa
no flags Details
WIP (4.38 KB, patch)
2022-07-25 22:46 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
WIP2 (14.79 KB, patch)
2022-08-14 22:59 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryosuke Niwa 2022-07-25 12:17:20 PDT
Created attachment 461200 [details]
test case

In the attached test case, you should only see green boxes but you see red
because WebKit fails to invalidate elements with :has(:lang(~)) even when lang content attribute is mutated.
Comment 1 Ryosuke Niwa 2022-07-25 12:19:41 PDT
There is a bit of design problem here. :lang(~) relies on Element::computeInheritedLanguage(),
which walks up the tree to find the nearest ancestor with lang content attribute.

:has(~) walks descendants to find an element with a matching :lang(~).

Combining these two naively results in O(n^2) behavior.
Comment 2 Ryosuke Niwa 2022-07-25 22:45:00 PDT
Created attachment 461213 [details]
Test case
Comment 3 Ryosuke Niwa 2022-07-25 22:46:52 PDT
Created attachment 461214 [details]
WIP

We need something like this to invalidate :lang and :dir in a subtree
whenever lang or dir content attributes are mutated.
Comment 4 Ryosuke Niwa 2022-07-25 23:04:52 PDT
The tricky thing is that lang and dir content attributes affect element's descendants. We need to either invalidate more than we need or need to walk over the entire subtree each time the attribute is mutated.
Comment 5 Radar WebKit Bug Importer 2022-08-01 12:18:17 PDT
<rdar://problem/97928899>
Comment 6 Ryosuke Niwa 2022-08-14 22:59:45 PDT
Created attachment 461632 [details]
WIP2
Comment 7 Ryosuke Niwa 2022-08-16 01:40:20 PDT
Pull request: https://github.com/WebKit/WebKit/pull/3353
Comment 8 EWS 2022-08-17 12:19:32 PDT
Committed 253530@main (c01b88a3c523): <https://commits.webkit.org/253530@main>

Reviewed commits have been landed. Closing PR #3353 and removing active labels.
Comment 9 Hercules Hjalmarsson 2022-08-18 11:15:19 PDT
Reverted by https://github.com/WebKit/WebKit/pull/3461
Comment 10 EWS 2022-08-18 11:19:08 PDT
Committed 253566@main (5c847bef1a06): <https://commits.webkit.org/253566@main>

Reviewed commits have been landed. Closing PR #3461 and removing active labels.
Comment 11 Ryosuke Niwa 2022-08-18 22:34:46 PDT
Re-opening for pull request https://github.com/WebKit/WebKit/pull/3472
Comment 12 EWS 2022-08-19 16:55:34 PDT
Committed 253610@main (84698f551725): <https://commits.webkit.org/253610@main>

Reviewed commits have been landed. Closing PR #3472 and removing active labels.
Comment 13 Ryosuke Niwa 2022-08-23 17:27:16 PDT
Re-opening for pull request https://github.com/WebKit/WebKit/pull/3600
Comment 14 EWS 2022-08-24 19:46:29 PDT
Committed 253764@main (0c6665bbc951): <https://commits.webkit.org/253764@main>

Reviewed commits have been landed. Closing PR #3600 and removing active labels.