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

Site settings: prevent console price formatting warnings #99046

Merged
merged 3 commits into from
Jan 31, 2025

Conversation

ciampo
Copy link
Contributor

@ciampo ciampo commented Jan 29, 2025

Proposed Changes

  • Change the computation of the agency billing message and its dependencies to be lazier

Why are these changes being made?

Currently, the price (that is displayed in the agency billing message) is compute every render.
When there's no agency associated to the site, this causes the browser console to be flooded with warnings.

Those warnings should pollute the browser console and should actually only be shown when the price needs to be calculated/displayed.

Note

The code in this page is quite messy, mixing logic about "untangled"/"tangled" sites, a4a and non-a4a site, and other forks in the logic. I tried to keep the scope of this PR as focused as possible on solving the warnings, but this file would definitely benefit from a refactor.

Testing Instructions

  • Load a simple site's settings page (ie. /settings/general/{SITE_SLUG}, make sure that:
    • the page looks and behaves as expected
    • the browser console doesn't show warnings about the value and currency not being defined correctly

Screenshot 2025-01-29 at 17 48 58

  • Test that the billing message is displayed correctly for a4a development sites:
    • Create an A4A development site (I followed instructions from pdtkmj-2Te-p2 )
    • In calypso WPCom environment, visit settings/general/{A4A_DEV_SITE_SLUG}
    • Make sure that the page behaves and looks as expected. In particular, check that:
      • the "Launch site" and "Refer to client" buttons work as expected;
      • the billing message is shows correctly next to the "launch site" button
      • when clicking the "Launch site" button, a modal is shown with the same billing message as its contents

Screenshot 2025-01-29 at 17 10 37
Screenshot 2025-01-29 at 17 09 14

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 UI changes, have we tested the change in various languages (for example, ES, PT, FR, or DE)? The length of text and words vary significantly between languages.
  • 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)?

@ciampo ciampo added the [Feature] Site Settings All other general site settings. label Jan 29, 2025
@ciampo ciampo requested review from candy02058912, ivan-ottinger and a team January 29, 2025 16:49
@ciampo ciampo self-assigned this Jan 29, 2025
@matticbot matticbot added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Jan 29, 2025
@matticbot
Copy link
Contributor

matticbot commented Jan 29, 2025

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

Sections (~42 bytes added 📈 [gzipped])

name           parsed_size           gzip_size
site-settings       +131 B  (+0.0%)      +42 B  (+0.0%)
settings            +131 B  (+0.0%)      +42 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.

Copy link
Contributor

@ivan-ottinger ivan-ottinger left a comment

Choose a reason for hiding this comment

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

Thank you for this fix and the review request, @ciampo.

The proposed changes look good to me. I can confirm the warning isn't displaying.

I haven't noticed any regressions when testing with either non-A4A or A4A sites. The modal is loading price correctly and the buttons work as expected:

Markup on 2025-01-31 at 11:35:21

The code in this page is quite messy, mixing logic about "untangled"/"tangled" sites, a4a and non-a4a site, and other forks in the logic. I tried to keep the scope of this PR as focused as possible on solving the warnings, but this file would definitely benefit from a refactor.

I remember it wasn't fun indeed when we worked on the A4A-related changes on this page. It caters to many different cases. I suspect that could have contributed to us missing the warning before.

client/sites/settings/site/visibility/index.jsx Outdated Show resolved Hide resolved
@ciampo ciampo force-pushed the fix/launch-site-split-agency-logic branch from 9215dec to 1b20e75 Compare January 31, 2025 12:58
@ciampo
Copy link
Contributor Author

ciampo commented Jan 31, 2025

Thank you for testing, @ivan-ottinger ! I pushed a couple of commits to address feedback, could you take another look to make sure everything keeps working as expected?

Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

This LGTM from my perspective 👍

Thanks for improving the price logic, looks so much cleaner now!

@ivan-ottinger
Copy link
Contributor

Thank you for testing, @ivan-ottinger ! I pushed a couple of commits to address feedback, could you take another look to make sure everything keeps working as expected?

I have reviewed the latest changes and tested the PR again and haven't noticed any issues. 👌🏼🙂

(tested with Simple, Atomic A4A, Atomic non-A4A sites)

@ciampo ciampo merged commit f81446e into trunk Jan 31, 2025
13 checks passed
@ciampo ciampo deleted the fix/launch-site-split-agency-logic branch January 31, 2025 13:46
@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 Jan 31, 2025
paulopmt1 pushed a commit that referenced this pull request Feb 1, 2025
* Site settings: refactor agencyBillingMessage to prevent price formatting warnings

* Move undefined check inside createAgencyBillingMessage function

* Add price/currency check, refactor from ternary to early return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Site Settings All other general site settings.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants