Skip to content

Commit

Permalink
Fix bug that introduced a race condition in consumers (#2373)
Browse files Browse the repository at this point in the history
* Fix bug that introduced a race condition in consumers
  • Loading branch information
amrocha authored Nov 18, 2019
1 parent 3aed7b7 commit a0622b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
3 changes: 3 additions & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
- Prevented scrolling to `Popover` content in development ([#2403](https://github.com/Shopify/polaris-react/pull/2403))
- Fixed an issue which caused HSL colors to not display in Edge ([#2418](https://github.com/Shopify/polaris-react/pull/2418))
- Fixed an issue where the dropzone component jumped from an extra-large layout to a layout based on the width of its container ([#2412](https://github.com/Shopify/polaris-react/pull/2412))
- Fixed an issue which caused HSL colors to not display in Edge ((#2418)[https://github.com/Shopify/polaris-react/pull/2418])
- Fixed an issue where the dropzone component jumped from an extra-large layout to a layout based on the width of it's container ([#2412](https://github.com/Shopify/polaris-react/pull/2412))
- Fixed a race condition in DatePicker ([#2373](https://github.com/Shopify/polaris-react/pull/2373))

### Documentation

Expand Down
22 changes: 13 additions & 9 deletions src/components/DatePicker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,18 @@ export function DatePicker({
const i18n = useI18n();
const [hoverDate, setHoverDate] = useState<Date | undefined>(undefined);
const [focusDate, setFocusDate] = useState<Date | undefined>(undefined);
const [newRange, setNewRange] = useState<Range | undefined>(undefined);

useEffect(() => {
setFocusDate(undefined);
}, [selected]);

useEffect(() => {
if (newRange) {
onChange(newRange);
}
}, [newRange, onChange]);

const handleFocus = useCallback((date: Date) => {
setFocusDate(date);
}, []);
Expand All @@ -85,16 +92,13 @@ export function DatePicker({
[onMonthChange],
);

const handleDateSelection = useCallback(
(range: Range) => {
const {end} = range;
const handleDateSelection = useCallback((range: Range) => {
const {end} = range;

setHoverDate(end);
setFocusDate(new Date(end));
onChange(range);
},
[onChange],
);
setHoverDate(end);
setFocusDate(new Date(end));
setNewRange(range);
}, []);

const handleMonthChangeClick = useCallback(
(month: Months, year: Year) => {
Expand Down

0 comments on commit a0622b9

Please sign in to comment.