Skip to content

Move CSS custom-property resolution onto StyleResolver (#242) - #1339

Merged
chubes4 merged 1 commit into
trunkfrom
refactor-svg-materializer-collaborator
Aug 29, 2026
Merged

Move CSS custom-property resolution onto StyleResolver (#242)#1339
chubes4 merged 1 commit into
trunkfrom
refactor-svg-materializer-collaborator

Conversation

@chubes4

@chubes4 chubes4 commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Part of #242, workstream 1. Prerequisite for the SvgMaterializationTrait extraction.

resolveCssVariablesInValue() expands var(--token) references against source custom properties. It lived in SvgMaterializationTrait.

The threading was the tell

Before this change, resolving a CSS variable took this route:

  1. HtmlTransformer passes a closure into StyleResolutionContext, wrapping a method it inherits from SvgMaterializationTrait.
  2. StyleResolver calls back out through that closure.
  3. The method — defined in the SVG trait — calls $this->styleResolver->structuralPresentationDeclarations().

So a CSS concern was defined in the SVG mixin, threaded through a context, and called back into the very collaborator it needed. Its two dependencies were sourceStyles() and a StyleResolver method: neither has anything to do with SVG.

I found this while measuring SvgMaterializationTrait for extraction. It is worth landing on its own rather than inside that slice, because it changes call sites across four files and is easier to review as one idea.

What changed

resolveCssVariablesInValue() becomes a public method on StyleResolver. Both dependencies resolve locally — sourceStyles() through the resolver's own context, structuralPresentationDeclarations() directly — so the closure leaves StyleResolutionContext entirely.

before after
StyleResolutionContext operations 15 14
SvgMaterializationTrait lines 983 944
SvgMaterializationTrait external deps 20 19

Call sites now reach it directly on the resolver: 16 in HtmlTransformer, 2 in SvgMaterializationTrait, and 3 inside StyleResolver that previously bounced through the context to reach code that called back into StyleResolver.

A check that was wrong, and how it surfaced

After rewiring HtmlTransformer I grepped for stale references with a filter that excluded $this->resolveCssVariablesInValue( — which was exactly the broken pattern. It reported clean.

The first fixture transform then failed immediately:

Call to undefined method HtmlTransformer::resolveCssVariablesInValue()
  in SvgMaterializationTrait.php:485

Two call sites inside the SVG trait itself, plus StyleResolver's three, were still unrouted. Fixed, then re-checked across the whole src tree rather than one file.

Noting it because the pattern keeps recurring in this workstream: a verification step that excludes the failure mode it is meant to detect. Same shape as the vacuous markup hash corrected on #1333.

Verification

serialized_blocks SHA-256 plus block, diagnostic, fallback, asset and coverage fingerprints, captured on trunk at fcca8efa and recaptured here:

383 documents — DIFFERING: 0 — threw: 0
markup: 22,053,531 bytes across 383 distinct hashes

composer test exit 0.


AI assistance disclosure: implemented and drafted by Claude Sonnet 4.6 running in Claude Code, operated by @chubes4. The AI found the misplacement while measuring SvgMaterializationTrait for a separate extraction slice, performed the move, diagnosed the undefined-method failure caused by its own faulty grep filter, and captured the before/after corpus comparison quoted above. Reviewed by a human before opening.

resolveCssVariablesInValue expands var(--token) references against source
custom properties. It lived in SvgMaterializationTrait, which is not
where CSS variable resolution belongs, and it already reached into
StyleResolver for structuralPresentationDeclarations().

The threading was the tell: HtmlTransformer passed it into
StyleResolutionContext as a closure so StyleResolver could call back out
to a method defined in the SVG trait, to reach a method on StyleResolver.

It moves onto StyleResolver as a public method. Its two dependencies
resolve locally -- sourceStyles() through the resolver's own context, and
structuralPresentationDeclarations() directly -- so the closure leaves
StyleResolutionContext entirely, taking that surface from 15 operations
to 14.

Callers now reach it at $this->styleResolver->resolveCssVariablesInValue():
16 sites in HtmlTransformer, 2 in SvgMaterializationTrait, and 3 in
StyleResolver that no longer route through the context.

Prerequisite for extracting SvgMaterializationTrait, which drops from 983
to 944 lines and from 20 external dependencies to 19 as a result.

Behavior preservation: 383 fixture documents with stylesheets attached,
0 differing, 0 throwing, against a fingerprint verified discriminating at
383 distinct hashes over 22 MB of markup. composer test exit 0.
@chubes4
chubes4 merged commit 8fd2673 into trunk Aug 29, 2026
10 checks passed
@chubes4
chubes4 deleted the refactor-svg-materializer-collaborator branch August 29, 2026 02:34
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.

1 participant