Skip to content
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

Migration Flow: Fix multiple stickers being added simultaneously when navigating to the "DIY" option #95612

Merged
merged 5 commits into from
Oct 31, 2024

Conversation

m1r0
Copy link
Member

@m1r0 m1r0 commented Oct 23, 2024

Resolves #95560

Proposed Changes

  • This fixes a race condition causing multiple stickers to be added when the "I'll do it myself" option is selected. The problem is explained in detail here.

Why are these changes being made?

  • We need only one migration sticker to be present at all times.

Testing Instructions

  • Go to /setup/migration.
  • Select "WordPress" and the "I'll do it myself" option.
  • Check the blog stickers for the site (you can check it in the Blog RC), and make sure that only themigration-started-diy sticker is present.

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • Have you written new tests for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-aUh-p2)?

@m1r0 m1r0 self-assigned this Oct 23, 2024
@matticbot
Copy link
Contributor

matticbot commented Oct 23, 2024

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

Sections (~27 bytes added 📈 [gzipped])

name                     parsed_size           gzip_size
import-hosted-site-flow       +111 B  (+0.0%)      +27 B  (+0.0%)

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.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

@m1r0 m1r0 marked this pull request as ready for review October 23, 2024 11:38
@m1r0 m1r0 requested a review from a team October 23, 2024 11:57
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Oct 23, 2024
Copy link
Contributor

@renatho renatho left a comment

Choose a reason for hiding this comment

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

Thanks @m1r0! In my tests, it seems the issue was fixed! 🙌

I just left some suggestions in the code.

@@ -1,8 +1,9 @@
import { StepContainer } from '@automattic/onboarding';
import { useTranslate } from 'i18n-calypso';
import { FC, useMemo } from 'react';
import { FC, useMemo, useState } from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

The component SiteMigrationHowToMigrate is getting a little complex (big). I started extracting part of the logic to another hook here. I think it would be nice to base this PR there and also add the loading logic there, returning the loading state. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good!

I've updated the code but I'm a bit unsure if my implementation is aligned with your vision. 😅 Could you give it a look again?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes! That looks great!

@@ -1,8 +1,9 @@
import { StepContainer } from '@automattic/onboarding';
import { useTranslate } from 'i18n-calypso';
import { FC, useMemo } from 'react';
import { FC, useMemo, useState } from 'react';
Copy link
Contributor

@renatho renatho Oct 23, 2024

Choose a reason for hiding this comment

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

And I thought of another scenario where we could have the same race condition issue.
If the user is in a slow connection and they click on one of the options quickly it would be registering the "pending" sticker, and could try to register the "pending-{TYPE}" at the same time.

If we rebase this PR, we could also add the loader for this scenario (when creating the first "pending" sticker).

If we follow the suggestion of the other comment, I think it would assume this behavior automatically.

Copy link
Member Author

@m1r0 m1r0 Oct 25, 2024

Choose a reason for hiding this comment

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

I think I've managed to fix this scenario but I'm facing an issue with the component loading first and then the loader appearing.

aAeTa2.mp4

Can I fix this without having an extra state in the component?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm! I noticed that it's because this fetch depends on the siteId, and it's taking some time to be ready because it's coming from the store. I wonder if we could get it directly from the query string, so we would have this information immediately when the component is loaded to start already with the loader. WDYT?

Copy link
Member Author

@m1r0 m1r0 Oct 28, 2024

Choose a reason for hiding this comment

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

Could you take a look at this approach? I wasn't able to avoid the site loading because of this check. Do you think it's good enough? 🙂

Copy link
Contributor

Choose a reason for hiding this comment

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

This approach looks good to me!

But I just noticed another flickering after clicking on the options ("Do it for me", for example). It finishes the loading (the sticker creating that comes from the click), and displays the step again very quickly before calling the onSubmit.

Screen.Recording.2024-10-28.at.13.02.34.mov

I think we'll probably need an extra state here, similar to your previous approach. Maybe something that we set as loading after clicking and keep this state unchanged, so onSubmit is called when it's still in the loading state.

Copy link
Member Author

@m1r0 m1r0 Oct 28, 2024

Choose a reason for hiding this comment

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

Oh, I didn't noticed that one. I've fixed it here following your suggestion. Thank you for your patience!

@m1r0 m1r0 force-pushed the fix/multiple-migration-stickers-added branch from 080cdb6 to df6a9e0 Compare October 25, 2024 17:54
@m1r0
Copy link
Member Author

m1r0 commented Oct 25, 2024

@renatho, I've noticed that I've broken some of the tests. I'll fix those once I have your approval for the implementation approach. 🙂

@@ -1,8 +1,9 @@
import { StepContainer } from '@automattic/onboarding';
import { useTranslate } from 'i18n-calypso';
import { FC, useMemo } from 'react';
import { FC, useMemo, useState } from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes! That looks great!

@@ -1,8 +1,9 @@
import { StepContainer } from '@automattic/onboarding';
import { useTranslate } from 'i18n-calypso';
import { FC, useMemo } from 'react';
import { FC, useMemo, useState } from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm! I noticed that it's because this fetch depends on the siteId, and it's taking some time to be ready because it's coming from the store. I wonder if we could get it directly from the query string, so we would have this information immediately when the component is loaded to start already with the loader. WDYT?

@gabrielcaires
Copy link
Contributor

We are having page flickering, probably due to the
https://github.com/user-attachments/assets/5e9404f5-54a1-470a-8bd2-748cc0a965e5
#95612 (comment)

I suggest showing the content only when we are ready to show it, preventing any future race conditions.

@m1r0
Copy link
Member Author

m1r0 commented Oct 28, 2024

@gabrielcaires, do you mean replacing the whole page content, not just the step content?

Copy link
Contributor

@renatho renatho left a comment

Choose a reason for hiding this comment

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

Looks good and works well!
I'm already approving, but pinging @gabrielcaires to check if he has anything else to add based on his last comment.

@m1r0 m1r0 merged commit 10c31f4 into trunk Oct 31, 2024
11 checks passed
@m1r0 m1r0 deleted the fix/multiple-migration-stickers-added branch October 31, 2024 15:48
@github-actions github-actions bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Oct 31, 2024
@m1r0
Copy link
Member Author

m1r0 commented Oct 31, 2024

Merging to unblock a potential refactor.

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.

Multiple stickers being added simultaneously when navigating to the "DIY" option
4 participants