Skip to content

fix: avoid conflict in the enqueing script with conditional display#3689

Open
Arukuen wants to merge 1 commit intodevelopfrom
fix/3688-conditional-display
Open

fix: avoid conflict in the enqueing script with conditional display#3689
Arukuen wants to merge 1 commit intodevelopfrom
fix/3688-conditional-display

Conversation

@Arukuen
Copy link
Contributor

@Arukuen Arukuen commented Mar 5, 2026

fixes #3688

Issue: When the first carousel (or any other block with frontend script) in the post is removed using Conditional Display, its frontend script will not be enqueued.

The conditional display feature removes the block content of the blocks to avoid rendering the block. If there's no block content for that block, the wp_enqueue_script does not proceed (tested). However, the $scripts_loaded tracker, prior to this PR, attempts to enqueue the script, fails silently, but still records that the script is loaded. This will omit the succeeding attempts to enqueue the script, even though they are valid with proper block content.

This PR makes the Conditional Display run first to avoid race condition (in the premium PR), and check for empty block content before enqueueing the script since it might be removed with Conditional Display .

Summary by CodeRabbit

  • Bug Fixes
    • Fixed script enqueuing behavior to prevent loading block scripts when block content is not displayed or conditionally hidden, improving overall performance.

@coderabbitai
Copy link

coderabbitai bot commented Mar 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b4a6320f-8b70-4e12-96e4-c348525cd160

📥 Commits

Reviewing files that changed from the base of the PR and between 783643d and 7af77d5.

📒 Files selected for processing (1)
  • src/init.php

📝 Walkthrough

Walkthrough

Modified the block script enqueue logic in src/init.php to check if block content is non-empty before enqueueing scripts. This prevents unnecessary script loading when blocks are hidden by display conditions.

Changes

Cohort / File(s) Summary
Block Script Enqueue Logic
src/init.php
Added condition to prevent block script enqueuing when block content is empty, ensuring scripts only load for visible block instances.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A carousel that prances with delight,
Now dances only when it's in the light,
Display conditions no longer confound,
The scripts load wisely, safe and sound! 🎠

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main change: preventing script enqueue conflicts caused by conditional display removing block content, which is the core issue fixed in this PR.
Linked Issues check ✅ Passed The code change ensures carousel scripts are enqueued only when block content remains after conditional display processing, directly addressing the root cause in #3688.
Out of Scope Changes check ✅ Passed All changes in src/init.php are directly related to fixing the conditional display script enqueue issue described in #3688, with no extraneous modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/3688-conditional-display

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

github-actions bot commented Mar 5, 2026

🤖 Pull request artifacts

file commit
pr3689-stackable-3689-merge.zip 7af77d5

github-actions bot added a commit that referenced this pull request Mar 5, 2026
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.

Carousel Block - carousel does not work with display conditions enabled

1 participant