-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Dates within DatePicker validationErrors
are not correctly localised on server when using a different language
#6227
Comments
validationErrors
are not correctly localised on server when using a different languagevalidationErrors
are not correctly localised on server when using a different language
Those error messages are the browser's built-in validation messages, so they rely on the browser's set language, not the provider's locale. There isn't currently a browser API for customizing this behavior. You can pass in custom error messages as an alternative instead: https://react-spectrum.adobe.com/react-spectrum/forms.html#customizing-error-messages |
Oh that's a shame. Is there a straightforward way to extract the date value from from the error? Or would regex be my only bet? Or should the date have the correct locale format already? The main problem is the date not using the correct locale (and therefore causing client/server mismatch errors), so if I could easily extract this and format it correctly, then it wouldn't be a big of a concern. Right now the server/client mismatch is our block. EDIT: I suppose I could use the |
Perhaps we do a isSSR check and turn off validation if true, we will need to figure out how though since the util for checking isSSR is from react aria and the validation happens in the stately hooks which shouldn't import from those packages since it is a circular dep. |
Provide a general summary of the issue here
When using
validationErrors
fromuseDatePicker
in@react-aria/datepicker
, the date is not correctly localised, causing a hydration error / mismatch in text values.🤔 Expected Behavior?
Dates in error strings are correctly localised, just like the DateField dates.
😯 Current Behavior
When using
validationErrors
fromuseDatePicker
in@react-aria/datepicker
, the date is not correctly localised, causing a hydration error / mismatch in text values.The date for the
DateField
is correct and does not face this issue.This issue is only present when your browser has a different preferred language (anything not "English" or "English US") - one that has a different date format to the default.
An example of this can be seen below, where the preferred language is "English (United Kingdom)" in Chrome. The DateField value is correctly localised on the server and client, but the date in the error message is formatted correctly on the client but not on the server.
💁 Possible Solution
No response
🔦 Context
No response
🖥️ Steps to Reproduce
CodeSandbox
Version
@react-aria/datepicker
": "3.9.3
",@react-aria/i18n
": "^3.10.2
",@internationalized/date
": "^3.5.2
",@react-aria/ssr
": "^3.9.2
",@react-aria/utils
": "^3.23.2
",react-stately
": "^3.30.1
"What browsers are you seeing the problem on?
Chrome
What operating system are you using?
Mac OS
The text was updated successfully, but these errors were encountered: