Skip to content

Only load block assets on frontend when block exists. - #226

Open
jamesmorrison wants to merge 14 commits into
developfrom
feature/199-tab-and-tab-items-block-assets
Open

jamesmorrison wants to merge 14 commits into
developfrom
feature/199-tab-and-tab-items-block-assets

Conversation

@jamesmorrison

Copy link
Copy Markdown
Member

Description of the Change

Adds conditional check that the block (Tabs / Tab Items) exist on the post before enqueueing assets.

Closes #199

How to test the Change

  1. Create a page with the Tabs / Tab Items blocks
  2. Verify these load on frontend without issue
  3. Create a separate page without the Tabs / Tab Items blocks
  4. Confirm the assets /dist/blocks/tabs-item-block.js and /dist/blocks/tabs-block.css are not enqueued

Changelog Entry

Fixed - Bug fix since 1.3.4 noted in #199

Credits

Props @jamesmorrison

Checklist:

@github-actions github-actions Bot added this to the Future Release milestone Aug 21, 2025
@github-actions github-actions Bot added the needs:code-review This requires code review. label Aug 21, 2025
@jamesmorrison

Copy link
Copy Markdown
Member Author

@dkotter / @jeffpaul Please could you review this PR?

@jeffpaul
jeffpaul requested a review from faisal-alvi August 21, 2025 14:26
@jeffpaul jeffpaul modified the milestones: Future Release, 1.4.0 Aug 21, 2025

@dkotter dkotter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Couple typos that were preventing this from working properly on the front-end.

Once addressed, this does work and may be good enough. I am curious though, looking at the original issue, why this ends up loading the block editor script at all on the front-end? Seems like there may be a bigger issue here with how this block is built/registered that may be worth changing to fix the problem here

jeffpaul and others added 2 commits September 8, 2025 15:04
Co-authored-by: Darin Kotter <darin.kotter@gmail.com>
Co-authored-by: Darin Kotter <darin.kotter@gmail.com>
@jeffpaul

jeffpaul commented Sep 8, 2025

Copy link
Copy Markdown
Member

I am curious though, looking at the original issue, why this ends up loading the block editor script at all on the front-end? Seems like there may be a bigger issue here with how this block is built/registered that may be worth changing to fix the problem here

@fabiankaegy any insights from your perspective on this?

@fabiankaegy

Copy link
Copy Markdown
Member

I am curious though, looking at the original issue, why this ends up loading the block editor script at all on the front-end? Seems like there may be a bigger issue here with how this block is built/registered that may be worth changing to fix the problem here

@fabiankaegy any insights from your perspective on this?

Yeah ideally we should enqueue the assets via the viewScript field in block.json.

@jamesmorrison

Copy link
Copy Markdown
Member Author

@jeffpaul / @dkotter / @fabiankaegy Sorry it's taken so long for me to make the requested changes here.

I've refactored this to use the viewScript; tested and working locally.

I chose to leave the frontend.js file in case it's needed, let me know if you'd like this removed.

Please could you review the updates here?

@jeffpaul
jeffpaul requested review from dkotter and fabiankaegy and removed request for faisal-alvi November 22, 2025 19:09
@jeffpaul
jeffpaul requested review from peterwilsoncc and removed request for jeffpaul January 13, 2026 20:20

@peterwilsoncc peterwilsoncc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good to me and is testing well. I've confirmed the tabs components' assets are enqueued only when the block is included in the mark up.

I've answered your question about frontend.js inline.

Note: for testing purposes I merged in the develop branch but I haven't pushed in case you have a preference for rebasing.

Comment thread assets/js/frontend/frontend.js Resolved
@nhrrob

nhrrob commented Jul 3, 2026

Copy link
Copy Markdown
Member

@peterwilsoncc

  • Deleted assets/js/frontend/frontend.js and its package.json entry, and removed the enqueue call
    wp_enqueue_script( 'publisher_media_kit_frontend', ... ) in core.php .

  • Also noting that, assets/js/shared/shared.js is in the same state frontend.js was — just a placeholder comment, but is unconditionally enqueued on every front-end and admin page via core.php.

  • The failed job - probably not related to our changes. Still not sure.

Screenshot 2026-07-03 at 5 05 34 PM

@nhrrob
nhrrob requested a review from peterwilsoncc July 3, 2026 11:21
@jeffpaul
jeffpaul requested a balanced review from Copilot November 3, 2026 14:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:code-review This requires code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tab and tab item blocks are loaded where they are not necessary

7 participants