Skip to content

fix(core): reject references to ids the icon does not define (TSK-111) - #40

Merged
jmlweb merged 3 commits into
mainfrom
hustle/maintainer/task-2026-11-24
Nov 24, 2026
Merged

jmlweb merged 3 commits into
mainfrom
hustle/maintainer/task-2026-11-24

Conversation

@jmlweb

@jmlweb jmlweb commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Fixes RPT-017 / TSK-111. An icon whose href="#x", url(#x) or SMIL begin/end points to an id the file does not define used to build with exit 0 and render blank. It is now an error, svg/missing-reference (principle 5: fail loudly).

What changed

  • packages/svgworm/src/core/errors.ts: new DiagnosticCode.MISSING_REFERENCE = 'svg/missing-reference'.
  • packages/svgworm/src/core/svg/validate.ts: validateTree adds findMissingReferences. It runs on the raw source tree, before svgo and renameIds. It first collects every id in the document (root included), so forward references such as <use href="#a"> before <defs><path id="a"> stay valid. Then it checks:
    • href / xlink:href="#id"
    • url(#id) in any attribute, including style (CSS-unescaped), and in <style> text
    • SMIL begin / end id.event parts. These use the same "letter after the dot" rule as renameIds, so 0.5s, click and indefinite are never treated as ids.
  • Each message names the element and the missing id, and the diagnostic carries the file. Example: <use> href="#missing" points to id "missing", which the file does not define.
  • tree.test.ts: the existing "accepts internal references" case used href="#a" and url(#g) with no targets. It now defines those ids.
  • Docs: the new row is in apps/site/src/content/docs/troubleshooting.md (kind: error) and in the error tables of both skills. llms.txt lists no codes (it links to troubleshooting), so it is unchanged.
  • Changeset missing-internal-reference.md: svgworm patch. Earlier validation rejections in CHANGELOG.md also shipped as patches.

Acceptance criteria

  1. Failing test first reproduces the dangling <use href="#missing"> and fill="url(#grad)" building with ok: true and no diagnostic. New cases in transform.test.ts and a two-file compile test in compile.test.ts. Before the fix: 6 failed in transform.test.ts, and the compile test failed with expected true to be false (so ok was true). After the fix they pass. The report's repro through the built CLI: before, {"ok":true,"warnings":[]}. Now:
    {"ok":false,"errors":[{"code":"svg/missing-reference","file":"icons/danglingfill.svg",…},{"code":"svg/missing-reference","file":"icons/danglingref.svg",…}]}, with exit code 1.
  2. A diagnostic names the file, the element and the missing id for href/xlink:href, url(#…) in attributes and style, and SMIL begin/end. vitest run src/core/svg/transform.test.ts gives 20 passed. There is one test each for href, xlink:href, fill="url()", a style attribute, a <style> block, and begin + end. Two more tests check that valid forward references and plain clock values still pass.
  3. Fixture set and snapshots unchanged for valid icons; gates pass.
    • pnpm verify: exit 0. 951 passed, and no snapshot file changed.
    • pnpm determinism:fingerprint: output is byte-identical to main (cmp of both runs).
    • pnpm example:check, pnpm example:vite:check, pnpm site:check: exit 0.
    • pnpm render:check: Chromium 57 pass / 0 fail, Firefox 57 pass / 0 fail. WebKit could not launch on this host because system libraries are missing, so the script exited before it rewrote tests/render/matrix.json. The compiled fixture output is byte-identical to main, so CI's matrix diff should be empty.
  4. Code and severity documented; changeset recorded. See the troubleshooting table, the two skill tables, and .changeset/missing-internal-reference.md.

Backlog: TSK-111 is moved to complete with evidence in its progress log. New learning LRN-071.

🤖 Generated with Claude Code

jmlweb and others added 3 commits November 24, 2026 04:11
A dangling href="#…", url(#…) in an attribute, style attribute or
<style>, or SMIL begin/end reference built with exit 0 and rendered a
blank icon. validateTree now reports each one as the error
svg/missing-reference, naming the file, the element and the missing id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rejections

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jmlweb

jmlweb commented Nov 24, 2026

Copy link
Copy Markdown
Owner Author

🤖 hustle review: approve — Dangling href, url(#…) and SMIL begin/end references now fail with svg/missing-reference. Forward references and clock values are handled, tests cover each form, and docs and a patch changeset are present. The only gap is that SMIL ids containing '-' are not checked, which gives a missed error rather than a false rejection.

@jmlweb
jmlweb merged commit 8e80224 into main Nov 24, 2026
23 checks passed
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