Skip to content

Add deferred badge loading for relation manager tabs#19464

Open
buzkall wants to merge 1 commit intofilamentphp:4.xfrom
buzkall:feat/defer-badge-relation-managers
Open

Add deferred badge loading for relation manager tabs#19464
buzkall wants to merge 1 commit intofilamentphp:4.xfrom
buzkall:feat/defer-badge-relation-managers

Conversation

@buzkall
Copy link
Contributor

@buzkall buzkall commented Mar 9, 2026

Description

Extends the deferred tab badge loading introduced in #19336 to relation manager tabs.

Problem: RelationManager::getTabComponent() evaluates getBadge() synchronously, and the Tabs component built by HasRelationManagers has no key — both of which prevent deferBadge() from working.

Solution:

  • Add protected static bool $deferBadge = false to RelationManager (overrideable via isBadgeDeferred() for dynamic, per-record control)
  • Add fluent ->deferBadge() to RelationGroup
  • Add ->key('relationManagerTabs') to the Tabs built in HasRelationManagers

Consumer usage

class TicketsRelationManager extends RelationManager
{
    protected static bool $deferBadge = true;

    public static function getBadge(Model $ownerRecord, string $pageClass): ?string
    {
        $count = $ownerRecord->tickets()->count();

        return $count > 0 ? (string) $count : null;
    }
}

No need to override getTabComponent() or the Edit page class.

Checklist

  • Code style has been fixed by running the composer cs command.
  • Changes have been tested — all 56 existing tests pass, 3 new tests added.
  • Documentation is up-to-date.

Extends the deferred tab badge loading introduced in PR filamentphp#19336 to
relation manager tabs, fixing two upstream issues:

1. `RelationManager::getTabComponent()` was evaluating `getBadge()`
   eagerly before the deferred mechanism could intercept it.
2. `HasRelationManagers::getRelationManagersContentComponent()` built
   `Tabs::make()` with no key, causing `callSchemaComponentMethod()` to
   receive null when the async badge fetch fired.

Changes:
- Add `protected static bool $deferBadge = false` to `RelationManager`
  with an overrideable `isBadgeDeferred()` method for per-record control
- Add fluent `->deferBadge()` and `isBadgeDeferred()` to `RelationGroup`
- Add `->key('relationManagerTabs')` to the `Tabs` built in
  `HasRelationManagers`
- Add docs and tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-project-automation github-project-automation bot moved this to Todo in Roadmap Mar 9, 2026
@danharrin danharrin added enhancement New feature or request pending review labels Mar 10, 2026
@danharrin danharrin added this to the v4 milestone Mar 10, 2026
@subIT1
Copy link

subIT1 commented Mar 16, 2026

Wouldn't it make sence to add a defer option in addition to all badges. So TextColumns, NavigationBadge, TextEntry...

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

Labels

enhancement New feature or request pending review

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants