fix(templates): interpolate tokens inside htmlAttributes - #353
Open
mostafasadeghidev wants to merge 1 commit into
Open
fix(templates): interpolate tokens inside htmlAttributes#353mostafasadeghidev wants to merge 1 commit into
mostafasadeghidev wants to merge 1 commit into
Conversation
`resolveDynamicProps` interpolated every string-typed prop, then skipped
anything that was not a string — including `htmlAttributes`, the one prop
that holds strings a level down. Tokens written on an author-set attribute
were never substituted: they shipped to the browser as literal text, so
the attribute pointed nowhere.
The asymmetry was invisible until you needed it. `href` on a link is a
first-class string prop and interpolated fine, so authors reasonably
expected `src` written on a custom tag to behave the same way. It did not:
<video>
<source src="{currentEntry.video-link}"> <-- shipped verbatim
</video>
That is the shape a per-item hover video takes on an imported site, and
the failure is silent — valid HTML, an attribute that resolves to nothing,
no error anywhere.
`htmlAttributes` is now walked as the string map it is. Attribute values
are deliberately NOT run through the richtext shim: an attribute is a
value, not a body, and wrapping a URL in `<p>` would corrupt it. Nothing
else is descended into — `filters` on a loop holds configuration, not
authored output.
The no-token path still returns the caller's object untouched, so pages
that use no tokens allocate nothing extra.
All three render surfaces resolve through this function, so the publisher,
the editor canvas, and ReadOnlyNodeTree stay identical.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
What
resolveDynamicPropsnow interpolates tokens insidehtmlAttributes, not just in string-typed props.Why
The resolver's second pass reads:
htmlAttributesis aRecord<string, string>— the one prop that holds authored strings a level down — so every token written on an attribute was skipped and shipped to the browser verbatim.The asymmetry is invisible until you need it.
hrefon a link is a first-class string prop and interpolates fine, so an author reasonably expectssrcwritten on a custom tag to behave the same way. It doesn't:That is the shape a per-item hover video takes on a site imported from another builder, where the
<source>is a custom tag inside a loop and itssrcis bound per row. The failure is completely silent: valid HTML, an attribute that resolves to nothing, no warning anywhere. It took reading the published bytes to find it.How
The loop now handles
htmlAttributesas the string map it is, and leaves everything else exactly as before.Two deliberate limits:
htmlmust not be wrapped in<p>— an attribute is a value, not a body. There is a test for this.filterson a loop is also an object of strings, but it holds configuration rather than authored output; interpolating it would be surprising. Only the one prop that authors type into gets this.The copy-on-write behaviour is preserved: a props bag with no tokens is returned by identity, so token-free pages allocate nothing extra (also covered by a test).
User impact
Additive. Every token that resolved before resolves to the same value; tokens that previously leaked as literal text now resolve. All three render surfaces — publisher, editor canvas,
ReadOnlyNodeTree— go through this one function, so they stay identical to each other.Verification
Seven new tests in
src/__tests__/templates/bindingSourcesAndTokens.test.ts. Four of them fail onmainand pass with this change — I checked by stashing the source edit and re-running:The other three pin the behaviour that must not change: no needless copy, no mutation of the caller's object, and a malformed bag ignored rather than thrown on.
Also verified end-to-end on a real imported site: the
<source src>inside a CMS loop now publishes the row's actual URL instead of the literal token.Note: the one
EBUSYfailure insrc/__tests__/loops/dataRowsFetch.test.tsis a pre-existing Windows temp-file teardown issue increateTestDb, unrelated to this change.