Skip to content

Agenda crashes with RN 0.78 #2610

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

Open
bmatasar opened this issue Feb 27, 2025 · 31 comments
Open

Agenda crashes with RN 0.78 #2610

bmatasar opened this issue Feb 27, 2025 · 31 comments

Comments

@bmatasar
Copy link
Contributor

After switching to RN 0.78, the Agenda component crashes with the infamous

Warning: Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
This error is located at:
at ReservationList (http://10.0.2.2:8081/index.bundle//&platform=android&dev=true&lazy=true&minify=false&app=com.calendartest&modulesOnly=false&runModule=true&excludeSource=true&sourcePaths=url-server:103469:36)
at RCTView ()
at View (http://10.0.2.2:8081/index.bundle//&platform=android&dev=true&lazy=true&minify=false&app=com.calendartest&modulesOnly=false&runModule=true&excludeSource=true&sourcePaths=url-server:47523:43)
at RCTView ()
at View (http://10.0.2.2:8081/index.bundle//&platform=android&dev=true&lazy=true&minify=false&app=com.calendartest&modulesOnly=false&runModule=true&excludeSource=true&sourcePaths=url-server:47523:43)
at Agenda (http://10.0.2.2:8081/index.bundle//&platform=android&dev=true&lazy=true&minify=false&app=com.calendartest&modulesOnly=false&runModule=true&excludeSource=true&sourcePaths=url-server:97582:36)

@bmatasar
Copy link
Contributor Author

Code example:

import React, {useState} from 'react';
import {StatusBar, View} from 'react-native';
import {Agenda, CalendarProvider} from 'react-native-calendars';

function App(): React.JSX.Element {
  const [currentDate, setCurrentDate] = useState(new Date().toDateString());

  return (
    <View>
      <StatusBar barStyle={'light-content'} />

      <CalendarProvider date={currentDate}>
        <Agenda />
      </CalendarProvider>
    </View>
  );
}

export default App;

@drumsSandoval
Copy link

Same error

@dmohler20
Copy link

I am also having the same issue

@RameeshSayone
Copy link

any fix on this issue

@iyanushow
Copy link

same here, any fix?

@dmohler20
Copy link

dmohler20 commented Mar 18, 2025

I was messing around a little bit, and the issue seems to be coming from here in the ReservationList component class.

componentDidUpdate(prevProps) {
  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);
    }
  }
}

I think the problem is with the prevProps !== this.props check. I modified it slightly to test it out:

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

This initially fixes it when you are looking at the current week at the top, but when you switch to the full month selection that no longer works. So there is more that needs done or updated, or maybe i missed the true issue completely.

I created a PR, with slightly updated coding. It looks the the other error I encountered is only on Android devices, and is there even in the current version on older version or RN as well.

Here is a link to the PR

@eneskooo
Copy link

same issue, waiting the fix

@gkasireddy202
Copy link

The app is crashed on iOS.

react-native:0.78.0 and react-native-calendars:1.1310.0

Image

@fatihtelis
Copy link

The app is crashed on iOS.

react-native:0.78.0 and react-native-calendars:1.1310.0

Image

I got the same error.
The issue is related with React 19 which is shipped with RN 0.78.
When I downgraded to RN 0.77 with React 18.3.1, the issue is solved.

I've encountered various bugs with React 19 when using other packages, so it's safer to stick with the previous version for now.

@bmatasar
Copy link
Contributor Author

#2624 is a possible fix. Let's see what the team chooses to implement.

@ashishAmz
Copy link

is it fixed?

@bmatasar
Copy link
Contributor Author

bmatasar commented Apr 6, 2025

There are at least 2 PR's with fixes. Let's see what WIX team will do about it.

@voulgarakis
Copy link

same issue

@bmatasar
Copy link
Contributor Author

It looks like they have released an update but still without the fix.

@artus9033
Copy link

Bump, @nitzanyiz can you take a look at the fix PRs?

@Lewitje
Copy link

Lewitje commented Apr 28, 2025

Same issue here

@kamador45
Copy link

@Lewitje I had the same issue but I could fix it using the solution of @bmatasar mentioned.

@gkasireddy202
Copy link

I faced this same issue in RN@0.79.2, react-native-calender:1.1312.0, and I just added the below code in
node_modules>react-native-calenders>src>agenda>reservation-list>index.js>ReservationList>index.js

componentDidUpdate(prevProps) {
if (this.props.topDay && prevProps.topDay &&
(!sameDate(prevProps.topDay, this.props.topDay) ||
prevProps.items !== this.props.items ||
prevProps.selectedDay !== this.props.selectedDay)) {

if (!sameDate(prevProps.topDay, this.props.topDay)) {
  this.setState({ reservations: [] }, () => this.updateReservations(this.props));
} else {
  this.updateReservations(this.props);
}

}
}

Is this right?

@bmatasar
Copy link
Contributor Author

I faced this same issue in RN@0.79.2, react-native-calender:1.1312.0, and I just added the below code in node_modules>react-native-calenders>src>agenda>reservation-list>index.js>ReservationList>index.js

componentDidUpdate(prevProps) { if (this.props.topDay && prevProps.topDay && (!sameDate(prevProps.topDay, this.props.topDay) || prevProps.items !== this.props.items || prevProps.selectedDay !== this.props.selectedDay)) {

if (!sameDate(prevProps.topDay, this.props.topDay)) {
  this.setState({ reservations: [] }, () => this.updateReservations(this.props));
} else {
  this.updateReservations(this.props);
}

} }

Is this right?

It is partially right. It does not crash anymore but you might discover that some changes are not propagated in the view. In the fix I suggested, I checked all the properties that are used in the component.

@gkasireddy202
Copy link

gkasireddy202 commented May 21, 2025

@bmatasar - Thanks for your update.
Please provide the code changes that you did, and I will add them to my project.

Or why are these changes not showing the latest react-native-calenders version?

@bmatasar
Copy link
Contributor Author

@gkasireddy202

#2624 is a possible fix. Let's see what the team chooses to implement.

@gkasireddy202
Copy link

gkasireddy202 commented May 21, 2025

@bmatasar - I copied the componentDidUpdate code and pasted into my project.
813f338

Here is the code. Please review if it is correct or not.
I did not use the ReservationListProps parameter.

componentDidUpdate(prevProps) {
if (this.props.topDay && prevProps.topDay) {
if (this.props.showOnlySelectedDayItems !== prevProps.showOnlySelectedDayItems || this.props.items !== prevProps.items || !sameDate(this.props.selectedDay, prevProps.selectedDay)) {
if (!sameDate(prevProps.topDay, this.props.topDay)) {
this.setState({ reservations: [] }, () => this.updateReservations(this.props));
} else {
this.updateReservations(this.props);
}
}
}
}

@neeleshyadav253
Copy link

Open your project directory.

Navigate to:
node_modules/react-native-calendars/src/agenda/reservation-list/index.js
Open the File for Editing

Open index.js.

Find the componentDidUpdate Method

Search for componentDidUpdate in the file.

Replace the Method with the Updated One

Replace the existing componentDidUpdate with the following code:

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

@bmatasar
Copy link
Contributor Author

You can use patch-package with the attached patch:

react-native-calendars+1.1312.0.patch

@gkasireddy202
Copy link

@bmatasar and @neeleshyadav253 - Thanks

@gkasireddy202
Copy link

react-native-calenders:1.1312.0

The onDayPress={(day) => {} method does not call a single press.
It was called once when I tapped the multiples on the day in the agenda calendar.
This issue is in react-native:0.79.2 on Android 15.

It is working fine on iOS.

video.mp4

@Lewitje
Copy link

Lewitje commented May 26, 2025

I have the same issue as @gkasireddy202 onDayPress does get called, I can alert a success.
I have to click around a-lot before the agenda view opens.

This only happens to me on an older Android version (version 14) and in release mode, doesn't happen in development.
react-native: 0.78.0
react-native-calendars: 1.1312.0

I've tried a few other versions of react-native-calendars and get the same issue, also tried the patch.

calendar.mp4

@bmatasar
Copy link
Contributor Author

I have the same issue as @gkasireddy202 onDayPress does get called, I can alert a success. I have to click around a-lot before the agenda view opens.

This only happens to me on an older Android version (version 14) and in release mode, doesn't happen in development. react-native: 0.78.0 react-native-calendars: 1.1312.0

I've tried a few other versions of react-native-calendars and get the same issue, also tried the patch.

calendar.mp4

@Lewitje , @gkasireddy202
It looks like this has a different cause. Maybe you fill in another issue.

@gkasireddy202
Copy link

Here is the issue:
#2662

@shareef-dweikat
Copy link

shareef-dweikat commented May 29, 2025

You can use patch-package with the attached patch:

react-native-calendars+1.1312.0.patch

Thanks @bmatasar ! Who is the publisher of this patch? Is there a PR where i can see the code changes?

@bmatasar
Copy link
Contributor Author

#2624 is a possible fix. Let's see what the team chooses to implement.

@shareef-dweikat - It's mentioned above

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