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: return correct locale in root 404 and 500 page with i18n #12365

Merged
merged 14 commits into from
Nov 21, 2024

Conversation

apatel369
Copy link
Contributor

@apatel369 apatel369 commented Nov 3, 2024

Changes

This PR fixes the issue where Astro.currentLocale was not correctly returning the locale for custom 404 and 500 pages in projects using i18n.

Closes #12356

Testing

Manually verified in dev server and SSR.

Added Dev and SSR tests custom for vertifying locale in custom 404 pages.

Docs

It is not needed as it is a bug fix

Copy link

changeset-bot bot commented Nov 3, 2024

⚠️ No Changeset found

Latest commit: 8f35066

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Nov 3, 2024
@apatel369 apatel369 changed the title fix: return correct locale in 404 pages with i18n fix: return correct locale in root 404 page with i18n Nov 3, 2024
computedLocale = computeCurrentLocale(url.pathname, locales, defaultLocale);
}
const pathname =
routeData.pathname && routeData.pathname !== '/404' ? routeData.pathname : url.pathname;
Copy link
Member

@ematipico ematipico Nov 12, 2024

Choose a reason for hiding this comment

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

The 404 check isn't strong enough, because it fail for /404/, for example. You should actually use routeData.pattern.test('/404'). Also, while we are at it, we should include 500 too, since users can have a 500.astro

I think you should create a function in routing/match.ts, calling is isRoute404or500(), which accept a RouteData

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I will make those changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added requested changes. PR is ready for re-review.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ematipico PTAL!

Copy link

codspeed-hq bot commented Nov 18, 2024

CodSpeed Performance Report

Merging #12365 will not alter performance

Comparing apatel369:arpan-#12356-locale404 (78427eb) with main (28dd3ce)

Summary

✅ 6 untouched benchmarks

@apatel369 apatel369 changed the title fix: return correct locale in root 404 page with i18n fix: return correct locale in root 404 and 500 page with i18n Nov 18, 2024
@ematipico
Copy link
Member

The test failing seems to be a fluke, and it's not related to your changes. Thank you for the fix!

@ematipico ematipico merged commit a23985b into withastro:main Nov 21, 2024
14 of 15 checks passed
This was referenced Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Astro.currentLocale not working correctly in root 404.astro with i18n
2 participants