-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Stepper: Avoid calling the submit function of the process step multiple times #98197
Conversation
Jetpack Cloud live (direct link)
Automattic for Agencies live (direct link)
|
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: Sections (~185 bytes added 📈 [gzipped])
Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to. Legend What is parsed and gzip size?Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory. Generated by performance advisor bot at iscalypsofastyet.com. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This prevents the exitFlow
in site-setup
to run twice so that it isn't executed again after the resetOnboardStoreWithSkipFlags
has been called.
* 4. The `exitFlow` function may set another pending action, and call `resetOnboardStoreWithSkipFlags` function | ||
* 5. The effect to call the `submit` runs again since the `recordSignupComplete` function changes | ||
* | ||
* It's also a reason why we have a hacky to set a pending action to return a Promise that is never resolved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* It's also a reason why we have a hacky to set a pending action to return a Promise that is never resolved. | |
* It's also a reason why we have a hack to set a pending action to return a Promise that is never resolved. |
@@ -49,6 +49,28 @@ const ProcessingStep: React.FC< ProcessingStepProps > = function ( props ) { | |||
const [ hasEmptyActionRun, setHasEmptyActionRun ] = useState( false ); | |||
const [ destinationState, setDestinationState ] = useState( {} ); | |||
|
|||
/** | |||
* There is a long-term bug here that the `submit` function will be called multiple times if we | |||
* call `resetOnboardStoreWithSkipFlags` after the submit function (e.g.: exitFlow) to reset states |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to myself: like here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @arthur791004, thanks for prioritizing this!
My main concern is the fact that this will change all flows, so I tested a few more flows to try to catch any possible issue, and all of them worked as expected:
- Free /start/onboarding with the
treatment
flag - Free /start/onboarding with the
control
flag worked as expected fixing the bug - Paid plan on /start/onboarding on both
treatment
andcontrol
- /setup/newsletter also worked as expected
- /setup/start-writing
- Add a new site inside /sites on both
treatment
andcontrol
flags
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great and a general precaution that is worth adding. But I think the original issue is that exitFlow
is setting a pending action, then redirecting to the processing step. This is certainly not exiting.
exitFlow
should be a synchronous function that just redirects. This issue emerged because something rightfully assumed exitFlow
will be the last thing to run and reset the store there. But then something else made exitFlow
do some non-exiting stuff, and this broke the original assumption.
It would be great if we can make exitFlow
not do anything besides exiting. and set the pending action in another function.
c5caaaf
to
01647de
Compare
This PR modifies the release build for the following Calypso Apps: For info about this notification, see here: PCYsg-OT6-p2
To test WordPress.com changes, run |
Related to #98167
Proposed Changes
There is a long-term bug here that the
submit
function will be called multiple times if wecall
resetOnboardStoreWithSkipFlags
after the submit function (e.g.: exitFlow) to reset statesthat are listed as the dependencies of the
recordSignupComplete
, e.g.: goals, selectedDesign, etc.Here is a possible flow:
exitFlow
function that is defined by each flowexitFlow
function may set another pending action, and callresetOnboardStoreWithSkipFlags
functionIt's also a reason why we have a hacky to set a pending action to return a Promise that is never resolved.
The issue, #98167, was the
exitFlow
might be called multiple times. However, we cleared the onboard state on the first call so the active theme would be reset to the default of the write intent when the pending action was triggered again (theselectedDesign
becamenull
on the second call.As a result, this PR proposed to define a flag to avoid calling the submit function multiple times in the short term.
Another way is to remove the recordSignupComplete function from the dependencies of the effect that
is called when the hasActionSuccessfullyRun flag turns on. But it seems to be better to use an explicit
flag to avoid the issue and describe it here.
The current solution will affect all flows. If we want to avoid any regression, we can simply add a flag like
isFlowCompleted
to the specific flow (e.g.: site-setup) to return immediately when theexitFlow
function calls multiple times.Why are these changes being made?
Testing Instructions
Publish a blog
goalPre-merge Checklist