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

Plans 2023: Account for siteId when updating storage add-ons UI state #87342

Merged
merged 10 commits into from
Mar 20, 2024

Conversation

jeyip
Copy link
Contributor

@jeyip jeyip commented Feb 9, 2024

Related to #85773

Proposed Changes

  • Persist storage add-on UI state on a per site basis

Testing Instructions

  • Navigate to /plans and select a non-standard storage add-on option
  • Switch sites
  • Verify that the storage add-on option has changed to the default

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • https://wpcalypso.wordpress.com/devdocs/docs/testing/index.md 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-ajp-p2)?

@jeyip jeyip added the 2023 Pricing Page ⚡ Changes for pricing page optimisation 2023 label Feb 9, 2024
@jeyip jeyip self-assigned this Feb 9, 2024
@jeyip jeyip force-pushed the update/storage-add-on-ui-store branch from 1bd14e3 to 4845441 Compare February 12, 2024 21:34
@matticbot
Copy link
Contributor

matticbot commented Feb 12, 2024

This PR modifies the release build for the following Calypso Apps:

For info about this notification, see here: PCYsg-OT6-p2

  • odyssey-stats
  • wpcom-block-editor

To test WordPress.com changes, run install-plugin.sh $pluginSlug update/storage-add-on-ui-store on your sandbox.

@matticbot
Copy link
Contributor

matticbot commented Feb 12, 2024

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

Sections (~108 bytes added 📈 [gzipped])

name                  parsed_size           gzip_size
update-design-flow         +207 B  (+0.0%)      +44 B  (+0.0%)
plugins                    +207 B  (+0.0%)      +44 B  (+0.0%)
plans                      +207 B  (+0.0%)      +44 B  (+0.0%)
link-in-bio-tld-flow       +207 B  (+0.0%)      +44 B  (+0.0%)
jetpack-app                +207 B  (+0.1%)      +44 B  (+0.0%)
theme                       +65 B  (+0.0%)      +23 B  (+0.0%)
stats                       +65 B  (+0.0%)      +21 B  (+0.0%)
import-flow                 +65 B  (+0.0%)      +20 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.

Async-loaded Components (~44 bytes added 📈 [gzipped])

name                                             parsed_size           gzip_size
async-load-signup-steps-plans-theme-preselected       +207 B  (+0.1%)      +44 B  (+0.0%)
async-load-signup-steps-plans                         +207 B  (+0.1%)      +44 B  (+0.0%)

React components that are loaded lazily, when a certain part of UI is displayed for the first time.

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.

@jeyip jeyip marked this pull request as ready for review February 12, 2024 22:38
@jeyip jeyip requested a review from a team as a code owner February 12, 2024 22:38
@jeyip jeyip requested a review from chriskmnds February 12, 2024 22:38
@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 Feb 12, 2024
@@ -77,7 +77,7 @@ const usePricingMetaForGridPlans = ( {
purchaseId: currentPlan?.purchaseId,
} );
const selectedStorageOptions = useSelect(
( select ) => select( WpcomPlansUI.store ).getSelectedStorageOptions(),
( select ) => select( WpcomPlansUI.store ).getSelectedStorageOptions( selectedSiteId ?? 0 ),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: Consider empty state for siteId ( Ex. onboarding for new site )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like 0 is used to represent a non-existent siteId throughout the codebase. I believe it makes sense here as well, but feel free to chime in if it doesn't

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's mainly used to bypass typescript when used with hooks for existing hooks. But I think the right representation of a non existing site id is either null or undefined. We should probably follow it where possible, especially when introducing new code. Because just sending 0 is trying to trick the type system where actually the underlying hook or function should be handling the empty value case.

I know sometimes for existing hooks we do this to just move things forward. And sometimes it's not possible to fix them due to the nature of hooks. But in other places I think we should avoid introducing them.

Copy link
Contributor

@ddc22 ddc22 Feb 13, 2024

Choose a reason for hiding this comment

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

Correct me if I am wrong here though. Because seems like we might have to do a lot of extra work to support the 'Empty' value for the selected site id.

Looks like it can be done by changing line at
https://github.com/Automattic/wp-calypso/pull/87342/files#diff-2acc0cb518c786c436317cfc21f6d624bb922f4b372df93dc57534b10f6786beR10-R11

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IIRC typescript gets upset at us for attempting to index an object with a null or undefined value. I'll double check tomorrow though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After reading over #87342 (comment), just wanted to say thanks again for the insight @ddc22.

I removed usage of 0 to represent a non-existent site id in 07e8ae7

@jeyip jeyip changed the title Plans 2023: Update storage add-ons UI store Plans 2023: Account for siteId when updating storage add-ons UI state Feb 12, 2024
@southp
Copy link
Contributor

southp commented Mar 5, 2024

There is a dedicated issue for the bug now: #86152 :)

@southp
Copy link
Contributor

southp commented Mar 15, 2024

@jeyip When you have a moment, could you help me clarify the status of this? I'd be grateful :)

@jeyip
Copy link
Contributor Author

jeyip commented Mar 18, 2024

Hi @southp! Thanks for pinging this. I'll check later today

@jeyip jeyip force-pushed the update/storage-add-on-ui-store branch 2 times, most recently from 3c1ede6 to 205c44a Compare March 19, 2024 18:08
) => {
// @ts-expect-error TS is unhappy if we index by a null or an undefined value. We, however,
// expect siteId to be null or undefined here before site creation ( like during onboarding ).
return state.selectedStorageOptionForPlans?.[ siteId ][ planSlug ];
Copy link
Contributor Author

@jeyip jeyip Mar 19, 2024

Choose a reason for hiding this comment

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

@ddc22 To maintain the representation of a non-existent siteId as null or undefined, we now index state by null or undefined values. This gives me pause, but since we're doing this intentionally, and since JS coerces these false-y values into strings before indexing ( Ex. state[null] becomes state['null'] ) , I believe it's fine. Lemme know if you have thoughts about this though.

@jeyip jeyip force-pushed the update/storage-add-on-ui-store branch from 8e83652 to 22fa91e Compare March 20, 2024 18:05
@jeyip jeyip force-pushed the update/storage-add-on-ui-store branch from 22fa91e to 28a1781 Compare March 20, 2024 18:16
@jeyip
Copy link
Contributor Author

jeyip commented Mar 20, 2024

Merging this PR for the time being. Happy to return and make any further changes requested by folks

@jeyip jeyip merged commit 1219c81 into trunk Mar 20, 2024
11 checks passed
@jeyip jeyip deleted the update/storage-add-on-ui-store branch March 20, 2024 22:11
@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 Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2023 Pricing Page ⚡ Changes for pricing page optimisation 2023
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants