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

JS Package: Add Critical CSS Gen #38429

Merged
merged 90 commits into from
Jul 31, 2024
Merged

Conversation

dilirity
Copy link
Member

@dilirity dilirity commented Jul 19, 2024

Fixes https://github.com/Automattic/boost-cloud/issues/267

Proposed changes:

  • Add critical css gen package to the monorepo:
    • Browser build is now in build-browser (was dist before);
    • Node build is now in build-node (was lib before);
  • Update browser version to not include playwright/puppeteer code;
  • Update node version to not include iframe code;
  • Update Boost to use the new package instead of the external repo. This will be done in a follow-up PR.

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

n/a

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

no

Testing instructions:

Pre-requisites

  • Go to the root of the js package;
  • Run pnpm install;
  • Build the package using pnpm build;
  • There should be no errors.

Testing with the Boost plugin

  • Apply the changes from this commit 3f586d8 (in reverse, the "removed" changes is what you need to add back to Boost);
  • Setup free Boost;
  • Install Boost dependencies using jetpack install plugins/boost;
  • Build Boost using jetpack build plugins/boost;
  • Try to generate critical css and make sure it's working.

@dilirity dilirity added [Status] Needs Team Review [Plugin] Boost A feature to speed up the site and improve performance. [Boost Feature] Critical CSS Issues involving the Critical CSS feature in Boost labels Jul 19, 2024
@dilirity dilirity requested a review from a team July 19, 2024 15:32
@dilirity dilirity self-assigned this Jul 19, 2024
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/js-package/critical-css-gen 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/js-package/critical-css-gen
    
    bin/jetpack-downloader test jetpack-mu-wpcom-plugin add/js-package/critical-css-gen
    

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

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.


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.

@pyronaur
Copy link
Member

2024_07_228rbFeqIX 30

Followed the instructions and got this:

@dilirity dilirity requested a review from anomiex July 26, 2024 16:58
projects/js-packages/critical-css-gen/.gitattributes Outdated Show resolved Hide resolved
@@ -0,0 +1,125 @@
import { BrowserContext, Page } from 'playwright-core';
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, it's not as bad as I thought since it's only importing types. Still, try this:

  1. Fix the .gitattributes as mentioned in the other comment.
  2. Download the build artifact from this PR, and unpack it to something like /tmp/jetpack-build.
    • Or, from a fresh checkout, do pnpm install && jetpack build --for-mirrors=/tmp/jetpack-build js-packages/critical-css-gen.
  3. Create package.json with these contents:
    {
      "dependencies": {
        "@automattic/jetpack-critical-css-gen": "file:/tmp/jetpack-build/Automattic/jetpack-critical-css-gen",
        "typescript": "^5.5.4"
      }
    }
  4. Create index.ts with these contents:
    import { generateCriticalCSS } from '@automattic/jetpack-critical-css-gen';
    
    console.log( 'The function is:', generateCriticalCSS );
  5. Run npm install && npm exec tsc index.ts.

You'll get an error like

../jetpack-build/Automattic/jetpack-critical-css-gen/lib/browser-interface-playwright.d.ts:1:38 - error TS2307: Cannot find module 'playwright-core' or its corresponding type declarations.

1 import { BrowserContext, Page } from 'playwright-core';
                                       ~~~~~~~~~~~~~~~~~


Found 1 error in ../jetpack-build/Automattic/jetpack-critical-css-gen/lib/browser-interface-playwright.d.ts:1

Unfortunately, it looks like using an optional (peer) dependency to account for this case is complicated.

  • Seems like the most straightforward way would be to have a separate entry point for BrowserInterfacePlaywright so people can do like import { BrowserInterfacePlaywright } from '@automattic/jetpack-critical-css-gen/playwright'; if they need it, rather than including it in the default entry point.
  • Second way would be to get tsc to include a // @ts-ignore comment before the import line when it outputs lib/browser-interface-playwright.d.ts. By default it seems to strip those, not sure how to best configure it not to.

dilirity and others added 3 commits July 29, 2024 09:55
Co-authored-by: Brad Jorsch <[email protected]>
We should release the package first then update Boost. That way
we can be sure that doing a new Boost release will not ship broken.
@dilirity dilirity marked this pull request as ready for review July 30, 2024 08:11
Copy link
Contributor

@haqadn haqadn left a comment

Choose a reason for hiding this comment

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

One small thing and I think it's ready to get merged.

projects/js-packages/critical-css-gen/package.json Outdated Show resolved Hide resolved
@dilirity dilirity requested a review from haqadn July 30, 2024 14:08
Copy link
Contributor

@haqadn haqadn left a comment

Choose a reason for hiding this comment

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

LGTM!

@dilirity dilirity merged commit 99baf6d into trunk Jul 31, 2024
72 checks passed
@dilirity dilirity deleted the add/js-package/critical-css-gen branch July 31, 2024 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Actions GitHub actions used to automate some of the work around releases and repository management [Boost Feature] Critical CSS Issues involving the Critical CSS feature in Boost Docs E2E Tests [JS Package] Critical Css Gen [Plugin] Boost A feature to speed up the site and improve performance. RNA [Tests] Includes Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants