diff --git a/packages/mountable/__mocks__/@stlite/common-react.ts b/packages/mountable/__mocks__/@stlite/common-react.ts deleted file mode 100644 index 2b257824b..000000000 --- a/packages/mountable/__mocks__/@stlite/common-react.ts +++ /dev/null @@ -1,11 +0,0 @@ -const onError = jest.fn(); -const onLoad = jest.fn(); -const onProgress = jest.fn(); - -export function makeToastKernelCallbacks() { - return { - onError, - onLoad, - onProgress, - }; -} diff --git a/packages/mountable/package.json b/packages/mountable/package.json index eeb7c9f84..11b8a9508 100644 --- a/packages/mountable/package.json +++ b/packages/mountable/package.json @@ -120,7 +120,6 @@ }, "jest": { "roots": [ - "", "/src" ], "collectCoverageFrom": [ diff --git a/packages/mountable/src/index.tsx b/packages/mountable/src/index.tsx index 09a07b56c..eeb0e080e 100644 --- a/packages/mountable/src/index.tsx +++ b/packages/mountable/src/index.tsx @@ -4,7 +4,11 @@ import StreamlitApp from "./StreamlitApp"; import { StliteKernel } from "@stlite/kernel"; import { getParentUrl } from "./url"; import { canonicalizeMountOptions, MountOptions } from "./options"; -import { ToastContainer, StliteKernelWithToast } from "@stlite/common-react"; +import { + ToastContainer, + makeToastKernelCallbacks, + StliteKernelWithToast, +} from "@stlite/common-react"; import "react-toastify/dist/ReactToastify.css"; import "@stlite/common-react/src/toastify-components/toastify.css"; @@ -34,6 +38,7 @@ export function mount( const kernel = new StliteKernel({ ...canonicalizeMountOptions(options), wheelBaseUrl, + ...makeToastKernelCallbacks(), }); ReactDOM.render( diff --git a/packages/mountable/src/options.test.ts b/packages/mountable/src/options.test.ts index fb4f48615..3b2816ce6 100644 --- a/packages/mountable/src/options.test.ts +++ b/packages/mountable/src/options.test.ts @@ -1,4 +1,3 @@ -import { makeToastKernelCallbacks } from "@stlite/common-react"; import { canonicalizeMountOptions, resolveUrl } from "./options"; describe("resolveUrl()", () => { @@ -64,7 +63,6 @@ describe("canonicalizeMountOptions()", () => { }, requirements: [], archives: [], - ...makeToastKernelCallbacks(), }); }); @@ -96,7 +94,6 @@ describe("canonicalizeMountOptions()", () => { }, }, archives: [], - ...makeToastKernelCallbacks(), }); }); @@ -142,7 +139,6 @@ describe("canonicalizeMountOptions()", () => { options: {}, }, ], - ...makeToastKernelCallbacks(), }); }); @@ -163,7 +159,6 @@ describe("canonicalizeMountOptions()", () => { }, }, archives: [], - ...makeToastKernelCallbacks(), }); }); @@ -177,31 +172,6 @@ describe("canonicalizeMountOptions()", () => { entrypoint: "streamlit_app.py", files: {}, archives: [], - ...makeToastKernelCallbacks(), }); }); - - it("wraps the `onError` option and also delegates to the original toast callback if `true` returned", () => { - const toastCallbacks = makeToastKernelCallbacks(); - - const onError = jest.fn(); - const options = canonicalizeMountOptions({ onError }); - - const error = new Error("foo"); - options.onError!(error); - expect(onError).toHaveBeenCalledWith(error); - expect(toastCallbacks.onError).toHaveBeenCalledWith(error); - }); - - it("wraps the `onError` option but prevents the toast if `false` returned", () => { - const toastCallbacks = makeToastKernelCallbacks(); - - const onError = jest.fn(() => false); - const options = canonicalizeMountOptions({ onError }); - - const error = new Error("foo"); - options.onError!(error); - expect(onError).toHaveBeenCalledWith(error); - expect(toastCallbacks.onError).not.toHaveBeenCalled(); - }); }); diff --git a/packages/mountable/src/options.ts b/packages/mountable/src/options.ts index 33851e10e..16c337ac0 100644 --- a/packages/mountable/src/options.ts +++ b/packages/mountable/src/options.ts @@ -3,7 +3,6 @@ import type { EmscriptenFile, EmscriptenFileUrl, } from "@stlite/kernel"; -import { makeToastKernelCallbacks } from "@stlite/common-react"; export interface SimplifiedStliteKernelOptions { entrypoint?: string; @@ -16,10 +15,6 @@ export interface SimplifiedStliteKernelOptions { allowedOriginsResp?: StliteKernelOptions["allowedOriginsResp"]; pyodideUrl?: StliteKernelOptions["pyodideUrl"]; streamlitConfig?: StliteKernelOptions["streamlitConfig"]; - // We won't add onProgress and onLoad callbacks until they are required by some users to keep the API simple. - onError?: ( - ...args: Parameters> - ) => boolean | void; } function canonicalizeFiles( @@ -86,8 +81,6 @@ export type MountOptions = string | SimplifiedStliteKernelOptions; export function canonicalizeMountOptions( options: string | SimplifiedStliteKernelOptions ): StliteKernelOptions { - const toastCallbacks = makeToastKernelCallbacks(); - if (typeof options === "string") { const mainScript = options; return { @@ -99,23 +92,12 @@ export function canonicalizeMountOptions( }, archives: [], requirements: [], - ...toastCallbacks, }; } const files = canonicalizeFiles(options.files); const archives = canonicalizeArchives(options.archives); - const onErrorOption = options.onError; - const onError: StliteKernelOptions["onError"] = onErrorOption - ? (...args) => { - const shouldShowToast = onErrorOption(...args); - if (shouldShowToast !== false) { - toastCallbacks.onError(...args); - } - } - : toastCallbacks.onError; - return { entrypoint: options.entrypoint || DEFAULT_ENTRYPOINT, files, @@ -124,7 +106,5 @@ export function canonicalizeMountOptions( allowedOriginsResp: options.allowedOriginsResp, pyodideUrl: options.pyodideUrl, streamlitConfig: options.streamlitConfig, - ...toastCallbacks, - onError, }; }