Library shows empty auto-created folders for categories whose Components are all disabled

Problem

After installing a site template, the Library sidebar lists folders that contain nothing: Announcements, Block, core, Dashboard, Drupal, Forms, … all showing 0.

library-sidebar

Component::postSave() auto-creates a folder for every new Component, regardless of status. ComponentSourceManager creates a Component for every block plugin, and computeInitialComponentStatus() returns FALSE for most of them — so each block category gets a folder whose members are all disabled.

The folders aren't empty in config, only in the UI: the Components list endpoint filters to enabled Components, the Folder list endpoint doesn't filter at all (Folder::refineListQuery() is a no-op). folderfyComponents() in ui/src/components/list/FolderList.tsx then re-adds every unpopulated folder, which is what renders them with a count of 0.

Site templates can't work around this: Folder uses its UUID as its ID (entity_keys: ['id' => 'uuid']), so the config name is canvas.folder.<random-uuid> generated at install time — unreachable by config actions. The only option today is a custom module with a hook_install() that deletes folders with no enabled items.

Steps to reproduce

  1. Install Drupal with Canvas and a theme providing SDCs.
  2. Open the Library sidebar → Components.
  3. Observe folders named after block plugin categories, each showing 0 items.

Proposed resolution

In folderfyComponents(), the second loop re-adds folders the first loop didn't populate:

if (folder.type === type && !folderComponents[id]) {

normalizeForClientSide() already sends items, so the two cases can be told apart:

if (folder.type === type && !folderComponents[id] && !folder.items?.length) {
  • items: [] → user-created, deliberately empty, still a drop target → keep showing.
  • items non-empty but all filtered out of the Components list → hide.

This would not need config changes or an update path and it fixes sites that already have these folders.

Follow-up (separate issue): make folder creation lazy — trigger it on a FALSE → TRUE status transition rather than on create. Needs a way to record that a Component was already auto-filed once (otherwise disable/enable pulls it back out of Uncategorized) and a \Drupal::isConfigSyncing() guard.

User interface changes

Folders whose Components are all disabled or filtered out no longer appear. Deliberately empty user-created folders are unaffected.