Skip to content

Never inject a duplicate stats.js tag when one is already present - #53

Merged
ralyodio merged 1 commit into
masterfrom
fix/no-duplicate-stats-snippet
Jun 12, 2026
Merged

ralyodio merged 1 commit into
masterfrom
fix/no-duplicate-stats-snippet

Conversation

@ralyodio

Copy link
Copy Markdown
Contributor

Summary

Fixes the Audience Hub / tracker installer adding a second stats.js script tag to repos that already have one.

Two gaps caused it:

  1. The "already installed" detection used a single-line tag regex, so a prettier-formatted multi-line <Script … /> (which prettier produces for any tag with 3+ attributes) slipped past it.
  2. The audience installer only inspected the top-ranked candidate file — if the existing snippet lived in a lower-ranked file, it injected a fresh tag into the top one.

Fix

  • New hasTrackerReference(content) in lib/github/install-tracker.ts: any reference to the tracker origin's /stats.js counts as installed, regardless of formatting.
  • Applied in previewInstallAtPath and the install probe (covers the tracker installer UI flow too).
  • installAudienceHub now does two passes: scan all candidate files for an existing reference first; only inject when none has it.

Test plan

  • npm run typecheck clean
  • npm test — 344 passed; new tests cover single-line, multi-line, and absent-tag cases for hasTrackerReference

🤖 Generated with Claude Code

The "already installed" check only matched single-line tracker tags, so a
prettier-formatted multi-line <Script /> slipped past it; the audience
installer also only inspected the top-ranked candidate file, missing
installs living in a lower-ranked one. Add hasTrackerReference (any
reference to the tracker origin's /stats.js counts as installed), apply it
in previewInstallAtPath and the install probe, and make the audience
installer scan all candidate files before injecting.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

vu1nz Security Review

0 finding(s) in PR #?

No security issues found.

@ralyodio
ralyodio merged commit 41ad400 into master Jun 12, 2026
8 checks passed
@ralyodio
ralyodio deleted the fix/no-duplicate-stats-snippet branch June 12, 2026 18:42
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