File tree Expand file tree Collapse file tree
fixture/plugin/slot-string Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import {
2+ children ,
23 createComponent ,
34 createContext ,
45 createMemo ,
@@ -40,11 +41,24 @@ function PluginBoundary(props: ParentProps<{ id: string; where: string }>) {
4041 return null
4142 } }
4243 >
43- { props . children }
44+ < PluginOutput > { props . children } </ PluginOutput >
4445 </ ErrorBoundary >
4546 )
4647}
4748
49+ // Bare text is only valid under <text>. Left to the host's insert, it would
50+ // throw outside the boundary and crash the app, so reject it here instead.
51+ function PluginOutput ( props : ParentProps ) {
52+ const output = children ( ( ) => props . children )
53+ const nodes = createMemo ( ( ) => {
54+ const resolved = output . toArray ( )
55+ if ( resolved . some ( ( node ) => typeof node === "string" || typeof node === "number" ) )
56+ throw new Error ( "rendered bare text; wrap it in <text>" )
57+ return resolved
58+ } )
59+ return < > { nodes ( ) } </ >
60+ }
61+
4862export function PluginRoute ( props : { readonly fallback : ( id : string , name : string ) => JSX . Element } ) {
4963 const plugins = usePlugin ( )
5064 const route = useRoute ( )
Original file line number Diff line number Diff line change 1+ import { Plugin } from "@opencode/plugin/tui"
2+
3+ // A slot that returns bare text next to a well-formed one (anomalyco/opencode#58112).
4+ export default Plugin . define ( {
5+ id : "fixture.slot-string" ,
6+ setup ( context ) {
7+ context . ui . slot ( { append : "home.footer" , render : ( ) => "hello from a plugin" } )
8+ context . ui . slot ( { append : "home.footer" , render : ( ) => < text > Plugin still alive</ text > } )
9+ } ,
10+ } )
Original file line number Diff line number Diff line change 1+ import { expect , test } from "bun:test"
2+ import { createAppFixture } from "./fixture/app"
3+ import { copyPlugin } from "./fixture/fixture"
4+
5+ test ( "a slot that renders bare text crashes only its own contribution" , async ( ) => {
6+ await using plugin = await copyPlugin ( "slot-string" )
7+ await using setup = await createAppFixture ( { config : { animations : false , plugins : [ plugin . directory ] } } )
8+ await setup . ready
9+ await setup . waitForFrame (
10+ ( frame ) => frame . includes ( "Plugin still alive" ) && frame . includes ( "fixture.slot-string crashed in slot home.footer" ) ,
11+ )
12+ expect ( setup . captureCharFrame ( ) ) . not . toContain ( "hello from a plugin" )
13+ } )
You can’t perform that action at this time.
0 commit comments