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

Connection: Load connection JS bundle via connection PHP package #38877

Merged

Conversation

manzoorwanijk
Copy link
Member

@manzoorwanijk manzoorwanijk commented Aug 14, 2024

Extracted out of #38330

Problem

For publicize (Social), the JS code that gets bundled in Jetpack takes precedence over Social even if Social is the latest version. This is not the case with PHP packages, for which we always load the latest version regardless.

This mismatch of PHP and JS code often results in bugs.

Also, bundled JS code makes it difficult to fix a bug in Jetpack given the monthly release cycle. Thus, we decided to bundle the publicize JS code into publicize package to ensure that the latest version of the publicize JS code is loaded both in Jetpack and Social.

Now, to be able to externalize publicize, we also need to externalize connection js code to avoid it getting bundled into publicize code and fix some API call errors due to duplicate instances of connection bundle both in publicize bundle as well as in the plugins (Jetpack and Social)

Benefits

  • JS Code for connection will always be in sync with its PHP package, i.e. the latest version gets loaded.
  • Plugins will have smaller js bundles

Proposed changes:

  • Bundle connection JS code inside connection PHP package
  • Let connection PHP package handle the registration or script for the connection bundle
  • Externalize that connection bundle for all the plugins/packages
  • The connection bundle will now be available via window.JetpackConnection just like @wordpress/* packages are available via window.wp.*

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

pdrWKz-1Mq-p2

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

Testing instructions:

  • Run jetpack build packages/assets packages/connection plugins/jetpack
  • Just do a smoke test of the pages that rely on Jetpack connection

@manzoorwanijk manzoorwanijk added the [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. label Aug 14, 2024
@manzoorwanijk manzoorwanijk requested review from a team August 14, 2024 10:44
@manzoorwanijk manzoorwanijk self-assigned this Aug 14, 2024
@github-actions github-actions bot added [JS Package] Webpack Config [Package] Connection [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 [Tests] Includes Tests E2E Tests RNA labels Aug 14, 2024
Copy link
Contributor

github-actions bot commented Aug 14, 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.


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Choose a review path based on your changes:
    • A. Team Review: add the "[Status] Needs Team Review" label
      • For most changes, including minor cross-team impacts.
      • Example: Updating a team-specific component or a small change to a shared library.
    • B. Crew Review: add the "[Status] Needs Review" label
      • For significant changes to core functionality.
      • Example: Major updates to a shared library or complex features.
    • C. Both: Start with Team, then request Crew
      • For complex changes or when you need extra confidence.
      • Example: Refactor affecting multiple systems.
  3. Get at least one approval before merging.

Still unsure? Reach out in #jetpack-developers for guidance!


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.


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.

Copy link
Contributor

github-actions bot commented Aug 14, 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 update/load-connection-js-bundle-via-connection-package 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 update/load-connection-js-bundle-via-connection-package
    
    bin/jetpack-downloader test jetpack-mu-wpcom-plugin update/load-connection-js-bundle-via-connection-package
    

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

@github-actions github-actions bot added the [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ label Aug 14, 2024
@manzoorwanijk
Copy link
Member Author

I will fix up versions once this gets an approval to avoid noise in the PR.

Copy link
Contributor

@coder-karen coder-karen left a comment

Choose a reason for hiding this comment

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

👋 I gave this a spin, testing different scenarios related to connection. One thing I noticed was that both on disconnecting and connecting Jetpack, with this PR applied the related modals seemed to be missing styling. So it looks like the way CSS styles are applied may be affected in some way via this PR. Examples here:
Connection:
Screenshot 2024-08-19 at 10 53 01
Disconnection (bottom part of modal):
Screenshot 2024-08-19 at 10 56 46

@coder-karen coder-karen added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Aug 19, 2024
@manzoorwanijk
Copy link
Member Author

manzoorwanijk commented Aug 19, 2024

Thank you for giving this a test...

👋 I gave this a spin, testing different scenarios related to connection. One thing I noticed was that both on disconnecting and connecting Jetpack, with this PR applied the related modals seemed to be missing styling. So it looks like the way CSS styles are applied may be affected in some way via this PR.

Did you run jetpack build packages/connection plugins/jetpack before loading that page?

@manzoorwanijk manzoorwanijk added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Aug 19, 2024
@manzoorwanijk
Copy link
Member Author

👋 I gave this a spin, testing different scenarios related to connection. One thing I noticed was that both on disconnecting and connecting Jetpack, with this PR applied the related modals seemed to be missing styling. So it looks like the way CSS styles are applied may be affected in some way via this PR.

I have fixed the issue for connection screen. I assumed that all our scripts are registered via Automattic\Jetpack\Assets::register_script and enqueued via Automattic\Jetpack\Assets::enqueue_script which automatically takes care of loading the styles, but I noticed that it's not the case with admin page styles and thus had to explicitly add connection CSS as a dependency.

Co-authored-by: Brad Jorsch <[email protected]>
@anomiex
Copy link
Contributor

anomiex commented Sep 2, 2024

@coder-karen If the issues you found are fixed, I think this is good to go. Do you have time to check it again? Otherwise I'll try to test it.

@manzoorwanijk manzoorwanijk merged commit 33068b8 into trunk Sep 3, 2024
73 checks passed
@manzoorwanijk manzoorwanijk deleted the update/load-connection-js-bundle-via-connection-package branch September 3, 2024 04:30
@github-actions github-actions bot removed the [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. label Sep 3, 2024
gogdzl pushed a commit that referenced this pull request Oct 25, 2024
)

* Mark connection js package being external to extract it as a dependency

* Bundle connection js package inside php connection package

* Register connect bundle as a script handle for dependents to use

* Add changelog

* Fix E2E tests

* Fix more e2e tests

* Fix jetpack-admin css dependency because it does not use Assets::register_script

* Update webpack.config.js

Co-authored-by: Brad Jorsch <[email protected]>

---------

Co-authored-by: Brad Jorsch <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E2E Tests [JS Package] Webpack Config [Package] Connection [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [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 RNA [Tests] Includes Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants