Skip to content

Outbound links with target="_self" not navigating#88

Merged
adriaandotcom merged 5 commits into
mainfrom
codex/test-claude-pr87-workflow
Jun 25, 2026
Merged

Outbound links with target="_self" not navigating#88
adriaandotcom merged 5 commits into
mainfrom
codex/test-claude-pr87-workflow

Conversation

@adriaandotcom

@adriaandotcom adriaandotcom commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

Closes #89

Bug

With auto-events.js active, tracked links that have target="_self" fired the Simple Analytics event but never navigated, so the link looked dead. Blocking the script made them work again. Found on YourHosting, button "Ik wil zelf alles regelen".

Cause

collectLink rewrites tracked links with an inline onclick and appends return false when the link has no target, or target="_self". That cancels the browser's native navigation, so saAutomatedLink has to navigate itself. Its callback only did that when the link had no target at all:

if (!sent && !element.hasAttribute("target"))
  document.location = element.getAttribute("href");

For target="_self" the navigation was cancelled but never triggered again, so the link did nothing.

Fix

Navigate under the same condition collectLink uses to add return false:

if (
  !sent &&
  (!element.hasAttribute("target") ||
    element.getAttribute("target") === "_self")
)
  document.location = element.getAttribute("href");

Links with no target and _self links now navigate in the same tab after the event, while _blank and _parent keep their native behaviour. Verified against all four target values in a jsdom harness.

Also in this PR

The Prettier 3 action was reformatting source with trailingComma: "all", which adds ES2017 commas the ES5 only UglifyJS build cannot parse, breaking npm run build. Fixed by adding .prettierrc.json with trailingComma: "es5", reformatting the two build source files, and changing the Prettier workflow step to report only, so it no longer writes or commits.

Security implications

No security impact

Testing

With browserstack.

Checklist

  • Linked to an issue
  • Tested
  • Asked for a review

@claude claude Bot added the change: needs review Changes affecting security, data protection, or system stability. label Jun 25, 2026
@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Claude review checkpoint

Reviewed commit 57c99dd0e524e1e95770a099c11d9376fb94d9bd. This is used to keep later automated reviews focused on changes Claude has not checked yet.

@adriaandotcom

Copy link
Copy Markdown
Collaborator Author

@Maimunar when you review, the most important change is in src/auto-events.js.

Comment thread .github/workflows/browserstack.yml
@adriaandotcom adriaandotcom changed the title Fix your hosting auto events Outbound links with target="_self" not navigating Jun 25, 2026
@adriaandotcom adriaandotcom merged commit 100d438 into main Jun 25, 2026
8 checks passed
@adriaandotcom adriaandotcom deleted the codex/test-claude-pr87-workflow branch June 25, 2026 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change: needs review Changes affecting security, data protection, or system stability.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Track: Fix your hosting auto events

2 participants