Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(plugins): render slot components as elements, not direct calls

Tioit-Wangc453263d3cb9
diff --git a/apps/desktop/src/components/Composer.tsx b/apps/desktop/src/components/Composer.tsx
index 901b61c4e..71a41dc95 100644
--- a/apps/desktop/src/components/Composer.tsx
+++ b/apps/desktop/src/components/Composer.tsx
@@ -1,4 +1,6 @@
import {
+ ComponentType,
+ createElement,
useEffect,
useLayoutEffect,
useMemo,
@@ -663,10 +665,13 @@ export function Composer({
data-pi-plugin={activeTrigger.entry.pluginId}
>
<SlotBoundary entry={activeTrigger.entry} slot="composerTrigger">
- {activeTrigger.entry.component({
- query: activeTrigger.query,
- dispatch: dispatchFor(activeTrigger.entry.pluginId),
- }) as React.ReactNode}
+ {createElement(
+ activeTrigger.entry.component as ComponentType<Record<string, unknown>>,
+ {
+ query: activeTrigger.query,
+ dispatch: dispatchFor(activeTrigger.entry.pluginId),
+ },
+ )}
</SlotBoundary>
</div>
) : null}
diff --git a/apps/desktop/src/components/PluginBlockRenderer.tsx b/apps/desktop/src/components/PluginBlockRenderer.tsx
index fc53eca8b..ffcfe1f7a 100644
--- a/apps/desktop/src/components/PluginBlockRenderer.tsx
+++ b/apps/desktop/src/components/PluginBlockRenderer.tsx
@@ -8,7 +8,14 @@
* component that throws (via the boundary's fallback) — the source code must
* always stay visible to the user.
*/
-import { useLayoutEffect, useRef, useState, type ReactNode } from "react";
+import {
+ createElement,
+ useLayoutEffect,
+ useRef,
+ useState,
+ type ComponentType,
+ type ReactNode,
+} from "react";
import type { PluginBlockRendererSlotProps } from "@pi-desktop/plugin-sdk";
import { SlotBoundary } from "../plugins/renderer-slots/use-slots";
import type { SlotEntry } from "../plugins/renderer-slots/registry";
@@ -50,7 +57,7 @@ export function PluginBlockRenderer({
data-pi-language={onceRef.current.language}
style={{ maxHeight: BLOCK_RENDERER_MAX_HEIGHT_PX }}
>
- {entry.component(onceRef.current) as ReactNode}
+ {createElement(entry.component as ComponentType<Record<string, unknown>>, onceRef.current)}
</div>
</SlotBoundary>
);
diff --git a/apps/desktop/src/features/chat/composer/ComposerToolbar.tsx b/apps/desktop/src/features/chat/composer/ComposerToolbar.tsx
index 30ceccdcb..dd8d9218b 100644
--- a/apps/desktop/src/features/chat/composer/ComposerToolbar.tsx
+++ b/apps/desktop/src/features/chat/composer/ComposerToolbar.tsx
@@ -1,4 +1,4 @@
-import type { Dispatch, SetStateAction } from "react";
+import { createElement, type ComponentType, type Dispatch, type SetStateAction } from "react";
import type { TFunction } from "i18next";
import {
keybindingDisplayParts,
@@ -303,10 +303,10 @@ function PluginControlGroup({
{entries.map((entry) => (
<SlotBoundary key={entry.id} entry={entry} slot="composerControl">
<span className="pi-plugin-control" data-pi-plugin={entry.pluginId}>
- {entry.component({
+ {createElement(entry.component as ComponentType<Record<string, unknown>>, {
position: side,
dispatch: dispatchFor(entry.pluginId),
- }) as React.ReactNode}
+ })}
</span>
</SlotBoundary>
))}
diff --git a/apps/desktop/src/features/chat/transcript/ActionBarSlots.tsx b/apps/desktop/src/features/chat/transcript/ActionBarSlots.tsx
index d2fe6dd5c..a7ca00109 100644
--- a/apps/desktop/src/features/chat/transcript/ActionBarSlots.tsx
+++ b/apps/desktop/src/features/chat/transcript/ActionBarSlots.tsx
@@ -10,7 +10,14 @@
* the gutters, so install/uninstall reflows immediately. 出错隔离 and the
* `.pi-plugin-slot` chrome live in `SlotBoundary`.
*/
-import { useEffect, useRef, useState, type ReactNode } from "react";
+import {
+ createElement,
+ useEffect,
+ useRef,
+ useState,
+ type ComponentType,
+ type ReactNode,
+} from "react";
import { useTranslation } from "react-i18next";
import type { UiMessage } from "@pi-desktop/shared";
import type { PluginActionSlotProps } from "@pi-desktop/plugin-sdk";
@@ -53,7 +60,7 @@ function ActionSlotItem({
);
return (
<SlotBoundary entry={entry} slot={slot}>
- {entry.component(props) as ReactNode}
+ {createElement(entry.component as ComponentType<Record<string, unknown>>, props)}
</SlotBoundary>
);
}
diff --git a/apps/desktop/src/features/chat/transcript/EntryExtraStack.tsx b/apps/desktop/src/features/chat/transcript/EntryExtraStack.tsx
index eb083e0dc..21314e93f 100644
--- a/apps/desktop/src/features/chat/transcript/EntryExtraStack.tsx
+++ b/apps/desktop/src/features/chat/transcript/EntryExtraStack.tsx
@@ -10,7 +10,14 @@
*
* 出错隔离 lives in `SlotBoundary`: a throwing block collapses only itself.
*/
-import { useLayoutEffect, useRef, useState, type ReactNode } from "react";
+import {
+ createElement,
+ useLayoutEffect,
+ useRef,
+ useState,
+ type ComponentType,
+ type ReactNode,
+} from "react";
import { useTranslation } from "react-i18next";
import type { UiMessage } from "@pi-desktop/shared";
import type { PluginEntryExtraSlotProps } from "@pi-desktop/plugin-sdk";
@@ -87,7 +94,7 @@ function EntryExtraBlock({
: ENTRY_EXTRA_COLLAPSED_MAX_HEIGHT,
}}
>
- <div ref={contentRef}>{entry.component(props) as ReactNode}</div>
+ <div ref={contentRef}>{createElement(entry.component as ComponentType<Record<string, unknown>>, props)}</div>
</div>
{showToggle ? (
<button
diff --git a/apps/desktop/src/features/chat/transcript/PluginToolCard.tsx b/apps/desktop/src/features/chat/transcript/PluginToolCard.tsx
index 02b92a998..4d1f5cfa0 100644
--- a/apps/desktop/src/features/chat/transcript/PluginToolCard.tsx
+++ b/apps/desktop/src/features/chat/transcript/PluginToolCard.tsx
@@ -10,7 +10,14 @@
* default card is gone for this row, so the failure is a collapsed region,
* not a missing tool call.
*/
-import { useLayoutEffect, useRef, useState, type ReactNode } from "react";
+import {
+ createElement,
+ useLayoutEffect,
+ useRef,
+ useState,
+ type ComponentType,
+ type ReactNode,
+} from "react";
import type { UiMessage } from "@pi-desktop/shared";
import type { PluginToolCardSlotProps } from "@pi-desktop/plugin-sdk";
import { SlotBoundary, useSlotSessionId } from "../../../plugins/renderer-slots/use-slots";
@@ -61,7 +68,7 @@ export function PluginToolCard({
return (
<SlotBoundary entry={entry} slot="toolCard">
<div className="pi-plugin-tool-card" data-pi-tool={message.toolName}>
- {entry.component(committed) as ReactNode}
+ {createElement(entry.component as ComponentType<Record<string, unknown>>, committed)}
</div>
</SlotBoundary>
);
diff --git a/apps/desktop/test/plugin-action-slots.test.mjs b/apps/desktop/test/plugin-action-slots.test.mjs
index 847f7193e..eca998797 100644
--- a/apps/desktop/test/plugin-action-slots.test.mjs
+++ b/apps/desktop/test/plugin-action-slots.test.mjs
@@ -139,3 +139,22 @@ test("slot shell styles carry the ⋯ overflow menu chrome", () => {
assert.match(css, /\.pi-action-overflow-panel/);
assert.match(css, /data-side="right"/);
});
+
+test("slot outlets render plugin components as elements, never direct calls", () => {
+ // A direct entry.component(props) call runs the plugin's hooks inside the
+ // host component's hook chain → React "Invalid hook call". Every outlet
+ // must hand the component to createElement so it owns its fiber.
+ const outlets = {
+ "features/chat/transcript/ActionBarSlots.tsx": /createElement\(\s*entry\.component/,
+ "features/chat/transcript/EntryExtraStack.tsx": /createElement\(\s*entry\.component/,
+ "features/chat/transcript/PluginToolCard.tsx": /createElement\(\s*entry\.component/,
+ "components/PluginBlockRenderer.tsx": /createElement\(\s*entry\.component/,
+ "features/chat/composer/ComposerToolbar.tsx": /createElement\(\s*entry\.component/,
+ "components/Composer.tsx": /createElement\(\s*\n?\s*activeTrigger\.entry\.component/,
+ };
+ for (const [file, pattern] of Object.entries(outlets)) {
+ const source = readFileSync(src(file), "utf8");
+ assert.match(source, pattern, `${file} must render via createElement`);
+ assert.doesNotMatch(source, /entry\.component\(\{/, `${file} must not call entry.component directly`);
+ }
+});