From 95eb9b5c844df58a2d64181b3e95efd8f96f93d1 Mon Sep 17 00:00:00 2001 From: Steve Purves Date: Fri, 19 Jul 2024 14:57:08 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20fix/direct=20import=20b?= =?UTF-8?q?ug=20(#757)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ✨keep types pure * 🙈 don't import objects from core to react * 📗changeset --- .changeset/pink-impalas-scream.md | 6 ++++++ packages/core/src/types.ts | 3 +-- packages/react/src/hooks/notebook.ts | 16 +++++----------- 3 files changed, 12 insertions(+), 13 deletions(-) create mode 100644 .changeset/pink-impalas-scream.md diff --git a/.changeset/pink-impalas-scream.md b/.changeset/pink-impalas-scream.md new file mode 100644 index 00000000..0ca861df --- /dev/null +++ b/.changeset/pink-impalas-scream.md @@ -0,0 +1,6 @@ +--- +'thebe-react': patch +'thebe-core': patch +--- + +Fixes a cross package import from `core` to `react` that caused downstream SSR to fail diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 88010854..5b5de244 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -5,7 +5,6 @@ import type { IRenderMimeRegistry } from '@jupyterlab/rendermime'; import type ThebeServer from './server'; import type { ServerStatusEvent } from './events'; import type { Config } from './config'; -import type ThebeNotebook from './notebook'; export type CellKind = 'code' | 'markdown'; export type JsonObject = Record; export type SessionIModel = Session.IModel; @@ -98,7 +97,7 @@ export interface IThebeCell extends IPassiveCell { source: string; session?: ThebeSession; metadata: JsonObject; - notebook?: ThebeNotebook; + notebookId?: string; readonly isBusy: boolean; readonly isAttached: boolean; readonly tags: string[]; diff --git a/packages/react/src/hooks/notebook.ts b/packages/react/src/hooks/notebook.ts index 1a8a2831..162e3275 100644 --- a/packages/react/src/hooks/notebook.ts +++ b/packages/react/src/hooks/notebook.ts @@ -1,20 +1,14 @@ import { createRef, useEffect, useState } from 'react'; -import { - type ThebeNotebook, - type ThebeSession, - type IThebeCell, - type IThebeCellExecuteReturn, - ThebePassiveManager, - WIDGET_VIEW_MIMETYPE, - WIDGET_STATE_MIMETYPE, -} from 'thebe-core'; +import type { ThebeNotebook, ThebeSession, IThebeCell, IThebeCellExecuteReturn } from 'thebe-core'; import { useThebeConfig } from '../ThebeServerProvider'; import { useThebeLoader } from '../ThebeLoaderProvider'; -import type { IExecuteResult, INotebookContent } from '@jupyterlab/nbformat'; +import type { INotebookContent } from '@jupyterlab/nbformat'; import { useThebeSession } from '../ThebeSessionProvider'; import { useRenderMimeRegistry } from '../ThebeRenderMimeRegistryProvider'; import type { IManagerState } from '@jupyter-widgets/base-manager'; +export const WIDGET_STATE_MIMETYPE = 'application/vnd.jupyter.widget-state+json'; + export interface NotebookExecuteOptions { stopOnError?: boolean; before?: () => void; @@ -168,7 +162,7 @@ export function useNotebook( }) .then((nb: ThebeNotebook) => { const cells = opts?.refsForWidgetsOnly ? nb?.widgets ?? [] : nb?.cells ?? []; - const manager = new ThebePassiveManager(rendermime); + const manager = new core.ThebePassiveManager(rendermime); if (nb.metadata.widgets && (nb.metadata.widgets as any)[WIDGET_STATE_MIMETYPE]) { manager.load_state((nb.metadata.widgets as any)[WIDGET_STATE_MIMETYPE] as IManagerState); }