feat(core): ensureHfIds node-id pass + shared hf- mint helper (R1)#1269
Open
vanceingalls wants to merge 1 commit into
Open
feat(core): ensureHfIds node-id pass + shared hf- mint helper (R1)#1269vanceingalls wants to merge 1 commit into
vanceingalls wants to merge 1 commit into
Conversation
Collaborator
Author
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
ensureHfIds(html: string): stringinpackages/core/src/parsers/hfIds.ts. Single DOM pass (via linkedom) that mints adata-hf-idattribute on every eligible element before the caller sees the markup.Id derivation: FNV-1a 32-bit hash of
tagName | sorted-attrs(\x00/\x01 separated) | ownText, last 4 chars of base-36,hf-prefix. Collision resolution appends a sibling counter and re-hashes. Preserves existing ids (elements withdata-hf-idalready set are skipped). Excludes non-visual tags:script,style,template,meta,link,noscript,base.Fragment handling: detects bare HTML fragments (no
<!doctype/<html) and wraps in a full document shell before parsing, then returnsbody.innerHTML— matching the pattern used byparseSourceDocumentinsourceMutation.Why
Counter-based ids (
element-0,element-1, …) are positional. Inserting a new layer at position 0 shifts every id below it. The R1 milestone requires content-based, stable ids so that targeting operations (split, patch, probe) stay valid across re-parses and element insertions. T2 spec (stableIds.test.ts) defines the contract: same content → same id, adding a sibling doesn't change other ids, format matches/^hf-[a-z0-9]{4}$/.How
toHfId(hash)—slice(-4)ofhash.toString(36)for better distribution across the suffix spacedata-hf-idis excluded from the hash input (prevents circular dependency on the attribute being set)Set; duplicates get a counter suffix before re-hashing/<!doctype|<html[\s>]/i.test(html)— if bare, wrap→parse→body.innerHTMLTest plan
packages/core/src/parsers/stableIds.test.ts— 7 tests pass (3 were.failsstubs targeting R1; 4 were pre-existing baselines that must not regress)