Skip to content

fix: Internal links that emit double-slash URLs - #454

Open
code-qtzl wants to merge 2 commits into
storybookjs:mainfrom
code-qtzl:fix/double-slash-urls
Open

fix: Internal links that emit double-slash URLs#454
code-qtzl wants to merge 2 commits into
storybookjs:mainfrom
code-qtzl:fix/double-slash-urls

Conversation

@code-qtzl

Copy link
Copy Markdown

This PR fixes a bug where internal documentation links could resolve to URLs containing duplicate slashes, such as //blog/... or //docs/.... These malformed URLs could break navigation and produce inconsistent links when rendering MDX content.

What changed

  • Normalized root-relative hrefs before they are returned, stripping duplicate slashes while preserving valid paths
  • Kept hash-only links untouched and ensured existing docs routing logic still works
  • Added regression tests covering:
    • root-relative links
    • duplicate slash cleanup
    • versioned docs links
    • hash-fragment handling
  • Also tightened sitemap URL normalization to avoid duplicate slashes in externally fetched sitemap URLs

Issue: #450
When a link started with / or included repeated separators, the resulting URL could contain a double slash and produce invalid or unexpected routes.

@netlify

netlify Bot commented Aug 12, 2026

Copy link
Copy Markdown

👷 Deploy request for storybook-frontpage pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 46f6d6c

@netlify

netlify Bot commented Aug 12, 2026

Copy link
Copy Markdown

👷 Deploy request for storybook-addon-catalog pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 46f6d6c

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 737120ea-fbe1-4b7c-9ef0-7c6f07cd7226

📥 Commits

Reviewing files that changed from the base of the PR and between 2adaf44 and 46f6d6c.

📒 Files selected for processing (3)
  • apps/frontpage/components/docs/mdx/a.tsx
  • apps/frontpage/lib/fetch-external-sitemap.ts
  • apps/frontpage/lib/get-all-trees.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • apps/frontpage/lib/get-all-trees.ts
  • apps/frontpage/components/docs/mdx/a.tsx
  • apps/frontpage/lib/fetch-external-sitemap.ts

Walkthrough

The change normalizes duplicate slashes in documentation links, generated slugs, and external sitemap URLs. It adds root-relative link tests and centralizes sitemap URL formatting.

Changes

URL normalization

Layer / File(s) Summary
Internal link and slug normalization
apps/frontpage/components/docs/mdx/a.tsx, apps/frontpage/components/docs/mdx/a.test.ts, apps/frontpage/lib/get-all-trees.ts
processHref normalizes root-relative links. getSlug removes empty path segments. Tests cover duplicate leading slashes and unchanged root-relative links.
Sitemap URL normalization
apps/frontpage/lib/fetch-external-sitemap.ts
normalizeSitemapUrl centralizes duplicate-slash and trailing-slash handling for fetched sitemap URLs.

Possibly related issues

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

apps/frontpage/components/docs/mdx/a.tsx

Parsing error: File '@repo/typescript-config/base.json' not found.

apps/frontpage/lib/fetch-external-sitemap.ts

Parsing error: File '@repo/typescript-config/base.json' not found.

apps/frontpage/lib/get-all-trees.ts

Parsing error: File '@repo/typescript-config/base.json' not found.


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/frontpage/components/docs/mdx/a.tsx`:
- Around line 28-29: Update the href normalization in the anchor component
around the startsWith('/') branch so only the pathname is collapsed; preserve
query-string and fragment contents unchanged, including repeated slashes in
values such as search parameters or hash sections.

In `@apps/frontpage/lib/fetch-external-sitemap.ts`:
- Around line 10-12: Update the isTrailingSlashSite path check so each special
path matches only exactly or when followed by a `/`, rather than using an
unbounded startsWith match. Preserve classification for `/showcase`, `/blog`,
`/tutorials` and their descendants while excluding similarly prefixed paths such
as `/blogger` and `/showcase-old`.

In `@apps/frontpage/lib/get-all-trees.ts`:
- Around line 31-33: Filter empty segments immediately after splitting the path,
before version-routing logic reads splitSegment[0] and splitSegment[1]. Update
the path-processing flow in get-all-trees so inputs such as
content/docs//10.2/page.mdx correctly identify and remove the latest-version
segment, while preserving the existing final path construction.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ac83f11d-4241-4f84-a5e6-aa020265ca9a

📥 Commits

Reviewing files that changed from the base of the PR and between f4c5ef8 and 2adaf44.

📒 Files selected for processing (4)
  • apps/frontpage/components/docs/mdx/a.test.ts
  • apps/frontpage/components/docs/mdx/a.tsx
  • apps/frontpage/lib/fetch-external-sitemap.ts
  • apps/frontpage/lib/get-all-trees.ts

Comment thread apps/frontpage/components/docs/mdx/a.tsx Outdated
Comment thread apps/frontpage/lib/fetch-external-sitemap.ts
Comment thread apps/frontpage/lib/get-all-trees.ts
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