## Repeater Default Items When Using `fillForm()` in Filament

### The problem

When using a **Filament `CreateAction`** with `fillForm()`, the form is considered *already hydrated*.
Because of this, **Repeaters will NOT call `defaultItems()`**, even if you expect them to.

This becomes an issue when:

* You need a repeater to **always have at least one item**
* The form is prefilled (e.g. from a Mandate, Snapshot, or Draft payload)
* The repeater represents a required structure (like an Address)

In short:

> `fillForm()` bypasses `defaultItems()`.

---

### The workaround (the “afterStateHydrated hack”)

To solve this, we **manually inject a default repeater item** inside `afterStateHydrated()` **only if the repeater has no state**.

This recreates the behavior of `defaultItems()` while still allowing `fillForm()` to work.

---

### Why this works

* `afterStateHydrated()` runs **after Filament finishes hydrating the form**
* We can safely inspect the repeater’s state
* If the repeater has no value, we inject a single “empty” item
* Filament now treats the repeater as having data → UI renders correctly

---

### Example implementation

```php
Repeater::make($name)
    ->hiddenLabel()
    ->dehydrated()
    ->compact()
    ->deletable(false)
    ->minItems(1)
    ->maxItems(1)
    ->columns(5)
    ->columnSpanFull()
    ->afterStateHydrated(function (Get $get, Set $set) use ($name) {

        // If the repeater already has state, do nothing
        if ($get($name) !== null) {
            return;
        }

        // Inject a default item manually (can just use [])
        // This mimics defaultItems() when fillForm() is used
        $set($name, []);
    })
```

---

### When to use this pattern

Use this approach when **all of the following are true**:

* You are using `fillForm()` on a Create/Edit action
* The repeater must **always have at least one item**
* `defaultItems()` is not firing
* You need the UI to render a “blank but valid” repeater row

---

### Important notes

* This is intentional and safe — not a Filament bug
* `defaultItems()` only works when the form is *not* prefilled
* This pattern is especially useful for:

  * Addresses
  * Contact methods
  * Single-row repeaters
  * Snapshot-driven forms

---

### TL;DR

> **`fillForm()` disables `defaultItems()` on repeaters.
> Use `afterStateHydrated()` to manually inject a default item when state is empty.**