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

Fix PHP-CSS-Parser patching #5082

Merged
merged 3 commits into from
Nov 4, 2020
Merged

Fix PHP-CSS-Parser patching #5082

merged 3 commits into from
Nov 4, 2020

Conversation

swissspidy
Copy link
Collaborator

Summary

Fixes broken CSS gradients.

Relevant Technical Choices

Originally, I simply wanted to use "enable-patching": true, but that doesn't work because of cweagans/composer-patches#315

(cc @westonruter maybe the Composer patches in the plugin could use patches from GitHub instead of locally provided ones?)

Then, I wanted to do "enable-patching": false and simply provide "patches": { ... } myself, but that didn't work - enable-patching is ignored when patches are provided.

So the correct way is to provide patches-ignore to ignore the AMP plugin's patches in favor of our own patches declaration.

Next, I learned that patches/php-css-parser-pull-185.patch cannot be applied for some reason (Could not apply patch! Skipping. The error was: Cannot apply patch patches/php-css-parser-pull-185.patch).

Since that patch doesn't seem critical for us, I simply removed it from the patches list.

Aside:

I wanted to use version 1.7 of the cweagans/composer-patches as it has a different structure and Composer 2 support, but the AMP plugin requires 1.6.x, so that doesn't work.

To-do

User-facing changes

Gradients are back!

Testing Instructions

  1. Apply gradient to element
  2. Notice that gradient no longer disappears on frontend.

Fixes #5081

@swissspidy swissspidy added Type: Bug Something isn't working Group: WordPress Changes related to WordPress or Gutenberg integration AMP Output Issues related to AMP output and validation Pod: WP & Infra labels Oct 30, 2020
@google-cla google-cla bot added the cla: yes label Oct 30, 2020
@github-actions
Copy link
Contributor

github-actions bot commented Oct 30, 2020

Size Change: 0 B

Total Size: 1.4 MB

ℹ️ View Unchanged
Filename Size Change
assets/css/edit-story.css 909 B 0 B
assets/css/stories-dashboard.css 939 B 0 B
assets/css/web-stories-embed-block.css 515 B 0 B
assets/js/chunk-fonts-********************.js 43.7 kB 0 B
assets/js/chunk-web-stories-template-0-********************.js 10.2 kB 0 B
assets/js/chunk-web-stories-template-1-********************.js 10.2 kB 0 B
assets/js/chunk-web-stories-template-2-********************.js 9.97 kB 0 B
assets/js/chunk-web-stories-template-3-********************.js 10.5 kB 0 B
assets/js/chunk-web-stories-template-4-********************.js 10.6 kB 0 B
assets/js/chunk-web-stories-template-5-********************.js 6.83 kB 0 B
assets/js/chunk-web-stories-template-6-********************.js 9.87 kB 0 B
assets/js/chunk-web-stories-template-7-********************.js 9.75 kB 0 B
assets/js/chunk-web-stories-textset-0-********************.js 5.25 kB 0 B
assets/js/chunk-web-stories-textset-1-********************.js 6.58 kB 0 B
assets/js/chunk-web-stories-textset-2-********************.js 7.83 kB 0 B
assets/js/chunk-web-stories-textset-3-********************.js 15.2 kB 0 B
assets/js/chunk-web-stories-textset-4-********************.js 4.38 kB 0 B
assets/js/chunk-web-stories-textset-5-********************.js 5.68 kB 0 B
assets/js/chunk-web-stories-textset-6-********************.js 5.47 kB 0 B
assets/js/chunk-web-stories-textset-7-********************.js 10.3 kB 0 B
assets/js/edit-story.js 528 kB 0 B
assets/js/stories-dashboard.js 594 kB 0 B
assets/js/web-stories-activation-notice.js 74.1 kB 0 B
assets/js/web-stories-embed-block.js 17.5 kB 0 B

compressed-size-action

@westonruter
Copy link
Collaborator

maybe the Composer patches in the plugin could use patches from GitHub instead of locally provided ones?

The reason for this I recall is to guard against a situation where the repo fork gets deleted or the branch is removed.

@swissspidy
Copy link
Collaborator Author

swissspidy commented Oct 30, 2020

maybe the Composer patches in the plugin could use patches from GitHub instead of locally provided ones?

The reason for this I recall is to guard against a situation where the repo fork gets deleted or the branch is removed.

Ah, interesting. Not sure about the fork-getting-deleted part, a URL like https://github.com/wp-media/wp-rocket/pull/3245.patch still works even though my branch does not exist anymore. And I bet it still works when I delete my fork.

@westonruter
Copy link
Collaborator

Is the thinking that using a remote patch file will facilitate keeping it updated?

cc @pierlon

@swissspidy
Copy link
Collaborator Author

Is the thinking that using a remote patch file will facilitate keeping it updated?

That, and it would help work around cweagans/composer-patches#315 because we'd no longer have to copy the patches from the amp-wp repo to this one.

@westonruter
Copy link
Collaborator

Got it. @pierlon What do you think about going back to using remote patches?

@pierlon
Copy link
Contributor

pierlon commented Oct 30, 2020

The patches currently employed by the amp-wp are from currently open PRs, so if we were to use remote patches there is a possibility of them being remotely updated if someone were to push to the relevant forked repo.

