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

Consolidate Jetpack initial state #38430

Merged
merged 48 commits into from
Aug 7, 2024
Merged

Conversation

manzoorwanijk
Copy link
Member

@manzoorwanijk manzoorwanijk commented Jul 19, 2024

This is the first attempt to consolidate initial state in Jetpack - pdWQjU-KI-p2

#38606 serves as the basic working example of the usage of the initial state (script data) added in this PR.

Proposed changes:

  • Introduce a js package named script-data which provides some basic JS utility functions. Suggestions are welcome.
  • Expose that script-data package via packages/assets, i.e. assets package will contain the build output from script-data js package.
  • Make the script data filterable via hooks
  • Any package/plugin intending to use the script-data can either import the package in its JS code or explicitly specify jetpack-script-data as a dependency to its JS script handle when registering/enqueueing it.

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

pdWQjU-KI-p2

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

Testing instructions:

This PR does not change anything, for any package/plugin. It just adds the support for initial state which can be used in subsequent PR. As mentioned above, #38606 serves as the basic working example of the usage of this PR.

  • Just do a smoke test of Jetpack and Social pages and the post editor.

Copy link
Contributor

github-actions bot commented Jul 19, 2024

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 Team 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 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team Review" label and ask someone from your team review the code. Once reviewed, it can then be merged.
If you need an extra review from someone familiar with the codebase, you can update the labels from "[Status] Needs Team Review" to "[Status] Needs Review", and in that case Jetpack Approvers will do a final review of your PR.


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen daily.
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly. The next release is scheduled for none scheduled (scheduled code freeze on undefined).

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Backup plugin:

  • Next scheduled release: none scheduled.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Boost plugin:

  • Next scheduled release: none scheduled.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Search plugin:

  • Next scheduled release: none scheduled.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Social plugin:

  • Next scheduled release: none scheduled.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Starter Plugin plugin:

  • Next scheduled release: none scheduled.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Protect plugin:

  • Next scheduled release: August 12, 2024.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Videopress plugin:

  • Next scheduled release: none scheduled.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Migration plugin:

  • Next scheduled release: none scheduled.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Mu Wpcom plugin:

  • Next scheduled release: WordPress.com Simple releases happen daily.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Inspect plugin:

  • Next scheduled release: none scheduled.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Wpcomsh plugin:

  • Next scheduled release: on demand (usually Mondays if not sooner).

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Automattic For agencies client plugin:

  • Next scheduled release: none scheduled.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Classic Theme helper plugin plugin:

  • Next scheduled release: none scheduled.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

Copy link
Contributor

github-actions bot commented Jul 19, 2024

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 WordPress.com Simple 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, and enable the add/consolidate-initial-state branch.

    • For jetpack-mu-wpcom changes, also add define( 'JETPACK_MU_WPCOM_LOAD_VIA_BETA_PLUGIN', true ); to your wp-config.php file.
  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack add/consolidate-initial-state
    
    bin/jetpack-downloader test jetpack-mu-wpcom-plugin add/consolidate-initial-state
    

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

@manzoorwanijk manzoorwanijk force-pushed the add/consolidate-initial-state branch from d8f5928 to 18026f2 Compare July 22, 2024 07:08
projects/packages/assets/src/class-initial-state.php Outdated Show resolved Hide resolved
projects/packages/assets/src/class-initial-state.php Outdated Show resolved Hide resolved
projects/packages/assets/src/class-initial-state.php Outdated Show resolved Hide resolved
projects/packages/assets/src/class-initial-state.php Outdated Show resolved Hide resolved
projects/packages/assets/src/class-initial-state.php Outdated Show resolved Hide resolved
projects/packages/assets/src/class-initial-state.php Outdated Show resolved Hide resolved
projects/packages/assets/src/class-initial-state.php Outdated Show resolved Hide resolved

wp_add_inline_script(
self::SCRIPT_HANDLE,
sprintf( 'var JETPACK_INITIAL_STATE = %s;', $initial_state ),
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder what the merits are of setting this global versus setting a property on the window.JetpackInitialState object.

Copy link
Member Author

@manzoorwanijk manzoorwanijk Jul 22, 2024

Choose a reason for hiding this comment

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

I am not sure which is better:

One benefit of window.JetpackInitialState is that it can be check in if() condition but it can also be deleted.

Copy link
Member

Choose a reason for hiding this comment

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

Since we're already using window.JetpackInitialState in both types and utils, can we use it here as well? I don't think there's a downside to it, is there?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just wanted to mention that a huge benefit of using window.JetpackInitialState has been that I can directly type JetpackInitialState in the console on simple sites where the editor parts are rendered in iframes and the variable is still attached to the window. Otherise, for the variables declared with var, I had to search the DOM to find the data being rendered inside iframes because it would not be globally available.

Thanks.

@manzoorwanijk manzoorwanijk force-pushed the add/consolidate-initial-state branch from d34ff98 to bb90514 Compare July 22, 2024 17:43
@manzoorwanijk manzoorwanijk requested a review from anomiex July 22, 2024 18:04
Copy link
Contributor

@anomiex anomiex left a comment

Choose a reason for hiding this comment

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

I'm going to ask Vulcan to finish up the review on this, since they know a lot more about how Connection and such works than I do.

projects/js-packages/initial-state/.eslintrc.js Outdated Show resolved Hide resolved
@anomiex anomiex requested a review from a team July 22, 2024 18:12
@manzoorwanijk
Copy link
Member Author

manzoorwanijk commented Jul 22, 2024

@anomiex any idea why the build for packages/assets fails in CI for not recognizing TS syntax?

It works fine locally.

@manzoorwanijk manzoorwanijk requested a review from zinigor August 1, 2024 12:35
@manzoorwanijk manzoorwanijk dismissed zinigor’s stale review August 1, 2024 12:38

Changes addressed

zinigor
zinigor previously approved these changes Aug 1, 2024
@manzoorwanijk manzoorwanijk enabled auto-merge (squash) August 6, 2024 11:55
Copy link
Member

@zinigor zinigor left a comment

Choose a reason for hiding this comment

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

Looks good!

@manzoorwanijk manzoorwanijk merged commit cd8884a into trunk Aug 7, 2024
72 checks passed
@manzoorwanijk manzoorwanijk deleted the add/consolidate-initial-state branch August 7, 2024 13:32
@github-actions github-actions bot removed the [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. label Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs [JS Package] Script Data [JS Package] Webpack Config [Package] Assets [Plugin] Automattic For Agencies Client [Plugin] Backup A plugin that allows users to save every change and get back online quickly with one-click restores. [Plugin] Boost A feature to speed up the site and improve performance. [Plugin] Classic Theme Helper Plugin [Plugin] CRM Issues about the Jetpack CRM plugin [Plugin] Inspect [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Migration [Plugin] mu wpcom jetpack-mu-wpcom plugin [Plugin] Protect A plugin with features to protect a site: brute force protection, security scanning, and a WAF. [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster. [Plugin] Social Issues about the Jetpack Social plugin [Plugin] Starter Plugin [Plugin] VideoPress A standalone plugin to add high-quality VideoPress videos to your site. [Plugin] Wpcomsh RNA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants