fix(filament): guard ProductForm status callouts against a null record - #2584
Open
ShamarKellman wants to merge 1 commit into
Open
fix(filament): guard ProductForm status callouts against a null record#2584ShamarKellman wants to merge 1 commit into
ShamarKellman wants to merge 1 commit into
Conversation
Mounting ProductForm without a record — as a resource Create page does — threw a TypeError on every load. The status-callout closures type-hinted a non-nullable `Model $record`, and the variant-attributes field a non-nullable `Product $record`, so Filament injecting a `null` record failed at the closure boundary before any of the existing null-safe `isDraft()`/`isPublished()` guards could run. Widen the closure parameters to `?Model` / `?Product`. The status callouts already short-circuit through the nullable `isPublished()`/`isDraft()` helpers, so only the two closures that dereference the record directly (`channels()` and `hasVariants`) gain an explicit null check. `hasEnabledCustomerGroup()` and `isDefaultGroupVisibleToGuests()` now accept a nullable record and guard internally, matching the existing `isPublished()`/`isDraft()`/`isArchived()` helpers. Behaviour is unchanged once a record exists. Adds a bridge-suite regression test that evaluates every status component inside a real schema container with a null record, plus a guard that the draft callout still tracks a persisted product's status.
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.
Problem
Mounting
Schemas\Product\ProductFormwithout a record — as any resource Create page does — throws aTypeErroron every load, before the form can render.The status-callout closures in
getStatusShouts()type-hint a non-nullableModel $record, andgetVariantAttributeDataComponent()a non-nullableProduct $record. Filament injects anullrecord on create, so evaluation fails at the closure boundary — the existing null-safeisDraft()/isPublished()helpers never get a chance to run.Reproduced on
2.x. A downstream panel that wiresProductForm::configure()onto a Create page hits this immediately (the bundledlunarphp/adminProductResource ships no standard Create page, which is why it hasn't surfaced there).Fix
?Model $recordand the variant closure to?Product $record.$record->channels()and$record->hasVariants— gain an explicit$record === null ||guard. The rest already short-circuit through the nullableisPublished()/isDraft()helpers, so no redundant null check is added.hasEnabledCustomerGroup()andisDefaultGroupVisibleToGuests()now accept?Modeland guard internally, matching the existingisPublished()/isDraft()/isArchived()helpers.Behaviour is unchanged once a record exists. No public method signatures change (widening a parameter type is contravariant / LSP-safe); README is untouched, CHANGELOG gets a bugfix entry.
Tests
New bridge-suite test
tests/filament/Unit/Schemas/Product/ProductFormTest.php:TypeErrorbefore this change, passes after.