Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix language switcher trailingSlash edge case #2616

Merged
merged 4 commits into from
Nov 19, 2024
Merged

Fix language switcher trailingSlash edge case #2616

merged 4 commits into from
Nov 19, 2024

Conversation

delucis
Copy link
Member

@delucis delucis commented Nov 19, 2024

Description

  • Closes trailingSlash is not respected for the multilingual sites selector #2609
  • Handles an edge case where we were still generating URLs with trailing slashes in the language switcher (and some <head> metadata) even when Astro’s trailingSlash: 'never' was set.
  • In general, we get away without formatting these URLs because we’re just changing the local prefix for Astro.url which is already in the correct format.
  • The edge case is that a URL object can never have a pathname of "". Setting pathname = "" still results in a pathname of "/". This means that when prefixing a root locale homepage, we can’t rely only on pathname to know if a trailing slash should be present or not.
  • Instead I’m importing our context object to retrieve the user’s configured trailingSlash option.
  • Wasn’t 100% sure how best to fix this. In the end I made the trailingSlash config a parameter to our localizedUrl() utility as this makes testing simpler, rather than importing the user config into the utility directly which would mean having to set up two separate test environments. But open to feedback if people think it would be better to avoid the extra parameter.

Copy link

changeset-bot bot commented Nov 19, 2024

🦋 Changeset detected

Latest commit: e8b0e2a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@astrojs/starlight Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the 🌟 core Changes to Starlight’s main package label Nov 19, 2024
Copy link

netlify bot commented Nov 19, 2024

Deploy Preview for astro-starlight ready!

Name Link
🔨 Latest commit e8b0e2a
🔍 Latest deploy log https://app.netlify.com/sites/astro-starlight/deploys/673cc83de1d4550009154917
😎 Deploy Preview https://deploy-preview-2616--astro-starlight.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 100 (no change from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@astrobot-houston
Copy link
Collaborator

astrobot-houston commented Nov 19, 2024

size-limit report 📦

Path Size
/index.html 6.15 KB (0%)
/_astro/*.js 22.41 KB (0%)
/_astro/*.css 13.73 KB (0%)

@delucis delucis changed the title Chris/fix 2609 Fix language switcher trailingSlash edge case Nov 19, 2024
@delucis delucis added the 🌟 patch Change that triggers a patch release label Nov 19, 2024
Copy link
Member

@HiDeoo HiDeoo left a comment

Choose a reason for hiding this comment

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

Tested locally too and the edge case seems to be fixed 🙌

I personally think it's fine to add the extra argument, we don't use that function in many places and it makes it easy to test without duplicating fixtures with multiple configs.

@delucis delucis merged commit 128cc51 into main Nov 19, 2024
15 checks passed
@delucis delucis deleted the chris/fix-2609 branch November 19, 2024 17:43
@astrobot-houston astrobot-houston mentioned this pull request Nov 19, 2024
HiDeoo added a commit to HiDeoo/starlight that referenced this pull request Nov 22, 2024
* main:
  Add issue and discussion templates for documentation improvements (withastro#2619)
  [ci] release (withastro#2618)
  Fix language switcher `trailingSlash` edge case (withastro#2616)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌟 core Changes to Starlight’s main package 🌟 patch Change that triggers a patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

trailingSlash is not respected for the multilingual sites selector
3 participants