fix: warn when Partial with append/prepend mode is missing key prop (#3738)

## Summary
- Adds a `console.warn` during SSR when a `<Partial>` uses
`mode="append"` or `mode="prepend"` without a `key` prop
- Without a key, Preact cannot correctly reconcile prepended/appended
children, leading to subtle rendering bugs
- No warning for `mode="replace"` (default) since keys aren't required
there

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Bartek Iwańczuk
2026-03-29 20:33:14 +02:00
committed by GitHub
co-authored by Claude Opus 4.6
parent 103427f9da
commit be467d3cdb
3 changed files with 108 additions and 4 deletions
+6 -4
View File
@@ -156,7 +156,7 @@ shops for example.
export default function AddToCartPartial() {
return (
<>
<Partial name="cart-items" mode="append">
<Partial name="cart-items" mode="append" key={newItem.id}>
{/* Render the new cart item here */}
</Partial>
<Partial name="total-price">
@@ -187,7 +187,7 @@ export default function LogView() {
const lines = getNewLogLines();
return (
<Partial name="logs-list" mode="append">
<Partial name="logs-list" mode="append" key={lines[0]}>
{lines.map((line) => {
return <li key={line}>{line}</li>;
})}
@@ -196,8 +196,10 @@ export default function LogView() {
}
```
> [info]: When picking the `prepend` or `append` mode, make sure to add keys to
> the elements.
> [warn]: When using `prepend` or `append` mode, you **must** add a `key` prop
> to the `<Partial>` component. Without it, Preact cannot distinguish new
> children from existing ones, leading to subtle rendering bugs. Fresh will log
> a warning if it detects a missing key on an append/prepend partial.
## Bypassing or disabling Partials