Skip to content
Open
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
33 changes: 25 additions & 8 deletions src/agenda/reservation-list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,31 @@ class ReservationList extends Component<ReservationListProps, State> {
}

componentDidUpdate(prevProps: ReservationListProps) {
if (this.props.topDay && prevProps.topDay && prevProps !== this.props) {
if (!sameDate(prevProps.topDay, this.props.topDay)) {
this.setState({reservations: []},
() => this.updateReservations(this.props)
);
} else {
this.updateReservations(this.props);
}
const {topDay, items} = this.props;
const {topDay: prevTopDay, items: prevItems} = prevProps;

// Only react when the visible "top day" or the agenda items actually change.
// Using `prevProps !== this.props` here is unsafe because React may recreate
// the props object on every render, which can lead to unnecessary updates and
// "Maximum update depth exceeded" loops under newer React versions.
if (!topDay || !prevTopDay) {
return;
}

const topDayChanged = !sameDate(prevTopDay, topDay);
const itemsChanged = prevItems !== items;

if (!topDayChanged && !itemsChanged) {
return;
}

if (topDayChanged) {
this.setState(
{reservations: []},
() => this.updateReservations(this.props)
);
} else if (itemsChanged) {
this.updateReservations(this.props);
}
}

Expand Down