Skip to content

Make captured choice-group state presentation follow the selection instead of baking the initial state - #3046

Open
chubes4 wants to merge 1 commit into
trunkfrom
fix/issue-3044-blocks-engine
Open

chubes4 wants to merge 1 commit into
trunkfrom
fix/issue-3044-blocks-engine

Conversation

@chubes4

@chubes4 chubes4 commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #3044 in CapturedChoiceGroupConverter. Conversion resolved the initial state's .on/.off classes into inline color/background-color on each core/button and left the state classes on the static wrappers, so the runtime's class swap never showed. The converter now resolves each choice's presentation in every captured state (it swaps in a copy of the group with that state's bindings applied, then restores the original and clears selector caches). It emits !important rules for only the properties that differ between states, scoped by a group class and keyed on data-blocks-engine-choice-active (or a new data-blocks-engine-choice-selected-index for patterns that are not just selected/unselected), and drops state-bound class tokens from the static choice block markup. Confirmed in headless Chrome: after clicking Two, Two is rgb(18,42,77) and the wrappers are transparent; before the fix Two stayed white.

What changed

  • [operator-only reference omitted]
  • CapturedChoiceGroupConverter: class tokens that the runtime swaps per state (e.g. on/off) are removed from the className and markup of the static choice blocks
  • CapturedChoiceGroupBlockGenerator view.js: setSelection also sets/removes data-blocks-engine-choice-selected-index on the group
  • HtmlCompilation: passes the style resolver, a rule registrar and a selector-cache invalidator to CapturedChoiceGroupConverter
  • New regression test tests/unit/captured-choice-group-state-presentation.php (issue's .on/.off reproduction through ArtifactCompiler, checks the generated block markup and CSS; 8 of its 12 checks fail without the fix), registered in composer.json

How to test

  1. Run cd php-transformer && composer install --no-interaction --prefer-dist --no-progress && composer test:canonical; expect passes as recorded by Cook's deterministic gate.

Compatibility

Additive. The new converter constructor arguments are optional; groups whose states have no bindings or no differing presentation produce the same output as before. The initial render is unchanged (the source state stays baked) until the runtime marks a selection. All 513 unit tests and the contract tests pass; phpstan is clean.

Evidence

  • Verified command cd php-transformer && composer install --no-interaction --prefer-dist --no-progress && composer test:canonical: status=succeeded; candidate commit 8a84f961068c7c6d92e093f7ff5ab00481de2b3b, tree b8c9f2faae32804a6315eaf0070803c14868d123, fingerprint 46124c864198cc0a844a0904a95d5b8711a779ba2fafdb1b13e0dc6b7b909db3; durable gate gate-1
  • Base unchanged since verification: trunk remains at 354dfdf.
  • CI expected: Homeboy CI after push
  • Candidate adoption provenance: the candidate was promoted from the recorded Cook task execution.
  • Cook deterministic verification: 1 gate(s) completed green.
  • Durable run execution: Succeeded
  • Reviewer-resolvable evidence from source_refs[0]: Captured choice-group state swaps are invisible: initial-state presentation is baked inline on the choices #3044
  • Task objective: Fix Captured choice-group state swaps are invisible: initial-state presentation is baked inline on the choices #3044 at its root cause. A candidate diff exists but it removes the source `style` attribute from choices; the source buttons had no style attribute. The inline `background-color`/border/color on the generated core/button come from conversion resolving the INITIAL state's class styles into block attributes/inline styles, which then override the runtime's per-state class bindings. Discard ineffective parts of the candidate. Make presentation that differs between captured choice states not be baked as static values on the choice blocks (or carry each state's presentation through a state-scoped rule keyed on the runtime's `data-blocks-engine-choice-active`), so the selected look follows selection. Add a regression test from the issue's reduced reproduction (.on/.off buttons) that asserts the generated block markup/CSS lets the active state's background win, failing without the fix.
  • Verified candidate scope: 5 changed file(s): php-transformer/composer.json, php-transformer/src/HtmlToBlocks/Elements/CapturedChoiceGroupConverter.php, php-transformer/src/HtmlToBlocks/Generators/CapturedChoiceGroupBlockGenerator.php, php-transformer/src/HtmlToBlocks/HtmlCompilation.php, php-transformer/tests/unit/captured-choice-group-state-presentation.php.
  • Verified finalization base: trunk at 354dfdf
  • deterministic gate passed: sh -c cd php-transformer && composer install --no-interaction --prefer-dist --no-progress && composer test:canonical (Passed)

AI assistance

  • AI assistance: Yes
  • Tool(s): Homeboy (pi)
  • Model: anthropic-claude-opus-5-5
  • Used for: Imported captured choice groups (tabs, segmented pickers such as forward-fy.com #pathwayTabs) whose selected look comes from swapping classes, so the selected button's look follows the click on the WordPress front end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Captured choice-group state swaps are invisible: initial-state presentation is baked inline on the choices

1 participant