You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[$1000] Dev - Console log error displayed on clicking 'Select a workspace' dropdown value #23818
BugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorReviewingHas a PR in reviewWeeklyKSv2
Precondition: account should have only one active workspace
Create a workspace & make sure you have only one active workspace
Click on 'FAB' menu ion
Click on 'New room'
4, Click on 'Workspace' dropdown menu
Click on 'Select a workspace' option
Expected Result:
There should be no console log error
Actual Result:
Console log error displayed [Cannot update a component (Form) while rendering a different component (SafeAreaInsetsContext.Consumer).]
Workaround:
Can the user still use Expensify without this being fixed? Have you informed them of the workaround?
Platforms:
Which of our officially supported platforms is this issue occurring on?
Android / native
Android / Chrome
iOS / native
iOS / Safari
MacOS / Chrome / Safari
MacOS / Desktop
Version Number: Dev Reproducible in staging?: needs reproduction Reproducible in production?: needs reproduction 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 Notes/Photos/Videos: Any additional supporting documentation
Please re-state the problem that we are trying to solve in this issue.
The issue at hand involves a console.log error that appears when the Select a workspace option in the Workspace dropdown menu is clicked. The expected outcome is that no console.log error should be displayed during this process.
What is the root cause of that problem?
Upon reviewing the console error and the associated code, the root cause of the problem appears to be tied to a state update operation that occurs during the rendering of Form component. More specifically, the function that iterates over inputRefs.current and conditionally calls setInputValues is invoked during rendering, which leads to this error. This operation attempts to delete a reference and update the state while the component is rendering, which violates the rules of Hooks in React.
What changes do you think we should make in order to solve the problem?
To resolve this issue, the state update operation needs to be moved out of the rendering process. We can accomplish this by wrapping the operation in a useEffect hook. This hook ensures that the state update operation is invoked as a side effect after the component render, rather than during the render itself.
Here is how we can modify the function:
useEffect(() => {
_.each(inputRefs.current, (inputRef, inputID) => {
if (inputRef) {
return;
}
setInputValues((prevState) => {
const copyPrevState = _.clone(prevState);
delete copyPrevState[inputID];
return copyPrevState;
});
});
}, [/* same dependencies as the childrenWrapperWithProps function */]);
By making this modification, we should be able to eliminate the console.log error.
Additionally, it may be possible to slightly optimize this code by moving the setInputValues function call outside of the _.each loop. However, this would require further investigation to ensure it doesn't introduce new issues or unexpected behavior.
This code is called during the render process. Setting state during the rendering should be avoided and leads to an unexpected result. In addition, calling the set function of another component during rendering is an error as described here
This is the root cause
What changes do you think we should make in order to solve the problem?
In order to avoid this pattern, we can use useEffect. useEffect is the perfect location we can change state
Move the above code into the useEffect
changed the title [-]Dev - Console log error displayed on clicking 'Select a workspace' dropdown value[/-][+][$1000] Dev - Console log error displayed on clicking 'Select a workspace' dropdown value[/+]on Jul 31, 2023
My understanding is that it's specifically addressing a regression from the PR author that introduced it, and so it makes sense to "fix your work" in this case.
BugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorReviewingHas a PR in reviewWeeklyKSv2
Activity
melvin-bot commentedon Jul 28, 2023
Triggered auto assignment to @trjExpensify (
Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.melvin-bot commentedon Jul 28, 2023
Bug0 Triage Checklist (Main S/O)
Platformsin OP are ✅)ygshbht commentedon Jul 30, 2023
Proposal
Please re-state the problem that we are trying to solve in this issue.
The issue at hand involves a
console.logerror that appears when the Select a workspace option in the Workspace dropdown menu is clicked. The expected outcome is that no console.log error should be displayed during this process.What is the root cause of that problem?
Upon reviewing the console error and the associated code, the root cause of the problem appears to be tied to a state update operation that occurs during the rendering of
Formcomponent. More specifically, the function that iterates overinputRefs.currentand conditionally callssetInputValuesis invoked during rendering, which leads to this error. This operation attempts to delete a reference and update the state while the component is rendering, which violates the rules of Hooks in React.App/src/components/Form.js
Lines 348 to 362 in eb02006
What changes do you think we should make in order to solve the problem?
To resolve this issue, the state update operation needs to be moved out of the rendering process. We can accomplish this by wrapping the operation in a
useEffecthook. This hook ensures that the state update operation is invoked as a side effect after the component render, rather than during the render itself.Here is how we can modify the function:
By making this modification, we should be able to eliminate the
console.logerror.2.New.Expensify.-.Google.Chrome.2023-07-30.18-09-09.mp4
Additionally, it may be possible to slightly optimize this code by moving the
setInputValuesfunction call outside of the_.eachloop. However, this would require further investigation to ensure it doesn't introduce new issues or unexpected behavior.dummy-1111 commentedon Jul 31, 2023
Proposal
Please re-state the problem that we are trying to solve in this issue.
Console error displayed When select
Select a workspaceinNew RoompageWhat is the root cause of that problem?
When we select
Select a workspace,Who can posttext input disappears and the following code is runThis code is called during the render process. Setting state during the rendering should be avoided and leads to an unexpected result. In addition, calling the set function of another component during rendering is an error as described here
This is the root cause
What changes do you think we should make in order to solve the problem?
In order to avoid this pattern, we can use
useEffect.useEffectis the perfect location we can change stateMove the above code into the useEffect
This works great
What alternative solutions did you explore? (Optional)
trjExpensify commentedon Jul 31, 2023
Moving on
externalfor input from C+ as a dev bug report.[-]Dev - Console log error displayed on clicking 'Select a workspace' dropdown value[/-][+][$1000] Dev - Console log error displayed on clicking 'Select a workspace' dropdown value[/+]melvin-bot commentedon Jul 31, 2023
Job added to Upwork: https://www.upwork.com/jobs/~01c6e4120bf877ce30
11 remaining items
Natnael-Guchima commentedon Jul 31, 2023
Accepted the offer. Thanks.
ygshbht commentedon Jul 31, 2023
Hi, so a call stack member can propose anytime and they'll get the job? @trjExpensify @rushatgabhane
trjExpensify commentedon Jul 31, 2023
My understanding is that it's specifically addressing a regression from the PR author that introduced it, and so it makes sense to "fix your work" in this case.
ygshbht commentedon Jul 31, 2023
So is he not going to get paid?
trjExpensify commentedon Jul 31, 2023
I don't think Expensify's financial arrangement with agencies we partner with are in scope of the discussion we're having here, Yogesh.
ygshbht commentedon Jul 31, 2023
Oh... makes sense. Apologies for the misunderstanding earlier
rezkiy37 commentedon Aug 4, 2023
#23919 was merged. Is the issue going to be closed?
rushatgabhane commentedon Aug 14, 2023
created a manual request - https://staging.new.expensify.com/r/2106109152629952
rushatgabhane commentedon Aug 14, 2023
this issue can be closed i guess
trjExpensify commentedon Aug 15, 2023
We need to pay @Natnael-Guchima for the bug report right?
rushatgabhane commentedon Aug 23, 2023
Yes!
trjExpensify commentedon Aug 23, 2023
Okay, confirming payments:
Closing this out!
JmillsExpensify commentedon Aug 24, 2023
Reviewed the details for @rushatgabhane. Approved for $1k payment in NewDot based on the BZ confirmation summary above.