fix: prevent duplicate resource table() invocation in InteractsWithCustomFields [3.x]#140
Merged
ManukMinasyan merged 1 commit into3.xfrom Apr 21, 2026
Conversation
…stomFields
Filament's ListRecords::makeTable() already applies the resource's table()
configuration via configureTable(). The trait then re-invoked
static::getResource()::table($table), causing every modifyQueryUsing,
filter, column, and action to be registered twice. Since Filament does
not deduplicate queryScopes, a resource scope like withExists/withSum or
whereNull('parent_id') resulted in duplicated subqueries and WHERE
clauses, roughly doubling list-page query cost.
The trait now returns the already-configured table unchanged before
layering custom-field columns, filters, and the customFieldValues eager
load on top.
Reported by Kenneth Sese.
There was a problem hiding this comment.
Pull request overview
Fixes a performance regression where InteractsWithCustomFields::table() re-invoked the resource’s table() configuration, causing Filament query scopes (and other table configuration) to be applied twice on List pages.
Changes:
- Remove the redundant
static::getResource()::table($table)invocation fromInteractsWithCustomFields. - Add a regression test asserting the resource
table()method is called exactly once when the concern is used. - Add a call counter on the
PostResourcefixture to support the regression test.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Concerns/InteractsWithCustomFields.php | Stops double-applying the resource table configuration; now only layers custom-field columns/filters and eager-loading onto the already-configured table. |
| tests/Fixtures/Resources/Posts/PostResource.php | Adds a static counter incremented by table() to detect duplicate invocations during tests. |
| tests/Feature/Integration/Resources/Pages/ListRecordsTest.php | Adds a regression test to ensure the resource table() is invoked only once when InteractsWithCustomFields is present. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
InteractsWithCustomFields::table()invoked the resource'stable()method a second time after Filament'sListRecords::makeTable()had already applied it viaconfigureTable(). Because Filament does not deduplicatequeryScopes, everymodifyQueryUsingclosure registered in the resource ran twice — duplicatingwithExists,withSum,whereNull, and similar clauses in the generated SQL and roughly doubling list-page query cost. Filters, columns, and actions were also registered twice (though idempotent by name, so no visible UI duplication).Root cause
Filament/Resources/Pages/ListRecords.php—makeTable()callsstatic::getResource()::configureTable($table).Filament/Resources/Resource.php—configureTable()invokesstatic::table($table)on the resource.Filament/Tables/Concerns/InteractsWithTable.php— Livewire then calls$this->table($this->makeTable()), which resolves to the trait.static::getResource()::table($table)a second time, re-running every resource-defined scope.Filament/Tables/Table/Concerns/HasQuery.php—modifyQueryUsingappends toqueryScopeswithout deduplication.For
RelationManager, the oldtry/catchfell through toparent::table($table)(a no-op), so relation managers are unaffected by the change.Change
Remove the redundant
static::getResource()::table($table)call. The$tableargument already carries the resource's configuration when the trait receives it, so the trait now layers the custom-field columns, filters, andcustomFieldValueseager load on top of the already-configured table.Test plan
it invokes resource table() only once when InteractsWithCustomFields is used— asserts the resource'stable()method is called exactly once.3.xbefore this change (count is 2) and passes after.ListRecordsTestPest run introduces no new failures (2 pre-existing$logoview failures unrelated to this fix remain unchanged).Credit
Reported by Kenneth Sese with precise diagnosis and reproducer.