fix: error on duplicate partial name (#1958)

This commit is contained in:
Marvin Hagemeister
2023-10-18 20:04:37 +02:00
committed by GitHub
parent 4c59f9df65
commit 7896005329
5 changed files with 199 additions and 141 deletions
+8 -1
View File
@@ -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)
+2
View File
@@ -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();
}
}