Alternatively, maybe we could create a PR on amp-wp with those patches and then use that as the remote patch. Thoughts @swissspidy @westonruter?

@westonruter
Copy link
Collaborator

Ah, interesting. Not sure about the fork-getting-deleted part, a URL like https://github.com/wp-media/wp-rocket/pull/3245.patch still works even though my branch does not exist anymore. And I bet it still works when I delete my fork.

@pierlon apparently the patch URLs persist even after the PR is closed and even when the fork is deleted, per Pascal above.

@pierlon
Copy link
Contributor

pierlon commented Oct 30, 2020

Right but it would be possible to push commits to the PR while it's open, thus updating the referenced remote patch. The example Pascal referred to (https://github.com/wp-media/wp-rocket/pull/3245.patch) would be an exception since the PR has already been merged.

@westonruter
Copy link
Collaborator

On one hand that is a good thing since it means it would be easy to update the patch (as in the case of a conflict). On the other hand, this means that the version is not explicitly indicated in the composer.json.

We could mitigate this by linking to the patch for a specific commit, rather than a PR. For example: https://github.com/wp-media/wp-rocket/commit/1b47bb97f9e7acdaaf8b66f44391fe2481a7293e.patch

For example, for your PR: MyIntervals/PHP-CSS-Parser#193. Instead of linking to https://github.com/sabberworm/PHP-CSS-Parser/pull/193.patch, we could instead link to: https://github.com/sabberworm/PHP-CSS-Parser/compare/d9d0190c2c29946aac93375ca05df2d48329d6d7%5E...0ff0e38629b5ba96ae3b8368385974b1ebee9acb.patch

This includes the same commits in your PR: MyIntervals/PHP-CSS-Parser@d9d0190c2c29946aac93375ca05df2d48329d6d7^...0ff0e38

So then if the PR gets updated, then we'd need to update the commit hashes in the composer.json.

@pierlon
Copy link
Contributor

pierlon commented Oct 30, 2020

Instead of linking to https://github.com/sabberworm/PHP-CSS-Parser/pull/193.patch, we could instead link to: https://github.com/sabberworm/PHP-CSS-Parser/compare/d9d0190c2c29946aac93375ca05df2d48329d6d7%5E...0ff0e38629b5ba96ae3b8368385974b1ebee9acb.patch

Hmm yea that makes sense. In that case I'm on board with using remote patches then.

@pierlon
Copy link
Contributor

pierlon commented Nov 2, 2020

@swissspidy cweagans/composer-patches will be updated to v1.7.0 in ampproject/amp-wp#5554 and I've opened a PR to switch to using patches from GitHub in ampproject/amp-wp#5556.

@swissspidy swissspidy force-pushed the fix/composer-patches branch from 10d526b to 40372fc Compare November 2, 2020 16:16
@codecov
Copy link

codecov bot commented Nov 2, 2020

Codecov Report

Merging #5082 into main will increase coverage by 0.81%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5082      +/-   ##
==========================================
+ Coverage   76.36%   77.17%   +0.81%     
==========================================
  Files         932      932              
  Lines       16485    16485              
==========================================
+ Hits        12589    12723     +134     
+ Misses       3896     3762     -134     
Flag Coverage Δ
karmatests 58.22% <ø> (+6.77%) ⬆️
unittests 65.66% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
assets/src/edit-story/elements/image/icon.js 0.00% <0.00%> (-100.00%) ⬇️
...sets/src/edit-story/elements/media/visibleImage.js 20.00% <0.00%> (-80.00%) ⬇️
assets/src/edit-story/utils/getMediaBaseColor.js 10.34% <0.00%> (-79.32%) ⬇️
...ets/src/edit-story/app/media/utils/preloadImage.js 11.11% <0.00%> (-77.78%) ⬇️
assets/src/edit-story/utils/useDoubleClick.js 8.00% <0.00%> (-72.00%) ⬇️
assets/src/edit-story/elements/media/frame.js 28.57% <0.00%> (-71.43%) ⬇️
assets/src/edit-story/elements/image/layer.js 33.33% <0.00%> (-66.67%) ⬇️
...story/components/panels/backgroundOverlay/panel.js 11.11% <0.00%> (-66.67%) ⬇️
...mponents/canvas/singleSelectionMoveable/useDrag.js 36.84% <0.00%> (-52.64%) ⬇️
assets/src/edit-story/elements/image/frame.js 50.00% <0.00%> (-50.00%) ⬇️
... and 63 more

@spacedmonkey
Copy link
Contributor

As ampproject/amp-wp#5556 has been merged, I think we are safe to merge.

I will approve after merge conflict is resolved.

@swissspidy
Copy link
Collaborator Author

@spacedmonkey conflicts resolved!

Copy link
Contributor

@spacedmonkey spacedmonkey left a comment

Choose a reason for hiding this comment

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

👍

@swissspidy swissspidy merged commit b604e4c into main Nov 4, 2020
@swissspidy swissspidy deleted the fix/composer-patches branch November 4, 2020 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AMP Output Issues related to AMP output and validation Group: WordPress Changes related to WordPress or Gutenberg integration Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AMP Sanitization breaks gradients (again)
4 participants