Skip to content

[$500] Display Name - Console log error when clicking on 'fix the errors ' link #29865

Closed

Description

@kbecciv

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 1.3.85.0
Reproducible in staging?: y
Reproducible in production?: y
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: @daveSeife
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1697554340620449

Action Performed:

  1. Click on 'Profile avatar'
  2. Click on 'Profile' link
  3. Click on 'Display name'
  4. Click on 'First name' and write 'Expensify'
  5. Click on 'Last name' and enter some value
  6. Click on 'fix the errors' link above save button

Expected Result:

No console log error when clicking on 'fix the errors ' link

Actual Result:

Console log error when clicking on 'fix the errors ' link

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Android: Native
Screen.Recording.2023-10-17.at.6.53.27.PM.mov
Android: mWeb Chrome
iOS: Native
Screen.Recording.2023-10-17.at.6.26.59.PM.mov
iOS: mWeb Safari
MacOS: Chrome / Safari
Screen.Recording.2023-10-17.at.6.33.33.PM.mov
MacOS: Desktop

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01d7ec16953ac2e5af
  • Upwork Job ID: 1714639879485181952
  • Last Price Increase: 2023-10-25

Activity

  1. added
    ExternalAdded to denote the issue can be worked on by a contributor
    BugSomething is broken. Auto assigns a BugZero manager.
    on Oct 18, 2023
  2. melvin-bot commented on Oct 18, 2023

    @melvin-bot

    Triggered auto assignment to @NicMendonca (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

  3. changed the title [-]Display Name - Console log error when clicking on 'fix the errors ' link[/-] [+][$500] Display Name - Console log error when clicking on 'fix the errors ' link[/+] on Oct 18, 2023
  4. melvin-bot commented on Oct 18, 2023

    @melvin-bot
  5. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Oct 18, 2023
  6. melvin-bot commented on Oct 18, 2023

    @melvin-bot

    Bug0 Triage Checklist (Main S/O)

    • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
    • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
      • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
    • This bug is reproducible using the reproduction steps in the OP. S/O
      • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
      • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
    • This issue is filled out as thoroughly and clearly as possible
      • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
    • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync
  7. melvin-bot commented on Oct 18, 2023

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @ntdiary (External)

  8. rayane-d commented on Oct 18, 2023

    @rayane-d
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    There is a console error when clicking on the "Fix the errors" link in the Display Name page after entering an invalid value for the First Name or Last Name field.

    What is the root cause of that problem?

    the DisplayNamePage component code lacks proper references to the input elements, preventing us from programmatically focusing on the input fields when clicking on the "Fix the errors" link. This results in a null reference error when attempting to access focusInput properties / methods here.

    Recording.2023-10-18.111137.mp4

    What changes do you think we should make in order to solve the problem?

    in the DisplayNamePage component :
    Create two refs, firstNameInputRef and lastNameInputRef, to reference the "First Name" and "Last Name" input elements, respectively.

        const firstNameInputRef = useRef(null);
        const lastNameInputRef = useRef(null);

    pass these refs to the respective InputWrapper components using the ref prop.

    <InputWrapper
        InputComponent={TextInput}
        inputID="firstName"
        ref={firstNameInputRef}
        // ...other props
    />
    <InputWrapper
        InputComponent={TextInput}
        inputID="lastName"
        ref={lastNameInputRef}
        // ...other props

    Result:

    Recording.2023-10-18.111015.mp4

    What alternative solutions did you explore? (Optional)

  9. abdel-h66 commented on Oct 18, 2023

    @abdel-h66
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    Display name page form does not focus inputs with error upon Please fix the errors in the form before continuing.

    What is the root cause of that problem?

    On the forms that use FormProvider, clicking on Please fix the errors in the form before continuing. will actually trigger a silent error Uncaught TypeError: Cannot read properties of null (reading 'isFocused')

    The issue happens during the registration in here inputRefs[inputID] = newRef; without setting the value inside .current it will cause them to vanish on re-render to become an empty object like this

    inputRef:  {
      current: null
      firstName: null
      lastName: null
    }
    focus-input.mp4

    What changes do you think we should make in order to solve the problem?

    • In the FormProvider, the input registration should become like this
      inputRefs.current = {[inputID] : newRef, ...(inputRefs.current || {})};
    • In the FormWrapper, finding the input to focus on will become like this
      const focusKey = _.find(_.keys(inputRefs.current), (key) => _.keys(errorFields).includes(key));
      This solution will fix the issue for all the other components that are using FormProvider for form management

    What alternative solutions did you explore? (Optional)

    The other option would be to simply use the Form instead of FormProvider component similar to other forms where the Please fix the errors in the form before continuing. does not have this issue.

    • The first solution fixes the issues in many places
    • We can go with the second solution, and create another ticket to refactor all the usage of FormProvider and simply retire it.

    N/A

  10. shubham1206agra commented on Oct 18, 2023

    @shubham1206agra
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    Display Name - Console log error when clicking on 'fix the errors' link

    What is the root cause of that problem?

    On the forms that use FormProvider, clicking on fix the errors will actually trigger a console error Uncaught TypeError: Cannot read properties of null (reading 'isFocused')

    The is due to multiple reasons:

    1. The registerInput has bugs due to incorrectly using refs, which are causing bugs
    2. On every input change inside the form, every InputWrapper gets re-rendered due to change in FormContext, as registerInput has a dependency of inputValues, and errors. This is creating a new ref on every input change since propsToParse.ref is null in this case.

    What changes do you think we should make in order to solve the problem?

    We need to fix both problems

    • We need to fix the use of inputRefs in FormProvider
    • To tackle this problem, we can create ref in InputWrapper in case of forwardRef to be null (using the memo also), and pass it in arguments instead of doing it inside registerInput, and pass it in arguments instead. In In
      const {registerInput} = useContext(FormContext);
      insert const ref = useMemo(() => forwardedRef || createRef(), [forwardedRef]); and pass it in
      return <InputComponent {...registerInput(inputID, {ref: forwardedRef, ...rest})} />;
      so that the inputRef will persist and will not be created on every re-render

    What alternative solutions did you explore? (Optional)

    N/A

  11. DylanDylann commented on Oct 19, 2023

    @DylanDylann
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    Clicking 'Fix The Errors" does not focus on the fields

    What is the root cause of that problem?

    Currently we don't pass ref input as prop in DisplayNamePage
    In

    const newRef = propsToParse.ref || createRef();
    propsToParse.ref will be null, it'll run createRef() in here and get error

    Screenshot 2023-10-18 at 11 26 16

    What changes do you think we should make in order to solve the problem?

    In DisplayNamePage we should add ref as prop in two inputs firstName and lastName

       <InputWrapper
            InputComponent={TextInput}
            inputID="firstName"
            ...
            ref={createRef()} // Add here
        />
    

    What alternative solutions did you explore? (Optional)

    Result

    Screen.Recording.2023-10-18.at.11.33.37.mov
  12. dukenv0307 commented on Oct 19, 2023

    @dukenv0307
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    Display Name - Console log error when clicking on 'fix the errors ' link

    What is the root cause of that problem?

    We always assign a new ref for inputRefs[inputID] whenever registerInput without checking inputRefs[inputID] is null or not. Then when we change the text input, a new ref createRef() is assigned for inputRefs[inputID] and then it is null.

    const newRef = propsToParse.ref || createRef();
    inputRefs[inputID] = newRef;

    What changes do you think we should make in order to solve the problem?

    We should check if the inputRef is already not empty we will not assign a new ref for it

    if (!inputRefs[inputID] || !inputRefs[inputID].current) {
        const newRef = propsToParse.ref || createRef();
        inputRefs[inputID] = newRef;
    }
    

    And here we will use inputRefs[inputID] instead of newRef

    What alternative solutions did you explore? (Optional)

    NA

    Result

    Screencast.from.19-10-2023.16.03.17.webm
  13. melvin-bot commented on Oct 24, 2023

    @melvin-bot

    @ntdiary, @NicMendonca Eep! 4 days overdue now. Issues have feelings too...

  14. ntdiary commented on Oct 24, 2023

    @ntdiary
    Contributor

    Will review later.

  15. ntdiary commented on Oct 25, 2023

    @ntdiary
    Contributor

    @kbecciv, @NicMendonca, not reproducible, it was fixed in PR #29962.

  16. melvin-bot commented on Oct 25, 2023

    @melvin-bot

    📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributorHelp WantedApply this label when an issue is open to proposals by contributors

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions