Skip to content

Fix external links not opening in new tabs after instant navigation#345

Open
bharvey88 wants to merge 1 commit into
wled:mainfrom
bharvey88:fix/newtab-instant-nav
Open

Fix external links not opening in new tabs after instant navigation#345
bharvey88 wants to merge 1 commit into
wled:mainfrom
bharvey88:fix/newtab-instant-nav

Conversation

@bharvey88

@bharvey88 bharvey88 commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

newtab.js runs once at initial page load. With navigation.instant enabled, Material swaps page content without a full reload, so external links only get target="_blank" and rel="noopener noreferrer" on the first page a visitor lands on. After any in-site navigation, external links open in the same tab.

To reproduce: open any page on kno.wled.ge, click a sidebar link, then click an external link (for example a GitHub link). It replaces the docs tab instead of opening a new one.

This subscribes the link decoration to Material's document$ observable, which emits on every page change including the first. classList.add replaces the string concatenation so classes aren't duplicated when the landing page is decorated again.

Summary by CodeRabbit

  • Enhancements
    • Improved handling and styling of external and local links.
    • External links now open in a new tab with enhanced security protections.
    • Link behavior remains consistent when navigating through dynamically updated documentation pages.

newtab.js ran once at initial page load, but navigation.instant
swaps page content without a reload, so external links stopped
getting target="_blank" (and the externalLink class) after the
first in-site navigation. Subscribe to Material's document$
observable instead, which emits on every page change including the
first. classList replaces the string concatenation so classes are
not duplicated when the landing page's links are re-decorated.
@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b39c5c06-4c7b-4b05-8c96-0eecf1cec4a6

📥 Commits

Reviewing files that changed from the base of the PR and between 1583203 and ab96bb8.

📒 Files selected for processing (1)
  • docs/assets/js/newtab.js

Walkthrough

The link decoration script now uses a named function, classList.add, and secure attributes for cross-host links. It subscribes to window.document$ when available for navigation updates, with a one-time initialization fallback.

Changes

Link Decoration

Layer / File(s) Summary
Link decoration and navigation updates
docs/assets/js/newtab.js
Refactors link processing into decorateLinks(), applies link classes with classList.add, preserves cross-host target and security attributes, and supports repeated decoration through window.document$ or one-time initialization.

Estimated code review effort: 3 (Moderate) | ~15 minutes

Poem

I’m a rabbit hopping through each link,
Adding classes quicker than you’d think.
Outside paths get safe new doors,
Local paths stay close to floors.
New pages bloom; I decorate anew—
With tidy paws and code that’s true!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: external links now open in new tabs after instant navigation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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