Skip to content

Commit 50de3fd

Browse files
mscolnickLight2Darkpre-commit-ci[bot]
authored
fix: cell-id logic in function-registry (#6500)
Fixes #6462 introduced in #6281 --------- Co-authored-by: Shahmir Varqha <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent e2e1556 commit 50de3fd

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

frontend/src/plugins/core/registerReactComponent.tsx

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import ReactDOM, { type Root } from "react-dom/client";
2424
import useEvent from "react-use-event-hook";
2525
import type { ZodSchema } from "zod";
2626
import { notebookAtom } from "@/core/cells/cells.ts";
27-
import { findCellId } from "@/core/cells/ids.ts";
27+
import { HTMLCellId } from "@/core/cells/ids.ts";
2828
import { isUninstantiated } from "@/core/cells/utils";
2929
import { createInputEvent, MarimoValueUpdateEvent } from "@/core/dom/events";
3030
import { 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

Comments
 (0)