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

[Bug] To many re-renders when DateTime uses "Eurpo/Moscow" timezone #33

Closed
beta3-z opened this issue Jan 16, 2024 · 2 comments
Closed

Comments

@beta3-z
Copy link

beta3-z commented Jan 16, 2024

How to reproduce

(I put a video and a simple CRA project below)

  1. Create a DateTime object with Europe/Moscow timezon
const timestamp = new Date('Sun Dec 18 2022 21:14:40 GMT+0300').getTime();
const defaultValue = dateTimeParse(timestamp, { timeZone: 'Europe/Moscow' }))
  1. Pass the date to a DatePicker value prop
const [value, setValue] = useState<DateTime | null | undefined>(defaultValue)

return <DatePicker value={value} ... />
  1. Try to change a year in a TextInput

Expected

Year is changed and React doesn't throw a error

Actual result

The "Too many re-renders. React limits the number of renders to prevent an infinite loop" error thrown

Reproduced in Browsers

Yandex.Browser, Safari, Firefox

Attachments

Video

Screen.Recording.2024-01-13.at.21.55.52.mov

Example project:

test-gravity-ui.zip

Full Code Example

import React, {useState} from 'react';
import './App.css';

import { ThemeProvider } from '@gravity-ui/uikit';
import {DatePicker} from '@gravity-ui/date-components';
import {DateTime, dateTimeParse} from '@gravity-ui/date-utils';

function App() {
    const timestamp = new Date('Sun Dec 18 2022 21:14:40 GMT+0300').getTime();
    const defaultValue = dateTimeParse(timestamp, { timeZone: 'Europe/Moscow' })
    const [value, setValue] = useState<DateTime | null | undefined>(defaultValue)

  return (<ThemeProvider theme="light">
        <DatePicker value={value}
                    onUpdate={setValue}
                    format="DD.MM.YYYY HH:mm" />
      </ThemeProvider>
  );
}

export default App;
@ValeraS
Copy link
Contributor

ValeraS commented Jan 17, 2024

Thanks for the details on the issue, PR #25 fixes it. We plan to release a major version with new date-utils at the end of January after releasing @gravity-ui/uikit v6.

@ValeraS
Copy link
Contributor

ValeraS commented Feb 26, 2024

fixed in #54

@ValeraS ValeraS closed this as completed Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants