Skip to content

Drop 404 hreflang alternates on English-only pages - #1987

Merged
David Pine (IEvangelist) merged 1 commit into
mainfrom
aspireagent/fix-english-only-hreflang
Oct 30, 2026
Merged

David Pine (IEvangelist) merged 1 commit into
mainfrom
aspireagent/fix-english-only-hreflang

Conversation

@davidfowl

Copy link
Copy Markdown
Contributor

Summary

Developer Hub, API reference and individual sample pages advertise hreflang alternates for all 15 locales, but those pages exist only in English. The localized URLs return 404, so search engines get alternates that point to error pages.

Live production (main 04ecd1c), checked with curl:

Page (200) Advertised alternate Status
https://aspire.dev/hub/ https://aspire.dev/de/hub/, /zh-cn/hub/ 404
https://aspire.dev/hub/glossary/apphost/ https://aspire.dev/ja/hub/glossary/apphost/ 404
https://aspire.dev/reference/api/csharp/ https://aspire.dev/de/reference/api/csharp/ 404
https://aspire.dev/reference/samples/aspire-shop/ https://aspire.dev/de/reference/samples/aspire-shop/ 404

Docs content pages are fine: /de/get-started/install-cli/ and /de/reference/samples/ return 200, either translated or as a fallback. The sitemap already lists the English-only pages without alternates, so only the page <head> was inconsistent.

Root cause: Starlight's getHead (@astrojs/starlight/utils/head.ts) adds an alternate for every configured locale whenever the site is multilingual. That includes the custom src/pages/** routes rendered through <StarlightPage>, which are never generated per locale. route-data-middleware.ts already documents that API reference pages exist only in the default locale.

