feat(core): sourceMutation data-hf-id targeting (R1, T7)#1272
Open
vanceingalls wants to merge 2 commits into
Conversation
Elements now get data-hf-id minted by ensureHfIds; parser reads data-hf-id as model id, so HTML id attrs are no longer the model id. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Collaborator
Author
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
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
Adds
hfIdtargeting tosourceMutation(packages/core/src/studio-api/helpers/sourceMutation.ts) and closes a CSS injection gap.New targeting field:
findTargetElementtrieshfIdfirst viafindByHfId, thenid, thenselector.CSS injection guard:
A crafted value like
hf-1234"][data-x="ywould otherwise produce a valid compound selector that silently matches the wrong element.Stable id protection:
data-hf-idis blocked in bothattributeandhtml-attributeop cases — it can never be overwritten by a patch operation.Split clone cleanup:
splitElementInHtmlremovesdata-hf-idfrom the cloned element so the next parse mints a fresh stable id for the new half.probeElementInSourceupdated to accepthfIdas a valid probe target.Why
T7 spec — the server-side mutation API (
files.tsroute) usessourceMutationto apply patches to composition source files. It needs to accepthfIdtargeting for the same reason as sourcePatcher (T3): stable R1 ids must be usable as mutation targets from all surfaces. Depends on PR #1270.The injection fix is a security correctness issue: without it, a user-controlled
hfIdvalue could produce a CSS selector that matches an unintended element.How
escapeCssAttrValue: escapes\before"(order matters — escaping"first would double-escape the backslash)findByHfIdwraps the selector call in try/catch in case the escaped value still somehow produces an invalid selectorsplitElementInHtmlclone:clone.removeAttribute("data-hf-id")before inserting — stable id must be unique; the parser will mint a new one on next round-tripTest plan
sourceMutation.test.ts— hfId targeting, injection guard, attribute protection