p: only :class and :style from the attribute map reach the DOM, so other attributes and :attr itself are dropped

Aperta
#388 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
clojure
Ambito
frontend

Direzione di ricerca

Read src/re_com/text.cljs around lines 225-234 (the ::p/wrapper :post-props call) and the standard-impl-keys set near line 185, then src/re_com/part.cljs lines 145-148 to see which keys the default renderer copies. Compare with the v2.28.2 code linked in the issue. Before any fix, a maintainer must settle whether bare attributes or only :attr is supported; once that is decided, model a failing test on test/re_com/checkbox_test.cljs rendering [p {:title "x"} "text"] and [p {:attr {:title "x"}} "text"], and expect :title on the wrapper element in both.

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

Descrizione

This is a suggested regression. We found it by reading the code during an audit of the :parts and :theme migration (#352). It was not reported from an app. It needs looking over before anyone decides whether it is a regression or an intended change.

What changed

Before, the attribute map went straight onto the outer span.
See src/re_com/text.cljs lines 177 to 179 at v2.28.2:

[:span.rc-p
 (apply dissoc m standard-impl-keys)
 (into [:span] (concat children hiccup-children))]

Any HTML attribute in the map, such as :on-click or :title, was rendered.

Now the same map, still with standard-impl-keys removed, is passed as :post-props to the ::p/wrapper part.
See src/re_com/text.cljs lines 225 to 234 at 66162a21.
That part uses the default renderer, which only copies :class, :style and :attr (src/re_com/part.cljs lines 145 to 148).
Bare attributes are top-level keys, so they are dropped without a warning.
:attr is in standard-impl-keys (line 185), so it is removed before the part sees it.
Only :class and :style get through.

The change arrived with 7cc04b73 (first released in v2.29.0).

Why we think it's a regression

  • The docstring still says "If the first child is a map, it is interpreted as a map of styles / attributes" (text.cljs line 202).
  • Validation only runs when the map has :theme, :pre-theme, :parts, :debug-as or :src (line 228). A map such as {:on-click f} is never validated.
  • p-args-desc lists :attr as an accepted arg (lines 172 to 183), but the code removes it.

At v2.28.2 :attr was also removed, so {:attr {...}} did not work then either.
Our working assumption is that :attr is meant to be the route now, and that it was never wired up.

Question: should bare attributes still work, or only :attr?

Who it affects

Callers that put HTML attributes in the map:

[rc/p {:on-click f :title "More detail"} "Some text"]

Before, the span had the click handler and the title.
Now it has neither.
[rc/p {:attr {:title "More detail"}} "Some text"] does not work either.

Suggested fix

Take :attr out of the keys removed for :post-props, so the documented arg works.
Then either fold the remaining bare keys into :attr, or validate the map every time.

A failing test should come first, modelled on test/re_com/checkbox_test.cljs: render [p {:title "x"} "text"] and [p {:attr {:title "x"}} "text"], and expect :title on the wrapper element in both.

Next step

Needs a maintainer to decide whether this is a regression, and to agree the fix.

Lingua principale
Clojure
Stelle
825
Fork
144
Merge medio
2h 42m
PR unite (30g)
1

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

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 day8/re-com

Tutte le issue di day8/re-com

Issue simili

Altre issue su Clojure

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.