-
-
Notifications
You must be signed in to change notification settings - Fork 58
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
refactor: Update error message for clarity on defined locales #252
refactor: Update error message for clarity on defined locales #252
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -3,30 +3,30 @@ import type { Context, ReactNode } from 'react'; | |||
import React, { Suspense, use, useMemo } from 'react'; | |||
import { flattenLocale } from '../../common/flatten-locale'; | |||
import type { LocaleContext } from '../../types'; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you revert the deletion of empty lines? It makes it harder to read the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry, it seems the formatter ran automatically. I'll fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed by 860e13c
clientLocale = use(locales[locale as keyof typeof locales]()).default; | ||
const newLocale = locales[locale as keyof typeof locales]; | ||
if (!newLocale) { | ||
throw new Error( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about throwing directly an error - we could log it and try to fallback to another locale instead of crashing the page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. I wasn't too concerned originally since a runtime error was occurring.
That's nice idea to use fallback locale. However, if the fallback locale isn't provided since it's optional, which locale should we default to ?
For now, I've implemented it to call notFound like useCurrentLocale. What do you think? 6435a19
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks!
Overview
Implemented a dedicated error message on the client side when an undefined locale is passed, using Next.js and App router.
Like this:
close #251