StyledElement: a subclass takes over the cached style sheets of its parent class and never adds its own

Aperta Adatta ai principianti
#198 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript
Ambito
frontend

Direzione di ricerca

Inizia da StyledElement.connectedCallback() e segui come legge e inizializza elementStyleSheets per le sottoclassi. Aggiungi test per entrambi gli ordini di connessione nella suite di test esistente, verificando che ogni classe riceva i propri stili nello shadow DOM e nel light DOM. Il lavoro è completato quando entrambi gli ordini superano i test e la sottoclasse mantiene i propri fogli di stile.

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

Descrizione

Goal

Every element class gets its own style sheets, whichever class of its hierarchy connected first.

Context

StyledElement.connectedCallback() caches the sheets with if (!this.constructor['elementStyleSheets']) { this.constructor['elementStyleSheets'] = … }. The read goes through the prototype chain of the constructor, so a subclass finds the cache of a parent class that connected earlier and never builds its own. In @webtides/element-library 0.2.0 PasswordField extends InputField: when an el-input-field connects before the first el-password-field on a client-rendered page, appendStyleSheets() writes the input field's CSS into <style id="EL-PASSWORD-FIELD0">, and the password toggle is left without its layout (a large icon on a line of its own below the input). A server-rendered page looks right; it shows after a client-side navigation from a page without fields to one with both. element-js 1.3.0. Hit in loewen-digital/sveltekit-ai-starter-template (issue #22 there); the template defines an own, empty elementStyleSheets on every component class before the class is defined as an element.

Acceptance criteria

  • With class B extends A, each with styles of its own: connect an A first, then a B. B gets its own sheets (shadow DOM: adoptedStyleSheets; light DOM: the appended <style>), not those of A.
  • The order B first, then A, keeps working.
  • A test covers both orders.

Proposal (non-binding)

Check Object.hasOwn(this.constructor, 'elementStyleSheets') instead of the value's truthiness.

Out of scope

Merging the styles of a parent class into its subclass.

Lingua principale
JavaScript
Stelle
30
Fork
5
Merge medio
1h 57m
PR unite (30g)
10

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 webtides/element-js

Tutte le issue di webtides/element-js

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.