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

DateField/DateInput off by one w/ optimistic rendering #5578

Closed
tommymcarver opened this issue Nov 23, 2020 · 6 comments · Fixed by #7242
Closed

DateField/DateInput off by one w/ optimistic rendering #5578

tommymcarver opened this issue Nov 23, 2020 · 6 comments · Fixed by #7242
Assignees
Labels

Comments

@tommymcarver
Copy link

tommymcarver commented Nov 23, 2020

What you were expecting:
When PUT/POST (update/create) with DateInput, optimistic rendering renders the date as the same date inputted

What happened instead:
Optimistic Rendering rendered the date off by one (EX: 4/5/2020 -> 4/4/2020) which results in the check to crash and error to pop up

Steps to reproduce:
Use a DateInput and save from an edit/create form a date and look at how optimistic rendering renders the date.

Related code:

export const BlankEdit = props => (
    <Edit {...props}}>
        <SimpleForm warnWhenUnsavedChanges redirect="show">        
		<DateInput source="date" locales="en-US"/>
	</SimpleForm>
    </Edit>
);

Other information:

Environment

  • React-admin version: 3.10.1
  • Last version that did not exhibit the issue (if applicable): N/A
  • React version: 16.13.1
  • Browser: Firefox
  • Stack trace (in case of a JS error): N/A
@fzaninotto
Copy link
Member

I'm sorry, but I don't understand your bug. When I use the DateInput, I see nothing wrong with it.

Can you please add a link to a CodeSandbox, and explain precisely the scenario to reproduce the bug?

@tommymcarver
Copy link
Author

I will mock up a code sandbox but in the mean time let me explain a little bit more.

When updating a date field that exists in my API using the DateInput component, optimistic rendering is rendering the date as one day less than the actual date the user inputs. So, when the optimistic rendering cleanup occurs, the data provider throws an error, as the API and render differ by one in the date field.

If you need more explanation, please let me know. I will work on mocking up a sandbox!

@tommymcarver
Copy link
Author

tommymcarver commented Nov 24, 2020

@fzaninotto here is a sandbox link: https://codesandbox.io/s/autumn-pine-2o2lf

Try going to the comments, changing the date of one of the comments, saving, and then look at what the date now says versus what the date you inputted says. This behavior is the unintended behavior that I am trying to explain.

This sandbox is not altered at all from the base react admin sandbox.

@WiXSL
Copy link
Contributor

WiXSL commented Nov 22, 2021

@tommymcarver, check this issue #5116 and the solution at the #end

@WiXSL
Copy link
Contributor

WiXSL commented Feb 14, 2022

@fzaninotto,

This is reproducible in DateField components if the time zone is negative and the month has two digits. (Picture from PostList of simple project)

Captura de pantalla 2022-02-13 212419

You can see how the tolocalDateString() usage vary in the two time zones (First run is Uruguay, Second is Paris):

Captura de pantalla 2022-02-13 212656

Which is what the DateField uses internally


Possible solutions:

  1. This is fixable in user land by passing the timezone in the options (It could be documented):
<DateField source='...' options={{ timeZone: 'UTC' }} />
  1. Setting a default options with timeZone = 'UTC' to the DateField.

@jamesrwoodruff
Copy link

jamesrwoodruff commented Jul 19, 2022

Is this fixed in later React-Admin versions? I'm using v2.9.4 and ran into this. Adding the timeZone 'UTC' to the options does seem to resolve it for me. If not fixed, it may be worth considering mentioning in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants