Skip to content

My Jetpack: Fix onboarding slider shift on window resize #43510

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

Merged
merged 1 commit into from
May 21, 2025

Conversation

manzoorwanijk
Copy link
Member

Fixes MYJP-111

@keoshi noticed that the My Jetpack onboarding carousel slides shift slightly when the browser window is resized.
Screen.Recording.2025-05-01.at.14.27.13.mov

The reason for the issue is that the container width in Swipeable component is stale for a moment when the window is resized and is not immediately applied to the slide, which is used by the DotPager component.

Proposed changes:

  • Reset the Swipeable component local state when the window is resized by using an underrated feature of React - Resetting state with a key

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

Testing instructions:

  • Disconnect your site - jetpack docker wp jetpack disconnect blog
  • Go to My Jetpack
  • Resize the browser window
  • Confirm that the carousel slides do not shift
BEFORE AFTER
Screen.Recording.2025-05-19.at.1.20.48.PM.mov
Screen.Recording.2025-05-19.at.1.21.52.PM.mov

@manzoorwanijk manzoorwanijk requested a review from a team May 19, 2025 08:05
@manzoorwanijk manzoorwanijk self-assigned this May 19, 2025
@manzoorwanijk manzoorwanijk added [Type] Bug When a feature is broken and / or not performing as intended [Status] Needs Team Review Obsolete. Use Needs Review instead. labels May 19, 2025
Copy link
Contributor

github-actions bot commented May 19, 2025

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack or WordPress.com Site Helper), and enable the fix/my-jetpack/slider-shift-on-window-resize branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/my-jetpack/slider-shift-on-window-resize
bin/jetpack-downloader test jetpack-mu-wpcom-plugin fix/my-jetpack/slider-shift-on-window-resize

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

Copy link
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

Copy link

Code Coverage Summary

This PR did not change code coverage!

That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷

Full summary · PHP report · JS report

@manzoorwanijk manzoorwanijk requested a review from keoshi May 19, 2025 12:17
@grzegorz-cp
Copy link
Contributor

This is a very innovative way to use keys, but using changing width as a key doesn't seem right to me. Introducing it to all Swipeable components also seems like an unnesary risk.
I think it would be better to fix it by either leveraging the resize observer or considering using throttle to optimise the resize events in the first place.

If this can't be avoided, passing this type of key from the consuming component that actually needs it (as outside props) would be a safer bet.

@manzoorwanijk
Copy link
Member Author

Thank you @grzegorz-cp for raising those concerns. I explained the reason for this issue in the PR description.

but using changing width as a key doesn't seem right to me

The width will change only when the window resizes and that is exactly when we want the UI to reflect the changes.

considering using throttle to optimise the resize events in the first place

That won't solve this issue and throttling is already in place.

If this can't be avoided, passing this type of key from the consuming component that actually needs it (as outside props) would be a safer bet.

key is a special prop in React and it's not passed down as a prop to the component you pass it to. So, the consumer component won't know the changing width and thus won't make any difference.

Conclusion: It's a perfectly valid usage and most of the time, that key will be undefined as the window won't be resized all the time. So, the only time it gets used is when the browser window gets resized and that won't affect much of the component behavior, except that it reflects the UI immediately, which is what we want.

@grzegorz-cp
Copy link
Contributor

grzegorz-cp commented May 20, 2025

Ah right, of course key is not passed down. I looked at { ...otherProps } in the code and thought about different props but applied it to keys.

Thanks 👍

@manzoorwanijk manzoorwanijk merged commit 27f96da into trunk May 21, 2025
88 checks passed
@manzoorwanijk manzoorwanijk deleted the fix/my-jetpack/slider-shift-on-window-resize branch May 21, 2025 05:10
@github-actions github-actions bot removed the [Status] Needs Team Review Obsolete. Use Needs Review instead. label May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[JS Package] Components RNA [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants