Skip to content

docs: redirects drop the #fragment of the requested URL #78587

Done

Description

@angelica-moreira

Suggested label: bug

Problem

Astro's static redirects are meta-refresh pages, which do not carry the URL fragment across. Bookmarks to a section of a moved page land at the top of the new page instead of at the section.

How to reproduce

Open /gh-aw/workshop/#x. It redirects to /gh-aw/guides/workshop/ and the #x is gone.

Plan

  1. Add a small Astro integration that runs after the build. For each redirect page whose meta refresh matches the configured redirect target, insert a short script before the meta refresh. The script moves the incoming location.hash onto the target.
  2. If the redirect target already has its own fragment (for example /reference/connectors/#servicenow), keep the target's fragment.
  3. Document the behaviour, and its limits, in docs/README.md. Without JavaScript the fragment is still lost, because the plain meta refresh is the fallback.

Done when

  • Browser tests on the built site pass:
    • /gh-aw/workshop/#x ends at /gh-aw/guides/workshop/#x;
    • /gh-aw/reference/servicenow-connector/#other ends at /gh-aw/reference/connectors/#servicenow.
  • Unit tests for the HTML rewrite pass.

Reference fix

Commit: angelica-moreira@eb87e83

It includes:

  • docs/src/lib/redirect-fragments.js and its unit tests;
  • the hook in docs/astro.config.mjs;
  • the browser tests in section-sidebar.spec.ts;
  • the README section.

A working version of this fix is on my fork, in branch angelica/docs-playwright-fixes (all changes vs main). With all 10 commits applied, the full docs Playwright suite passes (239/239). Feel free to reuse the commit linked above, or to implement the plan differently.

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions