Fix: RangeError - Maximum call stack size exceeded in IonDatetime bindings - #37
Open
sentry[bot] wants to merge 1 commit into
Open
Fix: RangeError - Maximum call stack size exceeded in IonDatetime bindings#37sentry[bot] wants to merge 1 commit into
sentry[bot] wants to merge 1 commit into
Conversation
✅ Deploy Preview for studenthub-student ready!
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} |
Author
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses the
RangeError: Maximum call stack size exceededoccurring due to an infinite synchronous update loop when usingIonDatetimewith React Hook Form.Root Cause:
The
IonDatetimecomponents insrc/pages/(auth)/dob/page.tsxandsrc/components/ui/form-datetime.tsxwere manually wired to React Hook Form. TheonIonChangehandler would callform.setValue()andform.trigger(), which caused a re-render. Thevalueprop, derived fromform.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-fireonIonChangeimmediately. This created an infinite loop, exhausting the call stack within Ionic's internal focus-trapping mechanisms.Solution:
src/pages/(auth)/dob/page.tsx: TheIonDatetimecomponent is now wrapped with React Hook Form's<Controller>. This allows for proper management ofvalueandonChangewithout manualsetValue()andtrigger()calls.src/components/ui/form-datetime.tsx: TheIonDatetimecomponent withinFormDateTimeInputalso had itsonIonChangehandler updated to usefield.onChangefrom theFormFieldrender prop.valuepassed toIonDatetimeis now normalized to aYYYY-MM-DDstring (e.g.,field.value.toISOString().split('T')[0]). This ensures that Ionic does not detect a spurious change in thevalueprop due to time/timezone differences or new object references, effectively breaking the infinite loop.Fixes SH-STUDENT-APP-1S
Fixes TECH-2063