Skip to content

Date-formatters: do not import @wordpress/date #47812

Open
alshakero wants to merge 10 commits intotrunkfrom
fix/data-formatters
Open

Date-formatters: do not import @wordpress/date #47812
alshakero wants to merge 10 commits intotrunkfrom
fix/data-formatters

Conversation

@alshakero
Copy link
Copy Markdown
Member

@alshakero alshakero commented Mar 27, 2026

Fixes DOTCOM-16527

Proposed changes

number-formatters imported @wordpress/date which imports moment entirely. But number-formatters only needs the settings from @wordpress/date which are available as a global anyway. This change makes it so we access the settings directly without dragging all the JS dependencies of @wordpress/date just to get the locale. This saves us 75KB minified and gzipped.

Other information

  • Generate changelog entries for this PR (using AI).

Related product discussion/links

https://linear.app/a8c/project/mobile-nux-performance-improvements-386901dd9438/overview

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

No.

Testing instructions

I'm not sure how to test this library, but you can test the change by going to the editor /wp-admin/post-new.php, opening DevTools > Console, and running window.wp?.date?.getSettings?.()?.l10n?.locale.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 27, 2026

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 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!

@github-actions github-actions bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Mar 27, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 27, 2026

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/data-formatters branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/data-formatters
bin/jetpack-downloader test jetpack-mu-wpcom-plugin fix/data-formatters

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

@alshakero alshakero requested a review from chriskmnds March 27, 2026 10:48
@alshakero alshakero added the [Status] Needs Review This PR is ready for review. label Mar 27, 2026
@alshakero alshakero changed the title Date-formatters: do not import moment.js Date-formatters: do not import @wordpress/data Mar 27, 2026
@jp-launch-control
Copy link
Copy Markdown

jp-launch-control bot commented Mar 27, 2026

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

@anomiex
Copy link
Copy Markdown
Contributor

anomiex commented Mar 27, 2026

Note that, with the previous method of including @wordpress/date, any bundle using this code would get wp-date included in its .asset.php file, so the WP locale would always be available if set in WordPress.

With this change, wp-date will not be included (unless something else in the bundle requires @wordpress/date), so the WP locale may or may not be available even if it's set in WordPress. Your code does properly avoid throwing an error by liberally using the ?. operator, but you should be clear that the fallback to the browser locale may be used more often as that may be unexpected.

@anomiex anomiex changed the title Date-formatters: do not import @wordpress/data Date-formatters: do not import @wordpress/date Mar 27, 2026
@alshakero
Copy link
Copy Markdown
Member Author

Note that, with the previous method of including @wordpress/date, any bundle using this code would get wp-date included in its .asset.php file, so the WP locale would always be available if set in WordPress.

Wow that's a great observation. I'll check if I can make @wordpress/date better.

@anomiex
Copy link
Copy Markdown
Contributor

anomiex commented Mar 27, 2026

Some of the documentation at https://momentjs.com/docs/#/-project-status/ may help. 😉

@alshakero
Copy link
Copy Markdown
Member Author

alshakero commented Mar 27, 2026

@anomiex I sent a PR to GB here, but it seems like this will take a long time to be usable as a package, at least two weeks until GB is released.

WDYT about this?

@alshakero alshakero force-pushed the fix/data-formatters branch from 34dfb1a to 097a19d Compare March 27, 2026 14:33
@anomiex
Copy link
Copy Markdown
Contributor

anomiex commented Mar 27, 2026

WDYT about this?

Hacky. It should work though.

Copy link
Copy Markdown
Contributor

@rcrdortiz rcrdortiz left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for these changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[JS Package] Number Formatters RNA [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Status] Needs Review This PR is ready for review. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants