Skip to content

fix: consolidate conditional class reactivity on attribute derives - #122

Merged
pinetops merged 2 commits into
mainfrom
feat/mixed-class-toggle
Aug 21, 2026
Merged

pinetops merged 2 commits into
mainfrom
feat/mixed-class-toggle

Conversation

@pinetops

@pinetops pinetops commented Aug 21, 2026 •

Copy link
Copy Markdown
Member

Closes #110. Closes #111. Closes #118.

Reworked after design review

Originally this PR generalized the class-toggle parser (list/concat/unless forms). Review question — "are we overfitting to the boolean condition?" — surfaced something better and something worse:

  1. Pattern 7 (reactive attribute derives) already generalizes: the analyzer transpiles any class={…} expression into a derive that recomputes the attribute client-side. Arbitrary conditions included — no boolean restriction needed anywhere.
  2. Both mechanisms were live on the same elements, and pattern 7 had a masked bug: list-form class expressions (the canonical Phoenix idiom) transpile to JS arrays, and el.className = array comma-joins — breaking every class on the element at the first optimistic update. The special case was hiding the general case's bug — same lesson as the audit.

The consolidation

  • data-lavash-attr-class is now array-aware: Phoenix class-list semantics (flatten, drop non-strings, space-join). Pinned by a browser e2e whose compound selectors (.static-class.on-class) fail under comma-joining.
  • Pattern 5 injection retired (parser deleted): conditional class expressions of any shape ride attribute derives — one general mechanism. Untranspilable expressions demote loudly, as before.
  • data-lavash-toggle stays as manual API (JS unchanged) for places the pipeline can't reach: component calls (<.form>), non-lavash templates.
  • Pattern 6 (member) deliberately kept: chip rows live in :for loops where attr derives are correctly skipped.

Demo

Manual toggle sites now express conditionals in the class attr itself — fixing their dead renders (the checkout card highlight used to server-render the unselected border regardless of payment method). All 9 manual data-lavash-visible attrs deleted (one was inverted, saved only by JS pass ordering). <.form> keeps a commented manual toggle (component-call gap, #123).

Full hook chain green: 915 root tests (incl. new e2e), 83 demo tests.

🤖 Generated with Claude Code

Asking whether the class-toggle injection was overfitted to boolean
conditions surfaced something worse: pattern 5 (toggle injection)
and pattern 7 (reactive attribute derives) were BOTH claiming the
same class expressions, and for list-form classes — the canonical
Phoenix idiom — the derive's client value is a JS array that
el.className coerced to a comma-joined string, breaking every class
on the element after the first optimistic update.

Consolidation:

- data-lavash-attr-class now normalizes arrays with Phoenix
  class-list semantics (flatten, drop non-strings, space-join) —
  the load-bearing fix, pinned by a browser e2e whose compound
  selectors fail under comma-joining
- pattern 5 injection is retired: conditional class expressions of
  any shape (pure if, list, concat, comparisons — no boolean
  restriction) ride attribute derives, one general mechanism
- data-lavash-toggle remains supported as a hand-written annotation
  for places the pipeline can't reach (component calls like <.form>,
  non-lavash templates); its JS is unchanged
- pattern 6 (member) stays: chip rows live inside :for loops where
  attr derives are correctly skipped

Demo: manual toggle sites now express conditionals in the class
attr itself (fixing their dead renders — the checkout card
highlight used to server-render the unselected border regardless of
state), all 9 manual data-lavash-visible attrs are gone (one was
inverted and saved only by JS pass ordering), and the payment-form
condition uses the @is_card_payment boolean.

Closes #110. Closes #111.
@pinetops pinetops changed the title feat: class-toggle injection for mixed static + conditional forms fix: consolidate conditional class reactivity on attribute derives Aug 21, 2026
@pinetops
pinetops force-pushed the feat/mixed-class-toggle branch from 02f7afe to fb0d1a5 Compare August 21, 2026 18:10
…118)

The layer-4 annotation section now documents the post-consolidation
reality: the auto-injected set (including attribute derives as THE
general mechanism, and select/textarea binds), the HTML-tags-only
injection boundary, and each hand-written escape hatch with its
reason for existing:

- display: async render blocks + non-lavash templates only — for
  sync fields there is no gap (transpilable non-bare expressions
  become subtree derives; untranspilable ones are compile errors
  under optimistic strictness, verified while writing this)
- toggle: component calls + non-lavash templates
- action: Enter-commit inputs (mints append ids)
- id: row identity / provisional marking
- valid: custom validity calc override
- manual: full opt-out

Also records the form-field footgun: a hand-written bind SUPPRESSES
the rest of the shorthand injection.
@pinetops
pinetops merged commit 54745fe into main Aug 21, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant