fix: error on duplicate partial name (#1958)
This commit is contained in:
@@ -367,6 +367,13 @@ options.__b = (vnode: VNode<Record<string, unknown>>) => {
|
||||
`<Partial> components cannot be used inside islands.`,
|
||||
);
|
||||
}
|
||||
const name = vnode.props.name as string;
|
||||
if (current.encounteredPartials.has(name)) {
|
||||
current.error = new Error(
|
||||
`Duplicate partial name "${name}" found. The partial name prop is expected to be unique among partial components.`,
|
||||
);
|
||||
}
|
||||
current.encounteredPartials.add(name);
|
||||
|
||||
const mode = encodePartialMode(
|
||||
// deno-lint-ignore no-explicit-any
|
||||
@@ -374,7 +381,7 @@ options.__b = (vnode: VNode<Record<string, unknown>>) => {
|
||||
);
|
||||
vnode.props.children = wrapWithMarker(
|
||||
vnode.props.children,
|
||||
`frsh-partial:${vnode.props.name}:${mode}:${vnode.key ?? ""}`,
|
||||
`frsh-partial:${name}:${mode}:${vnode.key ?? ""}`,
|
||||
);
|
||||
} else if (
|
||||
vnode.key && (current.islandDepth > 0 || current.partialDepth > 0)
|
||||
|
||||
@@ -39,6 +39,7 @@ export class RenderState {
|
||||
#nonce = "";
|
||||
error: Error | null = null;
|
||||
isPartial: boolean;
|
||||
encounteredPartials = new Set<string>();
|
||||
partialCount = 0;
|
||||
partialDepth = 0;
|
||||
islandDepth = 0;
|
||||
@@ -71,5 +72,6 @@ export class RenderState {
|
||||
this.renderingUserTemplate = false;
|
||||
this.ownerStack = [];
|
||||
this.owners.clear();
|
||||
this.encounteredPartials.clear();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user