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

Fix bug that introduced a race condition in consumers #2373

Merged
merged 2 commits into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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