Skip to content

Commit

Permalink
🛠 fix notebook build process (#323)
Browse files Browse the repository at this point in the history
* 🛠fix notebook build process

* ⚒️ fix passive render issue for non plotly unsafe outputs
  • Loading branch information
stevejpurves authored Mar 7, 2024
1 parent 1a90306 commit 947ddf3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/shy-buses-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@myst-theme/jupyter': patch
---

Fix for [322](https://github.com/executablebooks/myst-theme/issues/322) waiting for plotly during notebook build
10 changes: 5 additions & 5 deletions packages/jupyter/src/execute/leaf.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useRef } from 'react';
import type { ExecuteScopeAction } from './actions.js';
import type { IdKeyMap, ExecuteScopeState } from './types.js';
import type { IdKeyMap, ExecuteScopeState, ExecutionScope } from './types.js';
import { useThebeLoader, useThebeConfig, useThebeServer } from 'thebe-react';
import { notebookFromMdast } from './utils.js';
import type { GenericParent } from 'myst-common';
Expand Down Expand Up @@ -94,7 +94,7 @@ export function NotebookBuilder({

// TODO find a way to check if the all the notebooks are built and do a single dispatch
// potentilly use a move the loop down into this component
const allNotebooksAreBuilt = selectAreAllNotebookScopesBuilt(state, pageSlug);
const allNotebooksAreBuilt = plotly && selectAreAllNotebookScopesBuilt(state, pageSlug);
useEffect(() => {
if (!allNotebooksAreBuilt) return;
dispatch({ type: 'BUILD_STATUS', payload: { slug: pageSlug, status: 'wait-for-server' } });
Expand All @@ -120,10 +120,10 @@ export function SessionStarter({
const { config, server } = useThebeServer();
const lock = useRef(false); // TODO can be removed if we solve double render from provider

const scope = state.pages[pageSlug]?.scopes[notebookSlug];
const scope: ExecutionScope | undefined = state.pages[pageSlug]?.scopes[notebookSlug];

useEffect(() => {
if (!core || !server || scope.session || lock.current) return;
if (!core || !server || scope?.session || lock.current) return;
lock.current = true;
console.debug(`Jupyter: Starting session for ${pageSlug}-${notebookSlug} at ${location}`);
if (location === undefined) {
Expand Down Expand Up @@ -185,7 +185,7 @@ export function SessionStarter({
});
}
});
}, [core, config, pageSlug, notebookSlug, lock]);
}, [core, config, scope, pageSlug, notebookSlug, lock]);

// TODO avoid multiple dispatch?
const allSessionsAreStarted = selectAreAllSessionsStarted(state, pageSlug);
Expand Down
4 changes: 2 additions & 2 deletions packages/jupyter/src/plotly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export function isPlotly(outputs: IOutput[]) {
}

export function usePlotlyPassively(rendermime: IRenderMimeRegistry, outputs: IOutput[]) {
const [loaded, setLoaded] = useState(false);

const isPlotlyOutput = isPlotly(outputs);
// skip loading for non plotly outputs
const [loaded, setLoaded] = useState(!isPlotlyOutput);

useEffect(() => {
if (loaded || !isPlotlyOutput) return;
Expand Down

0 comments on commit 947ddf3

Please sign in to comment.