A descendant combinator after a complex :is() or :not() keeps answers it should not
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- javascript, typescript
- Lĩnh vực
- web-dev
Hướng nghiên cứu
Start by reading compileToken, getQuality, and isCachedDescendant (named cachedDescendant in 7.0.0); the issue does not name source or test files. Run the two supplied reproductions with caching enabled and disabled, then trace why complex :is() or :not() selectors arm this cache. Done means the first example matches o m and the second reflects the updated document.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
isCachedDescendant (cachedDescendant in 7.0.0) keeps one answer per element for as long as the compiled function lives. It is armed by hasExpensiveSubselector, which compileToken sets for any rule getQuality rates 0. That is meant for :has() and :contains(), but :is() or :not() with a combinator inside rates 0 as well, because the combinator's -1 is clamped to 0.
The answer the cache keeps can depend on :scope, which :has() changes from one element to the next:
import { compile } from 'css-select';
import { parseDocument } from 'htmlparser2';
import { findAll } from 'domutils';
const doc = parseDocument(
'<div class="c" id="o"><div class="b c" id="m"><span class="b c" id="t">' +
'<input class="b" disabled></span></div></div>',
);
const elements = findAll((e) => !!e.attribs.id, doc.children);
const ids = (options) =>
elements
.filter(compile(':has(:is(.c .b) :disabled)', options))
.map((e) => e.attribs.id)
.join(' ');
console.log(ids({ xmlMode: false }));
// o m t, where Chrome 152 matches o m: nothing strictly inside #t is a
// `.c .b` with a :disabled in it
console.log(ids({ xmlMode: false, cacheResults: false }));
// o m
The same cache reaches a selector with no :has() or :contains() in it, which is less of a bug, since the README tells you to disable cacheResults if the document changes between queries, but it is easy to miss that :is() is among what it applies to:
import { compile } from 'css-select';
import { parseDocument } from 'htmlparser2';
import { findOne } from 'domutils';
const doc = parseDocument(
'<div id="o"><div class="a"><span class="y" id="t"></span></div></div>',
);
const byId = (id) => findOne((e) => e.attribs.id === id, doc.children, true);
const matches = compile(':is(.x .a) .y', { xmlMode: false });
console.log(matches(byId('t'))); // false
byId('o').attribs.class = 'x';
console.log(matches(byId('t'))); // false, and true with cacheResults: false
What was tried. Turning the cached path off alone fixes both examples, so it is that cache and not the one in cacheParentResults. On a copy of 7.0.0, setting hasExpensiveSubselector only for has, contains and icontains rather than for every rule of quality 0 fixes both too, and leaves the cache for the selectors it was written for.
Run on css-select 7.0.0. master at 2b69f6c has the same logic under the new name, which I checked by reading it, not by running it.
- Ngôn ngữ chính
- TypeScript
- Star
- 636
- Fork
- 85
- Merge trung bình
- 1 phút
- Pull request đã merge (30 ngày)
- 13
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của fb55/css-select
-
:nth-* selectors incorrectly reject detached elements when the formula matches every indexCó thể đã có người làm @bardrop đã nhận 3 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
fb55/css-select#1945 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
fb55/css-select#1931 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
:is(), :where(), :not() and aliases inside :has() are read as relative to the :has() elementCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
fb55/css-select#1930 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
:has(.a .b) matches with the :has() element itself as .aCó thể đã có người làm @manav4u đã nhận 14 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
fb55/css-select#1928 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Nesting selector supportĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
fb55/css-select#1838 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của fb55/css-select
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
fb55/htmlparser2#2579 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug good first issue needs-review
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Add Module DB RulesĐang mởdocumentation public
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 68/100
midnightntwrk/umbradb#65 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
area/channels kind/bug priority/medium
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
nanocoai/nanoclaw#4501 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Docker images: plain X.Y.Z tag (e.g. 7.2.3) is never updated after the initial release buildĐang mởneeds verification
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 13 ngày