Skip to content

links/broken-anchors overstates certainty for runtime-created IDs in HTTP-only server-rendered pages #1616

Description

@deniskern

Summary: the existing unconfirmed-shell protection misses server-rendered pages that add a target ID during initialization. Both 0.0.170 and 0.0.171 report a definitely missing target even though a browser resolves it. This request concerns HTTP confidence; no claim is made about cloud rendering.

Reproduction: run the server below and the audit command above. /anchors contains an image and document.querySelector("img").id="groesse", plus href="#groesse". Actual: both groesse and missing are reported broken. Chromium after load: groesse exists, missing does not, static exists. Expected: rendered mode checks initialized DOM; HTTP mode exposes that runtime-dependent targets are unverified, without silently treating every script-bearing page as passed. Controls: the static target passes; genuinely absent target fails when measured after rendering. Current rule documentation already distinguishes unrendered shells. Request: extend or document the confidence boundary for mixed server-rendered/dynamic pages; keep real missing targets actionable. No customer-specific ignore/filter is requested.

Audit command

$BIN is the squirrel binary; $OUT is the output file.

SQUIRREL_NO_UPDATE=1 SQUIRREL_UPDATE_REEXEC=1 "$BIN" audit http://127.0.0.1:18766/ \
  --http --offline --no-publish --refresh --passive --disable-discovery-probes \
  --level full -m 20 \
  --rule-include schema/entity-conflicts,links/broken-anchors,content/duplicate-description \
  -f json -o "$OUT"

Reproduction server

Save as server.mjs, run node server.mjs, then use the versioned audit invocation above. All links stay on loopback. Description text differs between the locale pair, unrelated duplicate pair and other pages so clusters do not contaminate one another.

import http from 'node:http';
const base='http://127.0.0.1:18766';
const desc='Organic cotton shirt in navy blue, breathable and light for summer days with free returns and comfortable everyday wear.';
const page=(path, body, ld=[], alternates=[])=>`<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Fixture ${path}</title><meta name="description" content="${desc}${path.startsWith('/en') ? ' locale pair' : path.startsWith('/control') ? ' unrelated controls' : path}"><link rel="canonical" href="${base}${path}">${alternates.map(([lang,url])=>`<link rel="alternate" hreflang="${lang}" href="${base}${url}">`).join('')}<script type="application/ld+json">${JSON.stringify(ld)}</script></head><body><main><h1>Collection and service fixture</h1><p>${desc.repeat(8)}</p>${body}</main></body></html>`;
const paths=['/en/service','/en-dk/service','/control/a','/control/b','/anchors'];
http.createServer((req,res)=>{
 const path=req.url;
 let body=paths.map(p=>`<a href="${p}">${p}</a>`).join(' '), ld=[], alts=[];
 if(path.startsWith('/en')){
 alts=[['en','/en/service'],['en-DK','/en-dk/service']];
 ld=[{'@context':'https://schema.org','@type':'Service','@id':`${base}/b2b#service`,name:'B2B orders',url:base+path,provider:{'@type':'Organization','@id':base+'/#provider',name:'Fixture provider'}}];
 }
 if(path.startsWith('/control')) ld=[{'@context':'https://schema.org','@type':'Organization','@id':base+'/#conflict',name:'Conflicting phone control',telephone:path.endsWith('/a')?'+49111111':'+49222222'},{'@context':'https://schema.org','@type':'Service','@id':base+'/#stable',name:'Stable control',url:base+'/service'}];
 if(path==='/anchors') body+='<a href="#groesse">Size chart</a>``&lt;img alt="Größentabelle" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"&gt;``<script>document.querySelector("img").id="groesse"</script><a href="#missing">Missing target control</a><a href="#static">Static target control</a><div id="static">Static</div>';
 res.setHeader('content-type','text/html');res.end(page(path,body,ld,alts));
}).listen(18766,'127.0.0.1');

Triage

Confirmed from the rule source. links/broken-anchors (packages/rules/src/links/broken-anchors.ts) only downgrades a missing target to unconfirmed-anchors when the target record is flagged clientShell. A server-rendered page that sets an id from inline JavaScript at init is not flagged, so in HTTP mode the link is reported as definitely broken. Needed: either extend the confidence boundary for mixed server-rendered and dynamic pages, or document it, without passing every script-bearing page.

Acceptance Criteria

  • In HTTP-only mode, an anchor whose target id is set by inline script on a server-rendered page is reported as unconfirmed, not as definitely broken (or the limitation is documented in docs/rules/links/broken-anchors.mdx).
  • A genuinely absent target on the same page is still reported as broken.
  • A static target id still passes.
  • In rendered mode, the initialized DOM is used, so the runtime-created id passes.
  • Rule tests cover the script-set id, missing and static cases.

Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementrulessize: S

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions