A descendant combinator after a complex :is() or :not() keeps answers it should not
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- javascript, typescript
- Área
- web-dev
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 636
- Forks
- 85
- Merge medio
- 1 min
- PR fusionados (30 d)
- 13
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de fb55/css-select
-
:nth-* selectors incorrectly reject detached elements when the formula matches every indexPosiblemente ocupada @bardrop la tomó hace 3 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
fb55/css-select#1945 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
fb55/css-select#1931 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
:is(), :where(), :not() and aliases inside :has() are read as relative to the :has() elementPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
fb55/css-select#1930 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
:has(.a .b) matches with the :has() element itself as .aPosiblemente ocupada @manav4u la tomó hace 14 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 72/100
fb55/css-select#1928 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Nesting selector supportAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 42/100
fb55/css-select#1838 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de fb55/css-select
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
fb55/htmlparser2#2579 ·
Los mantenedores suelen responder en 1 día
-
bug good first issue needs-review
Dificultad 1/5 1-3 horas Aptitud para principiantes 83/100
Los mantenedores suelen responder en 1 día
-
Add Module DB RulesAbiertodocumentation public
Dificultad 1/5 1-3 horas Aptitud para principiantes 68/100
midnightntwrk/umbradb#65 ·
Los mantenedores suelen responder en 2 días
-
area/channels kind/bug priority/medium
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
nanocoai/nanoclaw#4501 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Docker images: plain X.Y.Z tag (e.g. 7.2.3) is never updated after the initial release buildAbiertoneeds verification
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Los mantenedores suelen responder en 13 días