-
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
Plans 2023: Account for siteId when updating storage add-ons UI state #87342
Conversation
Jetpack Cloud live (direct link)
Automattic for Agencies live (direct link)
|
1bd14e3
to
4845441
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 |
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: Sections (~108 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. Async-loaded Components (~44 bytes added 📈 [gzipped])
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. Generated by performance advisor bot at iscalypsofastyet.com. |
@@ -77,7 +77,7 @@ const usePricingMetaForGridPlans = ( { | |||
purchaseId: currentPlan?.purchaseId, | |||
} ); | |||
const selectedStorageOptions = useSelect( | |||
( select ) => select( WpcomPlansUI.store ).getSelectedStorageOptions(), | |||
( select ) => select( WpcomPlansUI.store ).getSelectedStorageOptions( selectedSiteId ?? 0 ), |
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.
TODO: Consider empty state for siteId ( Ex. onboarding for new site )
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 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
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.
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.
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.
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
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.
IIRC typescript gets upset at us for attempting to index an object with a null
or undefined
value. I'll double check tomorrow though
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.
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
There is a dedicated issue for the bug now: #86152 :) |
@jeyip When you have a moment, could you help me clarify the status of this? I'd be grateful :) |
Hi @southp! Thanks for pinging this. I'll check later today |
3c1ede6
to
205c44a
Compare
) => { | ||
// @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 ]; |
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.
@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.
8e83652
to
22fa91e
Compare
22fa91e
to
28a1781
Compare
Merging this PR for the time being. Happy to return and make any further changes requested by folks |
Related to #85773
Proposed Changes
Testing Instructions
Pre-merge Checklist