Skip to content

Navigation Link: Compare internal links by host instead of origin#76015

Merged
jeryj merged 4 commits intotrunkfrom
fix/compare-internal-link-by-host
Feb 27, 2026
Merged

Navigation Link: Compare internal links by host instead of origin#76015
jeryj merged 4 commits intotrunkfrom
fix/compare-internal-link-by-host

Conversation

@jeryj
Copy link
Copy Markdown
Contributor

@jeryj jeryj commented Feb 27, 2026

What?

Determine internal vs external by new URL('https://mysite.com').host instead of new URL('https://mysite.com').origin. On trunk, when you use the same URL but change the http:// vs https://, one is considered external.

Why?

When determining whether a navigation link is internal or external, the previous implementation compared URLs by their origin (scheme + host + port). This caused links using http:// to be incorrectly classified as external when the site URL used https://, even if they pointed to the same domain.

How?

This PR fixes the comparison to use host instead of origin, so http://example.com/page and https://example.com/page are both treated as internal links to an https://example.com site.

Additionally, the window.location.origin fallback (used when homeUrl was not provided) has been removed. The homeUrl is now required for internal/external detection; without it, URL parsing fails gracefully and the link is treated as external.

A unit test covering the http/https case is included.

Testing Instructions

  • Use the navigation block to add two manual, identical URLs to your navigation:
  • Both should report "Page" and not "External"
  • Add an external link, like http://test.com
  • Should correctly report external

Testing Instructions for Keyboard

Screenshots or screencast

Before After

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

Labels

Backported to WP Core Pull request that has been successfully merged into WP Core [Block] Navigation Link Affects the Navigation Link Block [Package] Block library /packages/block-library [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants