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:
co-authored by
Claude Opus 4.6
parent
103427f9da
commit
be467d3cdb
@@ -194,6 +194,19 @@ options[OptionsType.DIFF] = (vnode) => {
|
||||
`<Partial> components cannot be used inside islands.`,
|
||||
);
|
||||
}
|
||||
|
||||
const mode = (vnode.props as PartialProps).mode;
|
||||
if (
|
||||
(mode === "append" || mode === "prepend") &&
|
||||
vnode.key == null
|
||||
) {
|
||||
// deno-lint-ignore no-console
|
||||
console.warn(
|
||||
`<Partial name="${name}" mode="${mode}"> is missing a "key" prop. ` +
|
||||
`Without a key, Preact cannot correctly reconcile ${mode}ed children. ` +
|
||||
`Add a unique key to fix this.`,
|
||||
);
|
||||
}
|
||||
} else if (
|
||||
!PATCHED.has(vnode)
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user