Skip to content

Commit

Permalink
🛠improving binder connection cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
stevejpurves committed Nov 21, 2023
1 parent 15589b9 commit 93c32dd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion apps/demo-react/src/Connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ export function Connect() {

return (
<div className="my-2">
{!ready && (
{!connecting && !ready && (
<button className="button" onClick={clickConnect} disabled={!core || connecting}>
connect
</button>
)}
{connecting && (
<span className="inline-block h-[41px] bg-orange-500 text-white font-bold py-2 px-4 rounded-full">
connecting
</span>
)}
{ready && (
<span className="inline-block h-[41px] bg-green-500 text-white font-bold py-2 px-4 rounded-full">
connected
Expand Down
4 changes: 2 additions & 2 deletions apps/demo-react/src/NotebookPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { NotebookStatusTray } from './NotebookStatusTray';
import { NotebookErrorTray } from './NotebookErrorTray';

export function NotebookPage({ children }: React.PropsWithChildren) {
const { ready, config } = useThebeServer();
const { connecting, ready, config } = useThebeServer();

if (!ready) return null;
if (!connecting && !ready) return null;
return (
<ThebeRenderMimeRegistryProvider>
<ThebeSessionProvider start path={config?.kernels.path}>
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/ThebeServerProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function ThebeServerProvider({
setServer(svr);
}, [core, thebeConfig, server]);

const connectToServer = useCallback(() => {
const connectToServer = () => {
if (!server) return;
setConnecting(true);
if (customConnectFn) customConnectFn(server);
Expand Down Expand Up @@ -113,7 +113,7 @@ export function ThebeServerProvider({
);

return server.ready;
}, [server]);
};

// Once the core is loaded, connect to a server
// TODO: this should be an action not a side effect
Expand Down

0 comments on commit 93c32dd

Please sign in to comment.