@@ -24,7 +24,7 @@ import ReactDOM, { type Root } from "react-dom/client";
2424import useEvent from "react-use-event-hook" ;
2525import type { ZodSchema } from "zod" ;
2626import { notebookAtom } from "@/core/cells/cells.ts" ;
27- import { findCellId } from "@/core/cells/ids.ts" ;
27+ import { HTMLCellId } from "@/core/cells/ids.ts" ;
2828import { isUninstantiated } from "@/core/cells/utils" ;
2929import { createInputEvent , MarimoValueUpdateEvent } from "@/core/dom/events" ;
3030import { getUIElementObjectId } from "@/core/dom/ui-element" ;
@@ -182,24 +182,28 @@ function PluginSlotInternal<T>(
182182 const objectId = getUIElementObjectId ( hostElement ) ;
183183 invariant ( objectId , "Object ID should exist" ) ;
184184
185- const cellId = findCellId ( hostElement ) ;
186- invariant ( cellId , "Cell ID should exist" ) ;
187-
188- const notebookState = store . get ( notebookAtom ) ;
189- const cellRuntime = notebookState . cellRuntime [ cellId ] ;
190- const cellData = notebookState . cellData [ cellId ] ;
191-
192- const cellNotInitialized = isUninstantiated ( {
193- executionTime :
194- cellRuntime . runElapsedTimeMs ?? cellData . lastExecutionTime ,
195- status : cellRuntime . status ,
196- errored : cellRuntime . errored ,
197- interrupted : cellRuntime . interrupted ,
198- stopped : cellRuntime . stopped ,
199- } ) ;
200-
201- if ( cellNotInitialized ) {
202- throw new CellNotInitializedError ( ) ;
185+ const htmlId = HTMLCellId . findElementThroughShadowDOMs ( hostElement ) ?. id ;
186+ const cellId = htmlId ? HTMLCellId . parse ( htmlId ) : null ;
187+ if ( cellId ) {
188+ // If the cell is not initialized, throw an error
189+ const notebookState = store . get ( notebookAtom ) ;
190+ const cellRuntime = notebookState . cellRuntime [ cellId ] ;
191+ const cellData = notebookState . cellData [ cellId ] ;
192+
193+ const cellNotInitialized = isUninstantiated ( {
194+ executionTime :
195+ cellRuntime . runElapsedTimeMs ?? cellData . lastExecutionTime ,
196+ status : cellRuntime . status ,
197+ errored : cellRuntime . errored ,
198+ interrupted : cellRuntime . interrupted ,
199+ stopped : cellRuntime . stopped ,
200+ } ) ;
201+
202+ if ( cellNotInitialized ) {
203+ throw new CellNotInitializedError ( ) ;
204+ }
205+ } else {
206+ Logger . warn ( `Cell ID ${ cellId } cannot be found` ) ;
203207 }
204208
205209 const response = await FUNCTIONS_REGISTRY . request ( {
0 commit comments