Fix:

  • New isDefaultLocaleOnlyPath helper in src/utils/default-locale-only-routes.ts. It matches /hub/**, /reference/api/** (reusing the existing API reference pattern) and /reference/samples/<sample>/.
  • The route-data middleware removes the link[rel=alternate][hreflang] head entries for those routes.
  • Canonical, sitemap and every other head entry are unchanged, and localized docs routes keep all of their alternates.

Third-party links and affiliations

None.

Validation

  • New regression test tests/unit/route-data-middleware-hreflang.vitest.test.ts:
    • Before the fix: 6 of the 11 tests fail, one for each English-only route (expected [ 'en', 'da', 'de', … ] to deeply equal []).
    • After the fix: 11 of 11 pass.
    • It also checks that localized docs routes (/, /get-started/install-cli/, /de/get-started/install-cli/, /reference/samples/) keep all 15 locale alternates plus x-default.
  • Rendered head via astro dev, counting hreflang attributes:
    • /hub/, /hub/glossary/apphost/, /reference/api/csharp/ and /reference/samples/aspire-shop/: 0, down from 16 in production. Canonical is unchanged.
    • /get-started/install-cli/, /de/get-started/install-cli/ and /reference/samples/: still 16.
  • Full unit suite (vitest run): 83 files, 1119 passed and 1 skipped.
  • Lint (astro sync, skill digest check, eslint . --max-warnings 0), Prettier on the changed files, and tsc (no errors in the changed files): all pass.
  • No visual change, so there are no screenshots.

🤖 Posted by AspireAgent (AI Agent)

Starlight emits an hreflang alternate for every configured locale, but the
custom StarlightPage routes under /hub/, /reference/api/ and
/reference/samples/<sample>/ are only generated for the default locale, so
alternates such as /de/hub/ point at 404 pages. Remove the hreflang
alternates for those routes in the route-data middleware.

Co-authored-by: Copilot <[email protected]>
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

Frontend HTML artifact ready

The latest frontend build uploaded the frontend-dist artifact for PR #1987. Use the VS Code button below to open this PR with GitHub Artifacts Explorer and browse the built HTML locally.

VS Code: Open PR #1987 artifacts

This comment updates automatically when a new frontend build artifact is uploaded.

@davidfowl
David Fowler (davidfowl) marked this pull request as ready for review October 30, 2026 06:23
Copilot AI balanced review requested due to automatic review settings October 30, 2026 06:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block the change removing hreflang alternates from English-only pages.

No open issues 🎉

What changed in this PR

This PR removes hreflang alternates that point to nonexistent localized versions of English-only pages on aspire.dev.

Changes:

  • Adds a route helper identifying Developer Hub, API reference, and individual sample pages as English-only.
  • Filters locale alternates from those pages while preserving canonical links and other head entries.
  • Adds regression tests confirming English-only routes lose alternates and localized documentation routes retain them.
File Description
src/​frontend/​tests/​unit/​route-data-middleware-hreflang.vitest.test.ts Tests route matching, alternate removal, and preservation of other links.
src/​frontend/​src/​utils/​default-locale-only-routes.ts Identifies English-only custom routes.
src/​frontend/​src/​route-data-middleware.ts Removes hreflang alternates for matching routes.

Review effort: Balanced

@IEvangelist
David Pine (IEvangelist) merged commit 26a3a76 into main Oct 30, 2026
20 checks passed
@IEvangelist
David Pine (IEvangelist) deleted the aspireagent/fix-english-only-hreflang branch October 30, 2026 13:00
David Pine (IEvangelist) pushed a commit that referenced this pull request Nov 1, 2026
## Summary

On Developer Hub and sample pages, choosing a language in the footer
language picker sends readers to a 404. Those pages are generated only
in English, but the picker adds a locale prefix to the URL anyway:

| Page | Pick "Deutsch" → | Status |
| --- | --- | --- |
| `/hub/` | `/de/hub/` | 404 |
| `/hub/glossary/apphost/` | `/de/hub/glossary/apphost/` | 404 |
| `/reference/samples/aspire-shop/` |
`/de/reference/samples/aspire-shop/` | 404 |
| `/reference/api/csharp/` | `/reference/api/csharp/` | 200 (already
special-cased) |
| `/get-started/install-cli/` | `/de/get-started/install-cli/` | 200
(translated docs, unchanged) |

I reproduced this with Playwright against `astro dev` at `main`
04ecd1c, and production returns the same 404s for those URLs.

**Root cause:** `FooterPreferences.astro` only recognised API reference
pages as English-only, using `isApiReferencePath`. Every other path got
a locale prefix.

**Fix:**
- The picker's path decision moves into `src/utils/language-switch.ts`
(`getLanguageSwitchPath` and `getSelectedLocaleForPath`).
- Every default-locale-only route (`/hub/**`, `/reference/api/**` and
`/reference/samples/<sample>/`) now gets the existing API reference
behaviour: store the preferred locale, stay on the English URL, and show
the stored preference in the picker.
- Translated docs routes behave as before.

`src/utils/default-locale-only-routes.ts` is byte-identical to the file
added in #1987 (same git blob, `dd363d05`). These two PRs merge cleanly
in either order and don't depend on each other.

## Third-party links and affiliations

None.

## Validation

- **New unit test** `tests/unit/language-switch.vitest.test.ts`:
- Before the fix, the existing logic was extracted unchanged into the
new helpers and 7 of the 17 tests failed. All of the failures were on
hub and sample routes. The API reference and docs cases passed, which
shows the extraction itself didn't change behaviour.
  - After the fix: 17 of 17 pass.
- **New browser test** in `tests/e2e/ui-regressions.spec.ts` ("language
selector keeps English-only pages on their English URL"). It picks
Deutsch through the real listbox on `/hub/` and
`/reference/samples/aspire-shop/`.
- Before the fix it failed on desktop-chromium and mobile-chromium with
`Expected: "/hub/" Received: "/de/hub/"`.
  - After the fix it passes on both.
- It ran together with the existing footer and language-selector tests:
9 of 9 passed on `astro dev`.
- **Full unit suite** (`vitest run`): 83 files, 1125 passed and 1
skipped.
- **Lint** (`astro sync`, skill digest check, `eslint . --max-warnings
0`) and **Prettier** on the changed files: both pass.
- **`tsc`:** no new errors. The one `.astro` import resolution error in
`custom-components.vitest.test.ts` is already on `main`.
- This changes navigation, not styling, so there are no screenshots.

**🤖 Posted by AspireAgent (AI Agent)**

Co-authored-by: davidfowl <[email protected]>
Co-authored-by: Copilot <[email protected]>
David Pine (IEvangelist) pushed a commit that referenced this pull request Nov 3, 2026
## Summary

The **Get started** sidebar has a Glossary entry (`link:
'/hub/glossary/'` in `config/sidebar/docs.topics.ts`). Starlight adds
the active locale to sidebar links, so every localized docs page links
to `/de/hub/glossary/`, `/ja/hub/glossary/` and so on. The Hub is
English-only and those pages aren't generated, so the link returns a
404. For example, https://aspire.dev/de/get-started/install-cli/
currently renders `href="/de/hub/glossary/"`, and
`https://aspire.dev/de/hub/glossary/` returns **404**.

`route-data-middleware.ts` already removes the locale from sidebar links
to API reference pages. This PR extends that same sidebar pass: when a
localized sidebar href resolves to a default-locale-only route
(`isDefaultLocaleOnlyPath`, covering `/hub/**`, API reference and
individual samples), the locale prefix is stripped. Links to translated
docs pages keep their locale.

`src/utils/default-locale-only-routes.ts` is byte-identical to the copy
in #1987 and #1988, and the import is identical, so the PRs combine
without conflicts. I trial-merged this branch with #1984, #1987 and
#1988 locally: there were no conflicts and all 1143 unit tests passed on
the combined tree.

There is no visual change; only link targets change.

## Third-party links and affiliations

None.

## Validation

- New regression test
`tests/unit/route-data-middleware-sidebar-locale.vitest.test.ts` (3
tests):
- Before the fix: 1 failed (`/de/hub/glossary/`, `/ja/hub/`,
`/zh-cn/reference/samples/aspire-shop/` stayed localized) and 2 passed
(control cases).
  - After the fix: 3 of 3 pass.
- Full unit suite (`vitest run --config vitest.config.ts`): 83 files,
1111 passed, 1 skipped.
- Lint (`astro sync`, `compute-skill-digests --check`, `eslint .
--max-warnings 0`) passes, and Prettier check passes on the changed
files.
- Rendered on `astro dev`:
- `/de/get-started/install-cli/` and `/ja/fundamentals/telemetry/` now
render only `href="/hub/glossary/"`.
  - `/de/get-started/resources/` remains localized.

**🤖 Posted by AspireAgent (AI Agent)**

---------

Co-authored-by: davidfowl <[email protected]>
Co-authored-by: Copilot <[email protected]>
Sébastien Ros (sebastienros) added a commit that referenced this pull request Nov 11, 2026
- TypeScript API parameter descriptions (#2009)
- No locale prefix or hreflang alternates for English-only pages: the footer
  language picker (#1988), hreflang (#1987) and the sidebar Glossary link (#1989)
- Footer link to the Aspire MIT license
- Homepage: environment fade (#1993), stale AppHost animations (#1950), the
  dashboard carousel keeps the selected slide on activation
- Search: first-result highlight with out-of-order renders (#2007), hover cursor
  flicker (#1977)
- Live status over WebSocket (#1942) and twoslash hover, merged into the copies
  of the frontend scripts
- Icon data 5.40.0 and the regenerated sprite
- src/frontend now uses Bun: README and script usage updated
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.

3 participants