Skip to content

Conversation

@kaeizen
Copy link
Contributor

@kaeizen kaeizen commented Aug 27, 2025

fixes #3581

Summary by CodeRabbit

  • Bug Fixes
    • Preserve existing block visibility settings when applying metadata, avoiding accidental overrides of inserter visibility.
  • Chores
    • Hide the Design Library block from the inserter by default so it cannot be added directly.

@coderabbitai
Copy link

coderabbitai bot commented Aug 27, 2025

Walkthrough

Design Library block settings now include supports.inserter = false, hiding it from the inserter. The disabled-blocks logic was adjusted to only set metadata.supports.inserter when it is currently undefined, preserving explicit values.

Changes

Cohort / File(s) Summary
Design Library settings
src/block/design-library/index.js
Added supports.inserter = false to the exported settings (comment: "Always hide design library from block inserter"). No other exported settings changed.
Disabled blocks guard
src/disabled-blocks.js
Changed unconditional assignment of metadata.supports.inserter to a guarded assignment: set only if metadata.supports.inserter is undefined, preserving existing values.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Editor as WP Editor
    participant DesignSettings as Design Library settings
    participant Disabled as disabled-blocks logic

    Editor->>DesignSettings: Load block metadata/settings
    DesignSettings-->>Editor: settings (includes supports.inserter = false)
    Editor->>Disabled: apply metadata normalization
    Disabled-->>Editor: leave inserter alone if already defined
    Editor->>Editor: Build inserter catalog
    Note right of Editor #dff0d8: Design Library block omitted from inserter
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks (4 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning Beyond hiding the Design Library block, the PR modifies the general metadata logic in src/disabled-blocks.js to conditionally assign metadata.supports.inserter, which was not specified in the linked issue and extends the scope beyond the singular goal of removing that block from the inserter. Please isolate the changes to disabled-blocks.js into a separate PR or update issue #3581 to explicitly include this metadata-preservation logic so that the scope of each change remains clear and focused.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title “fix (design library): remove from inserter” clearly and concisely summarizes the primary change of hiding the Design Library block from the inserter, aligns with conventional commit formatting, and avoids extraneous details or noise.
Linked Issues Check ✅ Passed The PR directly implements the objective of issue #3581 by adding inserter: false to the Design Library block’s settings to remove it from the block inserter, and the supplementary change in disabled-blocks.js ensures that this flag is preserved rather than overwritten, fully satisfying the linked issue’s requirement.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Poem

I nibble code beneath the sun,
Tucked a block where it’s quietly done—
Gone from the picker, hidden with cheer,
A hop, a wink, the canvas clear. 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/3581-remove-design-library-from-block-inserter

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 Aug 27, 2025

🤖 Pull request artifacts

file commit
pr3587-stackable-3587-merge.zip 77171b1

github-actions bot added a commit that referenced this pull request Aug 27, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/block/design-library/index.js (1)

39-48: Add a nullish guard when spreading supports.

Minor hardening to avoid a TypeError if settings.supports is missing in some integration path.

 addFilter( `stackable.design-library.settings`, `stackable/design-library/inserter`, settings => {
   return {
     ...settings,
     supports: {
-      ...settings.supports,
+      ...( settings?.supports ?? {} ),
       inserter: false,
     },
   }
 } )

Optional: If you want a static, zero-runtime alternative, set inserter: false in block.json (supports.inserter) instead of using a filter. (developer.wordpress.org)

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 60e5ed7 and 5f82cb1.

📒 Files selected for processing (1)
  • src/block/design-library/index.js (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: PHP 8.2 and WP 6.6.2
  • GitHub Check: PHP 8.2 and WP 6.5.5
  • GitHub Check: PHP 8.2 and WP 6.7.2
  • GitHub Check: PHP 7.3 and WP latest
  • GitHub Check: PHP 8.2 and WP latest
  • GitHub Check: PHP 7.3 and WP 6.5.5
🔇 Additional comments (2)
src/block/design-library/index.js (2)

39-48: This correctly hides the block from the Inserter (and related UIs).

Setting supports.inserter to false is the documented way to hide a block from the Inserter, transforms menu, and Style Book. (developer.wordpress.org)


39-48: Filter Application Not Found – Manual Verification Required

I couldn’t locate any applyFilters('stackable.design-library.settings', …) invocation in the registration path, nor any registerBlockType( … 'design-library' ) calls that consume this filter. Without an applyFilters call running after this module loads, the filter you’ve added will never take effect. Please:

  • Confirm where and when your block registration for the design library occurs.
  • Add an applyFilters('stackable.design-library.settings', settings) wrapper around the registration settings in that code path, ensuring this module is imported beforehand.

Comment on lines 16 to 17
import { addFilter } from '@wordpress/hooks'

Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Importing addFilter is appropriate; please confirm bundling/external mapping.

Looks good. Verify that @wordpress/hooks is either listed as a dependency or mapped as wp.hooks in your bundler to avoid runtime resolution issues.


🏁 Script executed:

#!/bin/bash
# Ensure @wordpress/hooks is available via deps or externals.

echo "Checking package.json for @wordpress/hooks…"
fd -a package.json | xargs -I{} jq -r '
  .dependencies["@wordpress/hooks"] // empty,
  .devDependencies["@wordpress/hooks"] // empty
' {} 2>/dev/null | sed '/^$/d' || true

echo -e "\nSearching build config for externals mapping to wp.hooks…"
rg -nP -C2 'externals|wp\.hooks|@wordpress/hooks' --type js --type ts --type tsx

Length of output: 504


🏁 Script executed:

#!/bin/bash
# Search the entire repository (all file types) for externals mapping to wp.hooks or @wordpress/hooks
echo "Scanning for externals declarations related to @wordpress/hooks or wp.hooks…"
rg -nC2 'externals|wp\.hooks|@wordpress/hooks' .

Length of output: 147287


🏁 Script executed:

#!/bin/bash
# Check if @wordpress/scripts is used for bundling
echo "Checking for @wordpress/scripts in dependencies/devDependencies…"
jq -r '
  .dependencies["@wordpress/scripts"] // "not found",
  .devDependencies["@wordpress/scripts"] // "not found"
' package.json

# Show package.json scripts to see build commands
echo -e "\npackage.json scripts:"
jq '.scripts' package.json

# Look for common bundler configuration files
echo -e "\nSearching for bundler config files…"
fd webpack.config.js || echo "No webpack.config.js found"
fd rollup.config.js || echo "No rollup.config.js found"
fd vite.config.js || echo "No vite.config.js found"

Length of output: 3480


🏁 Script executed:

#!/bin/bash
# Scan webpack configuration files for externals mapping of @wordpress/hooks → wp.hooks
echo "Scanning .config directory for externals mappings…"
rg -nP 'externals\s*:' -C3 .config

Length of output: 851


🏁 Script executed:

#!/bin/bash
# List the first 50 entries under .config to locate externals definitions
echo "Listing .config directory recursively (top 50 entries)…"
find .config -maxdepth 2 -type f | head -n 50

echo -e "\nSearching for 'externals =' definitions in .config files…"
rg -nP 'externals\s*=' -C3 .config

echo -e "\nSearching for 'stackableExternals' definitions in .config files…"
rg -nP 'stackableExternals' -C3 .config

Length of output: 2952


🏁 Script executed:

#!/bin/bash
# Search for mapping of @wordpress/hooks in externals.js
echo "Inspecting externals.js for @wordpress/hooks mapping…"
rg -nC3 "@wordpress/hooks" .config/externals.js || echo "No direct mapping found"

Length of output: 221


Add externals mapping for @wordpress/hooks

We’ve confirmed that

  • @wordpress/hooks is declared in package.json dependencies (version ^3.2.2).
  • Both webpack configs in .config/webpack.config.dev.js and .config/webpack.config.prod.js spread in the shared externals object from .config/externals.js.

However, there’s currently no entry for @wordpress/hooks in .config/externals.js, so imports like

import { addFilter } from '@wordpress/hooks'

will be bundled rather than resolved against the global wp.hooks at runtime.

Please update .config/externals.js by adding a mapping for the Hooks package, for example:

const externals = {
  // existing mappings…
  '@wordpress/hooks': [ 'wp', 'hooks' ],
  wp:           'wp',
  lodash:       'lodash',
  stackable:    'stackable',
  // …
};

Because both dev and prod webpack configs use:

externals: {
  ...externals,
  ...stackableExternals,
},

this change will ensure addFilter/applyFilters etc. resolve to window.wp.hooks.

🤖 Prompt for AI Agents
In src/block/design-library/index.js around lines 16 to 17: imports from
"@wordpress/hooks" are currently being bundled because .config/externals.js
lacks a mapping for that package; update .config/externals.js to add an
externals entry mapping '@wordpress/hooks' to the global wp.hooks (e.g. add a
key '@wordpress/hooks' with value ['wp','hooks'] alongside the existing
wp/lodash/stackable mappings) so both dev and prod webpack configs that spread
the shared externals will resolve addFilter/applyFilters against window.wp.hooks
at runtime.

Copy link
Contributor

@bfintal bfintal left a comment

Choose a reason for hiding this comment

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

We can just set inserter to false from the json

github-actions bot added a commit that referenced this pull request Sep 10, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/disabled-blocks.js (1)

53-55: Fix operator-precedence bug: ! binds before ===, making inserter always false

The current expressions negate the value before comparison, effectively returning false in typical cases. Compare directly against BLOCK_STATE.HIDDEN.

Apply:

-    inserter = ! disabledBlocks[ metadata.name ] === BLOCK_STATE.HIDDEN
+    inserter = disabledBlocks[ metadata.name ] !== BLOCK_STATE.HIDDEN
-    inserter = ! disabledBlocks[ metadata[ 'stk-block-dependency' ] ] === BLOCK_STATE.HIDDEN
+    inserter = disabledBlocks[ metadata[ 'stk-block-dependency' ] ] !== BLOCK_STATE.HIDDEN

Also applies to: 58-60

♻️ Duplicate comments (1)
src/disabled-blocks.js (1)

6-6: Ensure externals mapping for @wordpress/hooks (wp.hooks) exists

Import relies on bundler externals. Verify .config/externals.js maps @wordpress/hooks['wp','hooks']. See prior review thread.

🧹 Nitpick comments (3)
src/disabled-blocks.js (1)

95-103: Confirm precedence: should user-hidden blocks override explicit supports.inserter?

With this guard, blocks that set supports.inserter: true won’t be hidden by user settings. If user-config should win, consider overriding unless supports.inserter === false.

Potential approach:

- if ( typeof metadata.supports.inserter === 'undefined' ) {
-   metadata.supports.inserter = inserter
- }
+ if ( metadata.supports.inserter === false ) {
+   // honor explicit false
+} else {
+  metadata.supports.inserter = inserter
+}
src/block/design-library/index.js (2)

25-28: Don’t overwrite metadata.supports; merge it

Preserve any supports defined in block.json.

Apply:

-  supports: {
-    stkSaveBlockStyle: false,
-    inserter: false, // Always hide design library from block inserter
-  },
+  supports: {
+    ...( metadata.supports || {} ),
+    stkSaveBlockStyle: false,
+    inserter: false, // Always hide design library from block inserter
+  },

16-36: Add a quick UI test to prevent regressions

Verify the block is absent from: (a) block inserter, (b) slash inserter. Also ensure existing content with the block remains editable.

I can draft a minimal Playwright/E2E spec asserting both inserters exclude this block—want me to add it?

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5f82cb1 and 77171b1.

📒 Files selected for processing (2)
  • src/block/design-library/index.js (1 hunks)
  • src/disabled-blocks.js (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: PHP 8.2 and WP latest
  • GitHub Check: PHP 8.2 and WP 6.7.2
  • GitHub Check: PHP 8.2 and WP 6.5.5
  • GitHub Check: PHP 8.2 and WP 6.6.2
  • GitHub Check: PHP 7.3 and WP latest
  • GitHub Check: PHP 7.3 and WP 6.5.5
  • GitHub Check: build
🔇 Additional comments (2)
src/disabled-blocks.js (1)

101-103: Guarded assignment preserves explicit block settings — LGTM

Only setting supports.inserter when undefined avoids clobbering block-defined intent.

src/block/design-library/index.js (1)

27-27: Hide from inserter via supports.inserter: false — LGTM

This aligns with the objective to remove the Design Library from the inserter.

@bfintal bfintal merged commit 68dbbc3 into develop Sep 16, 2025
8 of 9 checks passed
@bfintal bfintal deleted the fix/3581-remove-design-library-from-block-inserter branch September 16, 2025 03:35
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.

Remove design library block

3 participants