CSS variable stripped from calls to jQuery .css()

Aperta
#2,411 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Una pull request collegata è già stata integrata.

  • #180 di @Krinkle — integrata

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
javascript, jquery
Ambito
frontend

Direzione di ricerca

Start with jQuery Core's .css() path and the vendored jQuery Color plugin's color cssHooks, then reproduce the provided CSS-variable test case with jQuery UI loaded. Done means setting and reading var(--color-base, #202122) preserves the CSS variable expression and does not replace it with an rgb() fallback.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Comp: Effects

I found an odd behavior in the jQuery Core .css() function when passing values that contain CSS variables, with a color value as fallback. This bug only happens when jQuery UI is also loaded on the page, and seems to be caused by the jQuery Color plugin (as vendored by jQuery UI) and its cssHooks for converting colors to rgb() notation.

Test case

$('<div>').css('color', 'var(--color-base, #202122)').css('color');

Expected
If you run this e.g. on https://jquery.com where jQuery UI is not loaded, it returns var(--color-base, #202122).

Actual
If you run it on https://jqueryui.com/resources/demos/draggable/default.html where jQuery UI is present, it returns rgb(32, 33, 34).

This is not limited to the return value, the style attribute itself is altered so this happens during the setting, not the getting.

The impact is that when you later attach the element to the document, where the CSS variable exists in a stylesheet, its value will not be used, and instead the fallback is always used.

This was found downstream at Wikipedia (https://phabricator.wikimedia.org/T391461), where we found theme variables (especially dark mode) causing some challenging color combinations. The issue only happened on the subset of forms where jQuery UI is loaded by something elsewhere on the page.

Lingua principale
JavaScript
Stelle
11.3k
Fork
5.2k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di jquery/jquery-ui

Tutte le issue di jquery/jquery-ui

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.