Skip to content

Fix: RangeError - Maximum call stack size exceeded in IonDatetime bindings - #37

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/ion-datetime-infinite-loop
Open

Fix: RangeError - Maximum call stack size exceeded in IonDatetime bindings#37
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/ion-datetime-infinite-loop

Conversation

@sentry

@sentry sentry Bot commented Jul 10, 2026

Copy link
Copy Markdown

This PR addresses the RangeError: Maximum call stack size exceeded occurring due to an infinite synchronous update loop when using IonDatetime with React Hook Form.

Root Cause:
The IonDatetime components in src/pages/(auth)/dob/page.tsx and src/components/ui/form-datetime.tsx were manually wired to React Hook Form. The onIonChange handler would call form.setValue() and form.trigger(), which caused a re-render. The value prop, derived from form.getValues()?.toISOString(), could produce a slightly different string (due to local time vs. UTC date truncation differences or new object reference), causing Ionic to detect a change and re-fire onIonChange immediately. This created an infinite loop, exhausting the call stack within Ionic's internal focus-trapping mechanisms.

Solution:

  1. src/pages/(auth)/dob/page.tsx: The IonDatetime component is now wrapped with React Hook Form's <Controller>. This allows for proper management of value and onChange without manual setValue() and trigger() calls.
  2. src/components/ui/form-datetime.tsx: The IonDatetime component within FormDateTimeInput also had its onIonChange handler updated to use field.onChange from the FormField render prop.
  3. Value Normalization: In both cases, the value passed to IonDatetime is now normalized to a YYYY-MM-DD string (e.g., field.value.toISOString().split('T')[0]). This ensures that Ionic does not detect a spurious change in the value prop due to time/timezone differences or new object references, effectively breaking the infinite loop.

Fixes SH-STUDENT-APP-1S
Fixes TECH-2063

@linear-code

linear-code Bot commented Jul 10, 2026

Copy link
Copy Markdown

TECH-2063

@netlify

netlify Bot commented Jul 10, 2026

Copy link
Copy Markdown

Deploy Preview for studenthub-student ready!

Name Link
🔨 Latest commit eb3b473
🔍 Latest deploy log https://app.netlify.com/projects/studenthub-student/deploys/6a5181babbde3a0009c7f16c
😎 Deploy Preview https://deploy-preview-37--studenthub-student.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment on lines +143 to +145
value={field.value instanceof Date
? field.value.toISOString().split('T')[0]
: undefined}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The date of birth field isn't pre-populated on refresh because form.setValue is called with a string, but the IonDatetime component expects a Date object.
Severity: MEDIUM

Suggested Fix

Convert the date string received from the API into a Date object before calling form.setValue. For example, use new Date(res.candidate_birth_date) when setting the value for the candidate_birth_date field in the useEffect hook.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: src/pages/(auth)/dob/page.tsx#L143-L145

Potential issue: On page refresh, when the user profile is not in the Redux store, the
`useEffect` hook fetches the profile and sets the `candidate_birth_date` form value with
a string from the API response. The `IonDatetime` component's `value` is determined by
`field.value instanceof Date`. Since `field.value` is a string, this check fails, the
component's `value` prop becomes `undefined`, and the input field appears empty instead
of showing the user's saved date of birth.

Did we get this right? 👍 / 👎 to inform future reviews.

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

Successfully merging this pull request may close these issues.

0 participants