Fix external links not opening in new tabs after instant navigation#345
Fix external links not opening in new tabs after instant navigation#345bharvey88 wants to merge 1 commit into
Conversation
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
WalkthroughThe link decoration script now uses a named function, ChangesLink Decoration
Estimated code review effort: 3 (Moderate) | ~15 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches✨ Simplify 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. Comment |
newtab.jsruns once at initial page load. Withnavigation.instantenabled, Material swaps page content without a full reload, so external links only gettarget="_blank"andrel="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.addreplaces the string concatenation so classes aren't duplicated when the landing page is decorated again.Summary by CodeRabbit