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 issues with how assets are enqueued on the new SVG block #112

Merged
merged 3 commits into from
Mar 30, 2023

Conversation

dkotter
Copy link
Collaborator

@dkotter dkotter commented Mar 29, 2023

Description of the Change

A new SVG block was added in PR #80, which went out in the 2.1.0 release. We've gotten a handful of reports around how assets are being loaded for this block, most notably:

  • a CSS and JS file are loaded on all FE pages, even those without the block
  • the JS file is empty
  • an extra slash is in the CSS file URL

This PR fixes all of those issues by removing the JS file from being loaded at all and moving the CSS file from a typical enqueue to being loaded as part of the block.json. This ensures the CSS is only loaded on pages that are using the block and it loads the CSS inline instead of loading an extra stylesheet.

Also fix an incorrect use of add_filter to be add_action

Closes #109

How to test the Change

On the current released version (2.1.0) view any page on your site and note that two block related files (a CSS and JS file) are being loaded.

Checkout this branch and note those files are no longer loaded at all, even if a page has an SVG block. Verify the block itself still works and renders as expected.

Changelog Entry

Fixed - Only load our block CSS if a page has the SVG block in it and remove an extra slash in the CSS file path.. Remove an unneeded JS block file.

Credits

Props @dkotter, @freinbichler, @IanDelMar, @ocean90

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

@dkotter dkotter added this to the 2.1.1 milestone Mar 29, 2023
@dkotter dkotter requested a review from a team as a code owner March 29, 2023 16:59
@dkotter dkotter self-assigned this Mar 29, 2023
@dkotter dkotter requested review from Sidsector9 and faisal-alvi and removed request for a team March 29, 2023 16:59
Copy link
Member

@Sidsector9 Sidsector9 left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@Sidsector9 Sidsector9 merged commit 65e285e into develop Mar 30, 2023
@Sidsector9 Sidsector9 deleted the fix/block-issues branch March 30, 2023 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Safe-SVG v2.1.0 should not enqueue frontend stylesheet and JavaScript if Gutenberg block is not used
2 participants