fix: only render keyed comments when needed (#1859)
This commit is contained in:
@@ -286,6 +286,8 @@ options.__b = (vnode: VNode<Record<string, unknown>>) => {
|
||||
island &&
|
||||
!patched.has(vnode)
|
||||
) {
|
||||
current.islandDepth++;
|
||||
|
||||
// Check if an island is rendered inside another island, not just
|
||||
// passed as a child.In that case we treat it like a normal
|
||||
// Component. Example:
|
||||
@@ -359,6 +361,7 @@ options.__b = (vnode: VNode<Record<string, unknown>>) => {
|
||||
// deno-lint-ignore no-explicit-any
|
||||
} else if (vnode.type === (Partial as any)) {
|
||||
current.partialCount++;
|
||||
current.partialDepth++;
|
||||
if (hasIslandOwner(current, vnode)) {
|
||||
throw new Error(
|
||||
`<Partial> components cannot be used inside islands.`,
|
||||
@@ -373,7 +376,9 @@ options.__b = (vnode: VNode<Record<string, unknown>>) => {
|
||||
vnode.props.children,
|
||||
`frsh-partial:${vnode.props.name}:${mode}:${vnode.key ?? ""}`,
|
||||
);
|
||||
} else if (vnode.key) {
|
||||
} else if (
|
||||
vnode.key && (current.islandDepth > 0 || current.partialDepth > 0)
|
||||
) {
|
||||
const child = h(vnode.type, vnode.props);
|
||||
vnode.type = Fragment;
|
||||
vnode.props = {
|
||||
@@ -396,6 +401,14 @@ options.__r = (vnode) => {
|
||||
options.diffed = (vnode: VNode<Record<string, unknown>>) => {
|
||||
if (typeof vnode.type === "function") {
|
||||
if (vnode.type !== Fragment) {
|
||||
if (current) {
|
||||
if (islandByComponent.has(vnode.type)) {
|
||||
current.islandDepth--;
|
||||
} else if (vnode.type === Partial as ComponentType) {
|
||||
current.partialDepth--;
|
||||
}
|
||||
}
|
||||
|
||||
ownerStack.pop();
|
||||
} else if (vnode.props.__freshHead) {
|
||||
if (current) {
|
||||
|
||||
@@ -40,6 +40,8 @@ export class RenderState {
|
||||
error: Error | null = null;
|
||||
isPartial: boolean;
|
||||
partialCount = 0;
|
||||
partialDepth = 0;
|
||||
islandDepth = 0;
|
||||
url: URL;
|
||||
|
||||
constructor(
|
||||
|
||||
Reference in New Issue
Block a user