Move CSS custom-property resolution onto StyleResolver (#242) - #1339
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #242, workstream 1. Prerequisite for the
SvgMaterializationTraitextraction.resolveCssVariablesInValue()expandsvar(--token)references against source custom properties. It lived inSvgMaterializationTrait.The threading was the tell
Before this change, resolving a CSS variable took this route:
HtmlTransformerpasses a closure intoStyleResolutionContext, wrapping a method it inherits fromSvgMaterializationTrait.StyleResolvercalls back out through that closure.$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 aStyleResolvermethod: neither has anything to do with SVG.I found this while measuring
SvgMaterializationTraitfor 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 onStyleResolver. Both dependencies resolve locally —sourceStyles()through the resolver's own context,structuralPresentationDeclarations()directly — so the closure leavesStyleResolutionContextentirely.StyleResolutionContextoperationsSvgMaterializationTraitlinesSvgMaterializationTraitexternal depsCall sites now reach it directly on the resolver: 16 in
HtmlTransformer, 2 inSvgMaterializationTrait, and 3 insideStyleResolverthat previously bounced through the context to reach code that called back intoStyleResolver.A check that was wrong, and how it surfaced
After rewiring
HtmlTransformerI 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:
Two call sites inside the SVG trait itself, plus
StyleResolver's three, were still unrouted. Fixed, then re-checked across the wholesrctree 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_blocksSHA-256 plus block, diagnostic, fallback, asset and coverage fingerprints, captured ontrunkatfcca8efaand recaptured here:composer testexit 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
SvgMaterializationTraitfor 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.